|
1 import gtk |
|
2 |
|
3 |
|
4 class PanedExt(gtk.Paned): |
|
5 """Extended gtk.Paned (abstract) |
|
6 |
|
7 set_snap1(int), set_snap2(int) |
|
8 set minimum size of child widget |
|
9 if the handle is moved to the edge, child widget is hidden |
|
10 """ |
|
11 def __init__(self): |
|
12 self.connect('notify::position', self.on_position_change) |
|
13 self.min1 = 0 |
|
14 self.min2 = 0 |
|
15 |
|
16 |
|
17 def set_snap1(self, minpos): |
|
18 self.min1 = minpos |
|
19 |
|
20 |
|
21 def set_snap2(self, minpos): |
|
22 self.min2 = minpos |
|
23 |
|
24 |
|
25 def on_position_change(self, w, scrolltype): |
|
26 if self.allocation[0] == -1: |
|
27 return False |
|
28 |
|
29 pos = self.get_position() |
|
30 maxpos = self.get_property('max-position') |
|
31 |
|
32 if self.min1: |
|
33 if pos > 0 and pos < self.min1: |
|
34 if pos < self.min1 / 2: |
|
35 self.set_position(0) |
|
36 else: |
|
37 self.set_position(self.min1) |
|
38 return True |
|
39 |
|
40 if self.min2: |
|
41 if pos > maxpos - self.min2 and pos < maxpos: |
|
42 if pos > maxpos - self.min2 / 2: |
|
43 self.set_position(maxpos) |
|
44 else: |
|
45 self.set_position(maxpos - self.min2) |
|
46 return True |
|
47 |
|
48 return False |
|
49 |
|
50 |
|
51 class HPanedExt(gtk.HPaned, PanedExt): |
|
52 def __init__(self): |
|
53 gtk.HPaned.__init__(self) |
|
54 PanedExt.__init__(self) |
|
55 |
|
56 |
|
57 class VPanedExt(gtk.VPaned, PanedExt): |
|
58 def __init__(self): |
|
59 gtk.VPaned.__init__(self) |
|
60 PanedExt.__init__(self) |
|
61 |