1 # Generic Split implementation.
2 # Use as a base class for other splits.
3 # Derived classes should at least implement the methods that call
4 # unimpl() below: getminsize(), getbounds() and setbounds().
6 Error
= 'Split.Error' # Exception
9 from stdwinevents
import *
14 # NB derived classes may add parameters to create()
16 def create(self
, parent
):
20 self
.mouse_interest
= []
21 self
.keybd_interest
= []
22 self
.timer_interest
= []
23 self
.altdraw_interest
= []
24 self
.mouse_focus
= None
25 self
.keybd_focus
= None
28 # Downcalls from parent to child
32 for child
in self
.children
:
35 del self
.mouse_interest
[:]
36 del self
.keybd_interest
[:]
37 del self
.timer_interest
[:]
38 del self
.altdraw_interest
[:]
39 self
.mouse_focus
= None
40 self
.keybd_focus
= None
42 def getminsize(self
, m
, (width
, height
)):
43 return unimpl() # Should ask children
46 def setbounds(self
, bounds
):
47 unimpl() # Should tell children
50 for child
in self
.children
:
53 def draw(self
, d
, detail
):
54 # (Could avoid calls to children outside the area)
55 for child
in self
.children
:
58 def altdraw(self
, detail
):
59 for child
in self
.altdraw_interest
:
62 # Keyboard focus handling (used internally)
63 # XXX This is not enough if two levels of splits
64 # XXX surround text fields!
66 def set_keybd_focus(self
, child
):
67 if self
.keybd_focus
<> child
:
69 self
.keybd_focus
.deactivate()
70 self
.keybd_focus
= None
73 self
.keybd_focus
= child
74 def next_keybd_focus(self
):
75 if not self
.keybd_interest
:
76 self
.set_keybd_focus(None)
78 if self
.keybd_focus
in self
.keybd_interest
:
79 i
= self
.keybd_interest
.index(self
.keybd_focus
)
80 i
= (i
+1) % len(self
.keybd_interest
)
83 self
.set_keybd_focus(self
.keybd_interest
[i
])
85 # Downcalls only made after certain upcalls
87 def mouse_down(self
, detail
):
89 self
.mouse_focus
.mouse_down(detail
)
92 for child
in self
.mouse_interest
:
93 if rect
.pointinrect(p
, child
.getbounds()):
94 self
.mouse_focus
= child
95 if child
in self
.keybd_interest
:
96 self
.set_keybd_focus(child
)
97 child
.mouse_down(detail
)
98 def mouse_move(self
, detail
):
100 self
.mouse_focus
.mouse_move(detail
)
101 def mouse_up(self
, detail
):
103 self
.mouse_focus
.mouse_up(detail
)
104 self
.mouse_focus
= None
108 self
.keybd_focus
.activate()
110 self
.next_keybd_focus()
111 def deactivate(self
):
113 self
.keybd_focus
.deactivate()
115 def keybd(self
, type, detail
):
116 if not self
.keybd_focus
:
117 self
.set_keybd_focus(self
.keybd_interest
[0])
118 if type == WE_COMMAND
and detail
== WC_TAB
and \
119 len(self
.keybd_interest
) > 1:
120 self
.next_keybd_focus()
122 self
.keybd_focus
.keybd(type, detail
)
125 for child
in self
.timer_interest
:
128 # Upcalls from child to parent
130 def addchild(self
, child
):
131 if child
in self
.children
:
132 raise Error
, 'addchild: child already inlist'
133 self
.children
.append(child
)
134 def delchild(self
, child
):
135 if child
not in self
.children
:
136 raise Error
, 'delchild: child not in list'
137 self
.children
.remove(child
)
138 if child
in self
.mouse_interest
:
139 self
.mouse_interest
.remove(child
)
140 if child
in self
.keybd_interest
:
141 self
.keybd_interest
.remove(child
)
142 if child
in self
.timer_interest
:
143 self
.timer_interest
.remove(child
)
144 if child
in self
.altdraw_interest
:
145 self
.altdraw_interest
.remove(child
)
146 if child
== self
.mouse_focus
:
147 self
.mouse_focus
= None
148 if child
== self
.keybd_focus
:
149 self
.keybd_focus
= None
151 def need_mouse(self
, child
):
152 if child
not in self
.mouse_interest
:
153 self
.mouse_interest
.append(child
)
154 self
.parent
.need_mouse(self
)
155 def no_mouse(self
, child
):
156 if child
== self
.mouse_focus
:
157 self
.mouse_focus
= None
158 if child
in self
.mouse_interest
:
159 self
.mouse_interest
.remove(child
)
160 if not self
.mouse_interest
:
161 self
.parent
.no_mouse(self
)
163 def need_keybd(self
, child
):
164 if child
not in self
.keybd_interest
:
165 self
.keybd_interest
.append(child
)
166 self
.parent
.need_keybd(self
)
167 if not self
.keybd_focus
:
168 self
.set_keybd_focus(child
)
169 def no_keybd(self
, child
):
170 if child
== self
.keybd_focus
:
171 self
.keybd_focus
= None # Don't call child.deactivate()
172 if child
in self
.keybd_interest
:
173 self
.keybd_interest
.remove(child
)
174 if not self
.keybd_interest
:
175 self
.parent
.no_keybd(self
)
177 def need_timer(self
, child
):
178 if child
not in self
.timer_interest
:
179 self
.timer_interest
.append(child
)
180 self
.parent
.need_timer(self
)
181 def no_timer(self
, child
):
182 if child
in self
.timer_interest
:
183 self
.timer_interest
.remove(child
)
184 if not self
.timer_interest
:
185 self
.parent
.no_timer(self
)
187 def need_altdraw(self
, child
):
188 if child
not in self
.altdraw_interest
:
189 self
.altdraw_interest
.append(child
)
190 self
.parent
.need_altdraw(self
)
191 def no_altdraw(self
, child
):
192 if child
in self
.altdraw_interest
:
193 self
.altdraw_interest
.remove(child
)
194 if not self
.altdraw_interest
:
195 self
.parent
.no_altdraw(self
)
197 # The rest are transparent:
199 def begindrawing(self
):
200 return self
.parent
.begindrawing()
201 def beginmeasuring(self
):
202 return self
.parent
.beginmeasuring()
204 return self
.parent
.getwindow()
206 def change(self
, area
):
207 self
.parent
.change(area
)
208 def scroll(self
, area
, vector
):
209 self
.parent
.scroll(area
, vector
)
210 def settimer(self
, itimer
):
211 self
.parent
.settimer(itimer
)