8 class ControlWidget(Wbase
.ClickableWidget
):
10 """Baseclass for all native controls."""
12 def __init__(self
, possize
, title
= "Control", procID
= 0, callback
= None, value
= 0, min = 0, max = 1):
13 Wbase
.ClickableWidget
.__init
__(self
, possize
)
16 self
._callback
= callback
25 self
._control
= Ctl
.NewControl(self
._parentwindow
.wid
,
35 #self.GetWindow().ValidWindowRect(self._bounds)
36 self
.enable(self
._enabled
)
38 def adjust(self
, oldbounds
):
40 self
._control
.HideControl()
41 self
._control
.MoveControl(self
._bounds
[0], self
._bounds
[1])
42 self
._control
.SizeControl(self
._bounds
[2] - self
._bounds
[0], self
._bounds
[3] - self
._bounds
[1])
44 Qd
.EraseRect(self
._bounds
)
45 self
._control
.ShowControl()
46 self
.GetWindow().ValidWindowRect(self
._bounds
)
49 self
._control
.HideControl()
51 Wbase
.ClickableWidget
.close(self
)
53 def enable(self
, onoff
):
54 if self
._control
and self
._enabled
<> onoff
:
55 self
._control
.HiliteControl((not onoff
) and 255)
58 def show(self
, onoff
):
60 for w
in self
._widgets
:
63 self
._control
.ShowControl()
65 self
._control
.HideControl()
67 def activate(self
, onoff
):
68 self
._activated
= onoff
70 self
._control
.HiliteControl((not onoff
) and 255)
72 def draw(self
, visRgn
= None):
74 self
._control
.Draw1Control()
76 def test(self
, point
):
77 ctltype
, control
= Ctl
.FindControl(point
, self
._parentwindow
.wid
)
78 if self
._enabled
and control
== self
._control
:
81 def click(self
, point
, modifiers
):
84 part
= self
._control
.TrackControl(point
)
87 Wbase
.CallbackCall(self
._callback
, 0)
89 def settitle(self
, title
):
91 self
._control
.SetControlTitle(title
)
97 class Button(ControlWidget
):
99 """Standard push button."""
101 def __init__(self
, possize
, title
= "Button", callback
= None):
102 procID
= Controls
.pushButProc | Controls
.useWFont
103 ControlWidget
.__init
__(self
, possize
, title
, procID
, callback
, 0, 0, 1)
107 if not self
._enabled
:
110 self
._control
.HiliteControl(1)
112 self
._control
.HiliteControl(0)
114 Wbase
.CallbackCall(self
._callback
, 0)
116 def enable(self
, onoff
):
117 if self
._control
and self
._enabled
<> onoff
:
118 self
._control
.HiliteControl((not onoff
) and 255)
119 self
._enabled
= onoff
120 if self
._isdefault
and self
._visible
:
122 self
.drawfatframe(onoff
)
124 def activate(self
, onoff
):
125 self
._activated
= onoff
127 self
._control
.HiliteControl((not onoff
) and 255)
128 if self
._isdefault
and self
._visible
:
130 self
.drawfatframe(onoff
)
132 def show(self
, onoff
):
133 ControlWidget
.show(self
, onoff
)
135 self
.drawfatframe(onoff
and self
._enabled
)
137 def draw(self
, visRgn
= None):
139 self
._control
.Draw1Control()
140 if self
._isdefault
and self
._activated
:
141 self
.drawfatframe(self
._enabled
)
143 def drawfatframe(self
, onoff
):
144 state
= Qd
.GetPenState()
146 Qd
.PenPat(Qd
.qd
.black
)
148 Qd
.PenPat(Qd
.qd
.white
)
149 fatrect
= Qd
.InsetRect(self
._bounds
, -4, -4)
151 Qd
.FrameRoundRect(fatrect
, 16, 16)
152 Qd
.SetPenState(state
)
154 def _setdefault(self
, onoff
):
155 self
._isdefault
= onoff
156 if self
._control
and self
._enabled
:
158 self
.drawfatframe(onoff
)
160 def adjust(self
, oldbounds
):
162 old
= Qd
.InsetRect(oldbounds
, -4, -4)
163 new
= Qd
.InsetRect(self
._bounds
, -4, -4)
165 self
.GetWindow().InvalWindowRect(old
)
166 self
.GetWindow().InvalWindowRect(new
)
167 ControlWidget
.adjust(self
, oldbounds
)
170 class CheckBox(ControlWidget
):
172 """Standard checkbox."""
174 def __init__(self
, possize
, title
= "Checkbox", callback
= None, value
= 0):
175 procID
= Controls
.checkBoxProc | Controls
.useWFont
176 ControlWidget
.__init
__(self
, possize
, title
, procID
, callback
, value
, 0, 1)
178 def click(self
, point
, modifiers
):
179 if not self
._enabled
:
181 part
= self
._control
.TrackControl(point
)
185 Wbase
.CallbackCall(self
._callback
, 0, self
.get())
188 if not self
._enabled
:
192 Wbase
.CallbackCall(self
._callback
, 0, self
.get())
195 self
.set(not self
.get())
197 def set(self
, value
):
199 self
._control
.SetControlValue(value
)
205 return self
._control
.GetControlValue()
210 class RadioButton(ControlWidget
):
212 """Standard radiobutton."""
214 # XXX We need a radiogroup widget; this is too kludgy.
216 def __init__(self
, possize
, title
, thebuttons
, callback
= None, value
= 0):
217 procID
= Controls
.radioButProc | Controls
.useWFont
218 ControlWidget
.__init
__(self
, possize
, title
, procID
, callback
, value
, 0, 1)
219 self
.thebuttons
= thebuttons
220 thebuttons
.append(self
)
223 self
.thebuttons
= None
224 ControlWidget
.close(self
)
226 def click(self
, point
, modifiers
):
227 if not self
._enabled
:
229 part
= self
._control
.TrackControl(point
)
233 Wbase
.CallbackCall(self
._callback
, 0, 1)
236 if not self
._enabled
:
240 Wbase
.CallbackCall(self
._callback
, 0, 1)
242 def set(self
, value
):
243 for button
in self
.thebuttons
:
245 button
._control
.SetControlValue(button
== self
)
247 button
._value
= (button
== self
)
251 return self
._control
.GetControlValue()
256 class Scrollbar(ControlWidget
):
258 """Standard scrollbar."""
260 def __init__(self
, possize
, callback
= None, value
= 0, min = 0, max = 0):
261 procID
= Controls
.scrollBarProc
262 ControlWidget
.__init
__(self
, possize
, "", procID
, callback
, value
, min, max)
265 def set(self
, value
):
267 Wbase
.CallbackCall(self
._callback
, 1, value
)
271 Wbase
.CallbackCall(self
._callback
, 1, '+')
275 Wbase
.CallbackCall(self
._callback
, 1, '-')
279 Wbase
.CallbackCall(self
._callback
, 1, '++')
283 Wbase
.CallbackCall(self
._callback
, 1, '--')
285 def setmin(self
, min):
286 self
._control
.SetControlMinimum(min)
288 def setmax(self
, min):
289 self
._control
.SetControlMinimum(max)
292 return self
._control
.GetControlMinimum()
295 return self
._control
.GetControlMinimum()
298 def click(self
, point
, modifiers
):
299 if not self
._enabled
:
301 # custom TrackControl. A mousedown in a scrollbar arrow or page area should
302 # generate _control hits as long as the mouse is a) down, b) still in the same part
303 part
= self
._control
.TestControl(point
)
304 if Controls
.inUpButton
<= part
<= Controls
.inPageDown
:
305 self
._control
.HiliteControl(part
)
308 # slight delay before scrolling at top speed...
309 now
= Evt
.TickCount()
310 while Evt
.StillDown():
311 if (Evt
.TickCount() - now
) > 18: # 0.3 seconds
313 while Evt
.StillDown():
314 part
= self
._control
.TestControl(point
)
316 self
._control
.HiliteControl(part
)
319 self
._control
.HiliteControl(0)
321 point
= Evt
.GetMouse()
322 self
._control
.HiliteControl(0)
323 elif part
== Controls
.inThumb
:
324 part
= self
._control
.TrackControl(point
)
328 def _hit(self
, part
):
329 if part
== Controls
.inThumb
:
330 value
= self
._control
.GetControlValue()
331 elif part
== Controls
.inUpButton
:
333 elif part
== Controls
.inDownButton
:
335 elif part
== Controls
.inPageUp
:
337 elif part
== Controls
.inPageDown
:
340 Wbase
.CallbackCall(self
._callback
, 1, value
)
342 def draw(self
, visRgn
= None):
344 self
._control
.Draw1Control()
345 Qd
.FrameRect(self
._bounds
)
347 def adjust(self
, oldbounds
):
349 self
.GetWindow().InvalWindowRect(oldbounds
)
350 self
._control
.HideControl()
351 self
._control
.MoveControl(self
._bounds
[0], self
._bounds
[1])
352 self
._control
.SizeControl(self
._bounds
[2] - self
._bounds
[0], self
._bounds
[3] - self
._bounds
[1])
354 Qd
.EraseRect(self
._bounds
)
356 self
._control
.ShowControl()
358 Qd
.FrameRect(self
._bounds
)
359 self
.GetWindow().ValidWindowRect(self
._bounds
)
361 def activate(self
, onoff
):
362 self
._activated
= onoff
365 self
._control
.ShowControl()
367 self
._control
.HideControl()
369 self
.GetWindow().ValidWindowRect(self
._bounds
)
371 def set(self
, value
):
373 self
._control
.SetControlValue(value
)
379 return self
._control
.GetControlValue()
384 class __xxxx_PopupControl(ControlWidget
):
386 def __init__(self
, possize
, title
= "Button", callback
= None):
387 procID
= Controls
.popupMenuProc
# | Controls.useWFont
388 ControlWidget
.__init
__(self
, possize
, title
, procID
, callback
, 0, 0, 1)
392 def _scalebarvalue(absmin
, absmax
, curmin
, curmax
):
393 if curmin
<= absmin
and curmax
>= absmax
:
399 perc
= float(curmin
-absmin
) / float((absmax
- absmin
) - (curmax
- curmin
))
400 return int(perc
*32767)