8 class ControlWidget(Wbase
.ClickableWidget
):
10 def __init__(self
, possize
, title
= "Control", procID
= 0, callback
= None, value
= 0, min = 0, max = 1):
11 Wbase
.ClickableWidget
.__init
__(self
, possize
)
14 self
._callback
= callback
23 self
._control
= Ctl
.NewControl(self
._parentwindow
.wid
,
33 Win
.ValidRect(self
._bounds
)
34 self
.enable(self
._enabled
)
36 def adjust(self
, oldbounds
):
38 self
._control
.HideControl()
39 self
._control
.MoveControl(self
._bounds
[0], self
._bounds
[1])
40 self
._control
.SizeControl(self
._bounds
[2] - self
._bounds
[0], self
._bounds
[3] - self
._bounds
[1])
42 Qd
.EraseRect(self
._bounds
)
43 self
._control
.ShowControl()
44 Win
.ValidRect(self
._bounds
)
47 self
._control
.HideControl()
49 Wbase
.ClickableWidget
.close(self
)
51 def enable(self
, onoff
):
52 if self
._control
and self
._enabled
<> onoff
:
53 self
._control
.HiliteControl((not onoff
) and 255)
56 def show(self
, onoff
):
58 for w
in self
._widgets
:
61 self
._control
.ShowControl()
63 self
._control
.HideControl()
65 def activate(self
, onoff
):
66 self
._activated
= onoff
68 self
._control
.HiliteControl((not onoff
) and 255)
70 def draw(self
, visRgn
= None):
72 self
._control
.Draw1Control()
74 def test(self
, point
):
75 ctltype
, control
= Ctl
.FindControl(point
, self
._parentwindow
.wid
)
76 if self
._enabled
and control
== self
._control
:
79 def click(self
, point
, modifiers
):
82 part
= self
._control
.TrackControl(point
)
85 Wbase
.CallbackCall(self
._callback
, 0)
87 def settitle(self
, title
):
89 self
._control
.SetControlTitle(title
)
95 class Button(ControlWidget
):
97 def __init__(self
, possize
, title
= "Button", callback
= None):
98 procID
= Controls
.pushButProc | Controls
.useWFont
99 ControlWidget
.__init
__(self
, possize
, title
, procID
, callback
, 0, 0, 1)
103 if not self
._enabled
:
106 self
._control
.HiliteControl(1)
108 self
._control
.HiliteControl(0)
110 Wbase
.CallbackCall(self
._callback
, 0)
112 def enable(self
, onoff
):
113 if self
._control
and self
._enabled
<> onoff
:
114 self
._control
.HiliteControl((not onoff
) and 255)
115 self
._enabled
= onoff
116 if self
._isdefault
and self
._visible
:
118 self
.drawfatframe(onoff
)
120 def activate(self
, onoff
):
121 self
._activated
= onoff
123 self
._control
.HiliteControl((not onoff
) and 255)
124 if self
._isdefault
and self
._visible
:
126 self
.drawfatframe(onoff
)
128 def show(self
, onoff
):
129 ControlWidget
.show(self
, onoff
)
131 self
.drawfatframe(onoff
and self
._enabled
)
133 def draw(self
, visRgn
= None):
135 self
._control
.Draw1Control()
136 if self
._isdefault
and self
._activated
:
137 self
.drawfatframe(self
._enabled
)
139 def drawfatframe(self
, onoff
):
140 state
= Qd
.GetPenState()
142 Qd
.PenPat(Qd
.qd
.black
)
144 Qd
.PenPat(Qd
.qd
.white
)
145 fatrect
= Qd
.InsetRect(self
._bounds
, -4, -4)
147 Qd
.FrameRoundRect(fatrect
, 16, 16)
148 Qd
.SetPenState(state
)
150 def _setdefault(self
, onoff
):
151 self
._isdefault
= onoff
154 self
.drawfatframe(onoff
)
156 def adjust(self
, oldbounds
):
158 old
= Qd
.InsetRect(oldbounds
, -4, -4)
159 new
= Qd
.InsetRect(self
._bounds
, -4, -4)
163 ControlWidget
.adjust(self
, oldbounds
)
166 class CheckBox(ControlWidget
):
168 def __init__(self
, possize
, title
= "Checkbox", callback
= None, value
= 0):
169 procID
= Controls
.checkBoxProc | Controls
.useWFont
170 ControlWidget
.__init
__(self
, possize
, title
, procID
, callback
, value
, 0, 1)
172 def click(self
, point
, modifiers
):
173 if not self
._enabled
:
175 part
= self
._control
.TrackControl(point
)
179 Wbase
.CallbackCall(self
._callback
, 0, self
.get())
182 if not self
._enabled
:
186 Wbase
.CallbackCall(self
._callback
, 0, self
.get())
189 self
.set(not self
.get())
191 def set(self
, value
):
193 self
._control
.SetControlValue(value
)
199 return self
._control
.GetControlValue()
204 class RadioButton(ControlWidget
):
206 def __init__(self
, possize
, title
= "Radiobutton", thebuttons
, callback
= None, value
= 0):
207 procID
= Controls
.radioButProc | Controls
.useWFont
208 ControlWidget
.__init
__(self
, possize
, title
, procID
, callback
, value
, 0, 1)
209 self
.thebuttons
= thebuttons
210 thebuttons
.append(self
)
213 self
.thebuttons
= None
214 ControlWidget
.close(self
)
216 def click(self
, point
, modifiers
):
217 if not self
._enabled
:
219 part
= self
._control
.TrackControl(point
)
223 Wbase
.CallbackCall(self
._callback
, 0, 1)
226 if not self
._enabled
:
230 Wbase
.CallbackCall(self
._callback
, 0, 1)
232 def set(self
, value
):
233 for button
in self
.thebuttons
:
235 button
._control
.SetControlValue(button
== self
)
237 button
._value
= (button
== self
)
241 return self
._control
.GetControlValue()
246 class Scrollbar(ControlWidget
):
248 def __init__(self
, possize
, callback
= None, value
= 0, min = 0, max = 0):
249 procID
= Controls
.scrollBarProc
250 ControlWidget
.__init
__(self
, possize
, "", procID
, callback
, value
, min, max)
253 def set(self
, value
):
255 Wbase
.CallbackCall(self
._callback
, 1, value
)
259 Wbase
.CallbackCall(self
._callback
, 1, '+')
263 Wbase
.CallbackCall(self
._callback
, 1, '-')
267 Wbase
.CallbackCall(self
._callback
, 1, '++')
271 Wbase
.CallbackCall(self
._callback
, 1, '--')
273 def setmin(self
, min):
274 self
._control
.SetControlMinimum(min)
276 def setmax(self
, min):
277 self
._control
.SetControlMinimum(max)
280 return self
._control
.GetControlMinimum()
283 return self
._control
.GetControlMinimum()
286 def click(self
, point
, modifiers
):
287 if not self
._enabled
:
289 # custom TrackControl. A mousedown in a scrollbar arrow or page area should
290 # generate _control hits as long as the mouse is a) down, b) still in the same part
291 part
= self
._control
.TestControl(point
)
292 if Controls
.inUpButton
<= part
<= Controls
.inPageDown
:
293 self
._control
.HiliteControl(part
)
296 while Evt
.StillDown():
297 part
= self
._control
.TestControl(point
)
299 self
._control
.HiliteControl(part
)
302 self
._control
.HiliteControl(0)
304 point
= Evt
.GetMouse()
305 self
._control
.HiliteControl(0)
306 elif part
== Controls
.inThumb
:
307 part
= self
._control
.TrackControl(point
)
311 def _hit(self
, part
):
312 if part
== Controls
.inThumb
:
313 value
= self
._control
.GetControlValue()
314 elif part
== Controls
.inUpButton
:
316 elif part
== Controls
.inDownButton
:
318 elif part
== Controls
.inPageUp
:
320 elif part
== Controls
.inPageDown
:
323 Wbase
.CallbackCall(self
._callback
, 1, value
)
325 def draw(self
, visRgn
= None):
327 self
._control
.Draw1Control()
328 Qd
.FrameRect(self
._bounds
)
330 def adjust(self
, oldbounds
):
332 Win
.InvalRect(oldbounds
)
333 self
._control
.HideControl()
334 self
._control
.MoveControl(self
._bounds
[0], self
._bounds
[1])
335 self
._control
.SizeControl(self
._bounds
[2] - self
._bounds
[0], self
._bounds
[3] - self
._bounds
[1])
337 Qd
.EraseRect(self
._bounds
)
339 self
._control
.ShowControl()
341 Qd
.FrameRect(self
._bounds
)
342 Win
.ValidRect(self
._bounds
)
344 def activate(self
, onoff
):
345 self
._activated
= onoff
348 self
._control
.ShowControl()
350 self
._control
.HideControl()
352 Win
.ValidRect(self
._bounds
)
354 def set(self
, value
):
356 self
._control
.SetControlValue(value
)
362 return self
._control
.GetControlValue()
367 def _scalebarvalue(absmin
, absmax
, curmin
, curmax
):
368 if curmin
<= absmin
and curmax
>= absmax
:
374 perc
= float(curmin
-absmin
) / float((absmax
- absmin
) - (curmax
- curmin
))
375 return int(perc
*32767)