1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#!/usr/bin/env python3
"""
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GdkPixbuf
import os
class MyWindow(Gtk.Window):
def __init__(self):
super().__init__()
self.modify_bg(Gtk.StateType.NORMAL, Gdk.Color(6400, 6400, 6440))
fixed = Gtk.Fixed()
fixed.put(image1, 10, 10)
fixed.put(image2, 430, 10)
fixed.put(image3, 560, 10)
self.add(fixed)
self.set_border_width(20)
self.set_title("Fixed")
self.connect("destroy", Gtk.main_quit)
win = MyWindow()
win.show_all()
Gtk.main()
"""
import gi, os
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GdkPixbuf
class FlowBoxWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="FlowBox Demo")
self.set_border_width(10)
self.set_default_size(300, 250)
#header = Gtk.HeaderBar(title="Flow Box")
#header.set_subtitle("Sample FlowBox app")
#header.props.show_close_button = True
#self.set_titlebar(header)
scrolled = Gtk.ScrolledWindow()
scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
flowbox = Gtk.FlowBox()
flowbox.set_valign(Gtk.Align.START)
flowbox.set_max_children_per_line(30)
flowbox.set_selection_mode(Gtk.SelectionMode.NONE)
self.create_flowbox(flowbox)
scrolled.add(flowbox)
self.add(scrolled)
self.show_all()
def on_draw(self, widget, cr, data):
context = widget.get_style_context()
width = widget.get_allocated_width()
height = widget.get_allocated_height()
Gtk.render_background(context, cr, 0, 0, width, height)
r,g,b,a = data['color']
cr.set_source_rgba(r,g,b,a)
cr.rectangle(0, 0, width, height)
cr.fill()
def color_swatch_new(self, str_color):
color = Gdk.color_parse(str_color)
rgba = Gdk.RGBA.from_color(color)
button = Gtk.Button()
area = Gtk.DrawingArea()
area.set_size_request(24, 24)
area.connect("draw", self.on_draw, {'color': rgba})
button.add(area)
return button
def create_flowbox(self, flowbox):
base_path = os.path.expanduser("~/doxie")
for fn in os.listdir(base_path):
pb = GdkPixbuf.Pixbuf.new_from_file(os.path.join(base_path, fn))
img = Gtk.Image()
img.set_from_pixbuf(pb.scale_simple(300, 400, GdkPixbuf.InterpType.BILINEAR))
flowbox.add(img)
win = FlowBoxWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
|