1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from utils import is_in_rect
24 import gobject
25 import gtk
26
28 '''
29 Paned.
30
31 @undocumented: do_enter_notify_event
32 @undocumented: do_button_press_event
33 @undocumented: do_size_allocate
34 @undocumented: do_enter_notify_event
35 @undocumented: is_in_button
36 @undocumented: draw_handle
37 @undocumented: do_expose_event
38
39 gtk.Paned with custom better apperance.
40 '''
42 '''
43 Initialize Paned class.
44 '''
45 gtk.Paned.__init__(self)
46 self.bheight = 60
47 self.saved_position = -1
48 self.handle_size = self.style_get_property('handle-size')
49
51 '''
52 To intercept the default expose event and draw custom handle
53 after the **gtk.Container** expose evetn.
54 So the gtk.Paned's expose event callback is ignore.
55 '''
56
57 gtk.Container.do_expose_event(self, e)
58 self.draw_handle(e)
59
60 return False
61
63 '''
64 Draw the cusom handle apperance.
65 '''
66 handle = self.get_handle_window()
67 line_width = 1
68 cr = handle.cairo_create()
69 cr.set_source_rgba(1, 0,0, 0.8)
70 (width, height) = handle.get_size()
71 if self.get_orientation() == gtk.ORIENTATION_HORIZONTAL:
72
73 cr.rectangle(0, 0, line_width, height)
74
75
76 cr.rectangle(0, (height-self.bheight)/2, width, self.bheight)
77 else:
78 cr.rectangle(0, 0, height, line_width)
79 cr.rectangle((width-self.bheight)/2, 0, self.bheight, width)
80
81 cr.fill()
82 pass
83
99
101 '''
102 change the cursor style when move in handler
103 '''
104 handle = self.get_handle_window()
105 (width, height) = handle.get_size()
106 if self.is_in_button(e.x, e.y):
107 handle.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1))
108 else:
109 handle.set_cursor(self.cursor_type)
110
111 self.queue_draw()
112
127
129 gtk.Paned.do_size_allocate(self, e)
130
131 c2 = self.get_child2()
132
133 if c2 == None: return
134
135 a2 = c2.allocation
136
137 if self.get_orientation() == gtk.ORIENTATION_HORIZONTAL:
138 a2.x -= self.handle_size
139 a2.width += self.handle_size
140 else:
141 a2.y -= self.handle_size
142 a2.height += self.handle_size
143 c2.size_allocate(a2)
144
147 Paned.__init__(self)
148 self.set_orientation(gtk.ORIENTATION_HORIZONTAL)
149 self.cursor_type = gtk.gdk.Cursor(gtk.gdk.SB_H_DOUBLE_ARROW)
150
153 Paned.__init__(self)
154 self.set_orientation(gtk.ORIENTATION_VERTICAL)
155 self.cursor_type = gtk.gdk.Cursor(gtk.gdk.SB_V_DOUBLE_ARROW)
156
157 gobject.type_register(Paned)
158 gobject.type_register(HPaned)
159 gobject.type_register(VPaned)
160
161 if __name__ == '__main__':
162 w = gtk.Window()
163 w.set_size_request(700, 400)
164
165 box = gtk.VBox()
166
167 p = VPaned()
168 c1 = gtk.Button("11111111111111111111111")
169 c1.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('blue'))
170 c2 = gtk.Button("122222222222222222222222")
171 c1.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('red'))
172 p.add1(c1)
173 p.add2(c2)
174 box.pack_start(p)
175
176 p = HPaned()
177 c1 = gtk.Button("11111111111111111111111")
178 c1.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('blue'))
179 c2 = gtk.Button("122222222222222222222222")
180 c1.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('red'))
181 p.add1(c1)
182 p.add2(c2)
183 box.pack_start(p)
184
185 w.add(box)
186 w.connect('destroy', gtk.main_quit)
187 w.show_all()
188 gtk.main()
189