]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/lib/analogclock/setup.py
added missing button state
[wxWidgets.git] / wxPython / wx / lib / analogclock / setup.py
CommitLineData
caeac82e
RD
1# AnalogClock setup dialog
2# E. A. Tacao <e.a.tacao |at| estadao.com.br>
3# http://j.domaindlx.com/elements28/wxpython/
4# 15 Fev 2006, 22:00 GMT-03:00
5# Distributed under the wxWidgets license.
6
7import wx
8
9import styles
10import lib_setup.colourselect as csel
11import lib_setup.fontselect as fsel
12import lib_setup.buttontreectrlpanel as bt
13
14#----------------------------------------------------------------------
15
16_window_styles = ['wx.SIMPLE_BORDER', 'wx.DOUBLE_BORDER', 'wx.SUNKEN_BORDER',
17 'wx.RAISED_BORDER', 'wx.STATIC_BORDER', 'wx.NO_BORDER']
18
19#----------------------------------------------------------------------
20
21class _GroupBase(wx.Panel):
22 def __init__(self, parent, title, group):
23 wx.Panel.__init__(self, parent)
24
25 self.parent = parent
26 self.clock = self.parent.clock
27 self.group = group
28 self.target = {"Hours": styles.HOUR,
29 "Minutes": styles.MINUTE,
30 "Seconds": styles.SECOND}.get(title)
31
32 self.Bind(fsel.EVT_FONTSELECT, self.OnSelectFont)
33 self.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour)
34 self.Bind(wx.EVT_SPINCTRL, self.OnSpin)
35 self.Bind(wx.EVT_TEXT_ENTER, self.OnSpin)
36 self.Bind(wx.EVT_CHOICE, self.OnChoice)
37
38
39 def OnSelectFont(self, evt):
40 self.clock.SetTickFont(evt.val, self.target)
41
42
43 def OnSelectColour(self, evt):
44 obj = evt.obj; val = evt.val
45
46 if hasattr(self, "fc") and obj == self.fc:
47 if self.group == "Hands":
48 self.clock.SetHandFillColour(val, self.target)
49 elif self.group == "Ticks":
50 self.clock.SetTickFillColour(val, self.target)
51 elif self.group == "Face":
52 self.clock.SetFaceFillColour(val)
53
54 elif hasattr(self, "bc") and obj == self.bc:
55 if self.group == "Hands":
56 self.clock.SetHandBorderColour(val, self.target)
57 elif self.group == "Ticks":
58 self.clock.SetTickBorderColour(val, self.target)
59 elif self.group == "Face":
60 self.clock.SetFaceBorderColour(val)
61
62 elif hasattr(self, "sw") and obj == self.sw:
63 self.clock.SetShadowColour(val)
64
65 elif hasattr(self, "bg") and obj == self.bg:
66 self.clock.SetBackgroundColour(val)
67
68 elif hasattr(self, "fg") and obj == self.fg:
69 self.clock.SetForegroundColour(val)
70 self.parent.GetGrandParent().UpdateControls()
71
72
73 def OnSpin(self, evt):
74 obj = evt.GetEventObject(); val = evt.GetInt()
75
76 if hasattr(self, "bw") and obj == self.bw:
77 if self.group == "Hands":
78 self.clock.SetHandBorderWidth(val, self.target)
79 elif self.group == "Ticks":
80 self.clock.SetTickBorderWidth(val, self.target)
81 elif self.group == "Face":
82 self.clock.SetFaceBorderWidth(val)
83
84 elif hasattr(self, "sz") and obj == self.sz:
85 if self.group == "Hands":
86 self.clock.SetHandSize(val, self.target)
87 elif self.group == "Ticks":
88 self.clock.SetTickSize(val, self.target)
89
90 elif hasattr(self, "of") and obj == self.of:
91 self.clock.SetTickOffset(val, self.target)
92
93
94 def OnChoice(self, evt):
95 self.clock.SetWindowStyle(eval(evt.GetString()))
96
97
98 def UpdateControls(self):
99 if hasattr(self, "ft"):
100 self.ft.SetValue(self.clock.GetTickFont(self.target)[0])
101
102 if hasattr(self, "fc"):
103 if self.group == "Hands":
104 self.fc.SetValue(self.clock.GetHandFillColour(self.target)[0])
105 elif self.group == "Ticks":
106 self.fc.SetValue(self.clock.GetTickFillColour(self.target)[0])
107 elif self.group == "Face":
108 self.fc.SetValue(self.clock.GetFaceFillColour())
109
110 if hasattr(self, "bc"):
111 if self.group == "Hands":
112 self.bc.SetValue(self.clock.GetHandBorderColour(self.target)[0])
113 elif self.group == "Ticks":
114 self.bc.SetValue(self.clock.GetTickBorderColour(self.target)[0])
115 elif self.group == "Face":
116 self.bc.SetValue(self.clock.GetFaceBorderColour())
117
118 if hasattr(self, "sw"):
119 self.sw.SetValue(self.clock.GetShadowColour())
120
121 if hasattr(self, "bg"):
122 self.bg.SetValue(self.clock.GetBackgroundColour())
123
124 if hasattr(self, "fg"):
125 self.fg.SetValue(self.clock.GetForegroundColour())
126
127 if hasattr(self, "bw"):
128 if self.group == "Hands":
129 self.bw.SetValue(self.clock.GetHandBorderWidth(self.target)[0])
130 elif self.group == "Ticks":
131 self.bw.SetValue(self.clock.GetTickBorderWidth(self.target)[0])
132 elif self.group == "Face":
133 self.bw.SetValue(self.clock.GetFaceBorderWidth())
134
135 if hasattr(self, "sz"):
136 if self.group == "Hands":
137 self.sz.SetValue(self.clock.GetHandSize(self.target)[0])
138 elif self.group == "Ticks":
139 self.sz.SetValue(self.clock.GetTickSize(self.target)[0])
140
141 if hasattr(self, "of"):
142 self.of.SetValue(self.clock.GetTickOffset(self.target)[0])
143
144 if hasattr(self, "ws"):
145 for style in _window_styles:
146 if self.clock.GetWindowStyleFlag() & eval(style):
147 self.ws.SetStringSelection(style)
148 break
149
150#----------------------------------------------------------------------
151
152class _Group_1(_GroupBase):
153 def __init__(self, parent, title, group="Hands"):
154 _GroupBase.__init__(self, parent, title, group)
155
156 box = wx.StaticBoxSizer(wx.StaticBox(self, label=title), wx.VERTICAL)
157
158 sizer = self.sizer = wx.GridBagSizer(2, 6)
159
160 p = wx.StaticText(self, label="Border:")
161 sizer.Add(p, pos=(0, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
162
163 p = self.bc = csel.ColourSelect(self)
164 sizer.Add(p, pos=(0, 1), flag=wx.ALIGN_CENTRE_VERTICAL)
165
166 p = self.bw = wx.SpinCtrl(self, size=(75, 21),
167 min=0, max=100, value="75")
168 sizer.Add(p, pos=(0, 2), span=(1, 2), flag=wx.ALIGN_CENTRE_VERTICAL)
169
170 p = wx.StaticText(self, label="Fill:")
171 sizer.Add(p, pos=(1, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
172
173 p = self.fc = csel.ColourSelect(self)
174 sizer.Add(p, pos=(1, 1), flag=wx.ALIGN_CENTRE_VERTICAL)
175
176 p = self.ls = wx.StaticText(self, label="Size:")
177 sizer.Add(p, pos=(2, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
178
179 p = self.sz = wx.SpinCtrl(self, size=(75, 21),
180 min=0, max=100, value="75")
181 sizer.Add(p, pos=(2, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
182
183 box.Add(sizer)
184
185 self.SetSizer(box)
186
187#----------------------------------------------------------------------
188
189class _Group_2(_Group_1):
190 def __init__(self, parent, title, group="Ticks"):
191 _Group_1.__init__(self, parent, title, group)
192
193 sizer = self.sizer
194
195 p = wx.StaticText(self, label="Offset:")
196 sizer.Add(p, pos=(3, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
197
198 p = self.of = wx.SpinCtrl(self, size=(75, 21),
199 min=0, max=100, value="75")
200 sizer.Add(p, pos=(3, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
201
202 p = wx.StaticText(self, label="Font:")
203 sizer.Add(p, pos=(4, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
204
205 p = self.ft = fsel.FontSelect(self)
206 sizer.Add(p, pos=(4, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
207
208 self.GetSizer().Layout()
209
210#----------------------------------------------------------------------
211
212class _Group_3(_Group_1):
213 def __init__(self, parent, title, group="Face"):
214 _Group_1.__init__(self, parent, title, group)
215
216 sizer = self.sizer
217
218 for widget in [self.ls, self.sz]:
219 sizer.Detach(widget)
220 widget.Destroy()
221 sizer.Layout()
222
223 p = wx.StaticText(self, label="Shadow:")
224 sizer.Add(p, pos=(2, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
225
226 p = self.sw = csel.ColourSelect(self)
227 sizer.Add(p, pos=(2, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
228
229 self.GetSizer().Layout()
230
231#----------------------------------------------------------------------
232
233class _Group_4(_GroupBase):
234 def __init__(self, parent, title, group="Window"):
235 _GroupBase.__init__(self, parent, title, group)
236
237 box = wx.StaticBoxSizer(wx.StaticBox(self, label=title), wx.VERTICAL)
238
239 sizer = self.sizer = wx.GridBagSizer(2, 6)
240
241 p = wx.StaticText(self, label="Foreground:")
242 sizer.Add(p, pos=(0, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
243
244 p = self.fg = csel.ColourSelect(self)
245 sizer.Add(p, pos=(0, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
246
247 p = wx.StaticText(self, label="Background:")
248 sizer.Add(p, pos=(1, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
249
250 p = self.bg = csel.ColourSelect(self)
251 sizer.Add(p, pos=(1, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
252
253 p = wx.StaticText(self, label="Style:")
254 sizer.Add(p, pos=(2, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
255
256 p = self.ws = wx.Choice(self, choices=_window_styles)
257 sizer.Add(p, pos=(2, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
258
259 box.Add(sizer)
260
261 self.SetSizer(box)
262
263#----------------------------------------------------------------------
264
265class _PageBase(wx.Panel):
266 def __init__(self, parent):
267 wx.Panel.__init__(self, parent)
268
269 self.clock = self.GetGrandParent().GetParent()
270 self.sizer = wx.BoxSizer(wx.VERTICAL)
271 self.SetSizer(self.sizer)
272
273
274 def UpdateControls(self):
275 [group.UpdateControls() for group in self.GetChildren()]
276
277#----------------------------------------------------------------------
278
279class StylesPanel(bt.ButtonTreeCtrlPanel):
280 def __init__(self, parent):
281 bt.ButtonTreeCtrlPanel.__init__(self, parent)
282
283 self.clock = self.GetGrandParent().GetParent()
284
285 root = self.AddItem("Styles")
286 g1 = self.AddItem("General", parent=root)
287 g2 = self.AddItem("Hours", parent=root)
288 g3 = self.AddItem("Minutes", parent=root)
289 self.groups = [g1, g2, g3]
290
291 clockStyle = self.clock.GetClockStyle()
292 hourStyle, minuteStyle = self.clock.GetTickStyle()
293
294 for label in dir(styles):
295 if label.startswith("TICKS_"):
296 value = bool(getattr(styles, label) & hourStyle)
297 self.AddItem(label, parent=g2, style=wx.RB_SINGLE, value=value)
298
299 value = bool(getattr(styles, label) & minuteStyle)
300 self.AddItem(label, parent=g3, style=wx.RB_SINGLE, value=value)
301
302 elif not (label.startswith("DEFAULT_") or \
303 label.startswith("_") or \
304 label in ["HOUR", "MINUTE", "SECOND", "ALL"]):
305 value = bool(getattr(styles, label) & clockStyle)
306 self.AddItem(label, parent=g1, style=wx.CHK_2STATE, value=value)
307
308 self.EnsureFirstVisible()
309
310 self.Bind(bt.EVT_CHANGED, self.OnChanged)
311
312
313 def OnChanged(self, evt):
314 clockStyle, hourStyle, minuteStyle = \
315 [reduce(lambda x, y: x | y,
316 [getattr(styles, item) \
317 for item in self.GetStringItemsChecked(group)], 0) \
318 for group in self.groups]
319
320 self.clock.SetClockStyle(clockStyle)
321 self.clock.SetTickStyle(hourStyle, styles.HOUR)
322 self.clock.SetTickStyle(minuteStyle, styles.MINUTE)
323
324
325 def UpdateControls(self):
326 clockStyle = self.clock.GetClockStyle()
327 hourStyle, minuteStyle = self.clock.GetTickStyle()
328
329 [g1, g2, g3] = self.groups
330
331 for label in dir(styles):
332 if label.startswith("TICKS_"):
333 item = self.GetItemByLabel(label, g2)
334 value = bool(getattr(styles, label) & hourStyle)
335 self.SetItemValue(item, value)
336
337 item = self.GetItemByLabel(label, g3)
338 value = bool(getattr(styles, label) & minuteStyle)
339 self.SetItemValue(item, value)
340
341 elif not (label.startswith("DEFAULT_") or \
342 label.startswith("_") or \
343 label in ["HOUR", "MINUTE", "SECOND", "ALL"]):
344 item = self.GetItemByLabel(label, g1)
345 value = bool(getattr(styles, label) & clockStyle)
346 self.SetItemValue(item, value)
347
348#----------------------------------------------------------------------
349
350class HandsPanel(_PageBase):
351 def __init__(self, parent):
352 _PageBase.__init__(self, parent)
353
354 [self.sizer.Add(_Group_1(self, title), 1,
355 flag=wx.EXPAND|wx.ALL, border=6) \
356 for title in ["Hours", "Minutes", "Seconds"]]
357
358#----------------------------------------------------------------------
359
360class TicksPanel(_PageBase):
361 def __init__(self, parent):
362 _PageBase.__init__(self, parent)
363
364 [self.sizer.Add(_Group_2(self, title), 1,
365 flag=wx.EXPAND|wx.ALL, border=6) \
366 for title in ["Hours", "Minutes"]]
367
368#----------------------------------------------------------------------
369
370class MiscPanel(_PageBase):
371 def __init__(self, parent):
372 _PageBase.__init__(self, parent)
373
374 self.sizer.Add(_Group_3(self, "Face"), 1,
375 flag=wx.EXPAND|wx.ALL, border=6)
376 self.sizer.Add(_Group_4(self, "Window"), 1,
377 flag=wx.EXPAND|wx.ALL, border=6)
378
379#----------------------------------------------------------------------
380
381class Setup(wx.Dialog):
382 """AnalogClock customization dialog."""
383
384 def __init__(self, parent):
385 wx.Dialog.__init__(self, parent, title="AnalogClock Setup")
386
387 sizer = wx.BoxSizer(wx.VERTICAL)
388
389 nb = self.nb = wx.Notebook(self)
390 for s in ["Styles", "Hands", "Ticks", "Misc"]:
391 page = eval(s + "Panel(nb)"); page.Fit()
392 nb.AddPage(page, s)
393 nb.Fit()
394 sizer.Add(nb, 1, flag = wx.EXPAND|wx.ALL, border=6)
395
396 bsizer = wx.BoxSizer(wx.HORIZONTAL)
397 bsizer.Add(wx.Button(self, label="Reset"),
398 flag = wx.LEFT|wx.RIGHT, border=6)
399 bsizer.Add(wx.Button(self, wx.ID_OK),
400 flag = wx.LEFT|wx.RIGHT, border=6)
401 sizer.Add(bsizer, 0, flag=wx.ALIGN_RIGHT|wx.ALL, border=6)
402
caeac82e
RD
403 self.Bind(wx.EVT_CLOSE, self.OnClose)
404 self.Bind(wx.EVT_BUTTON, self.OnButton)
405
406 self.customcolours = [None] * 16
407
408 self.SetSizerAndFit(sizer)
70e8e9b8
RD
409 wx.CallAfter(self.UpdateControls)
410
caeac82e
RD
411
412 def OnClose(self, evt):
413 self.Hide()
414
415
416 def OnButton(self, evt):
417 if evt.GetEventObject().GetLabel() == "Reset":
418 self.ResetClock()
419 evt.Skip()
420
421
422 def UpdateControls(self):
423 wx.BeginBusyCursor()
424 for i in range(self.nb.GetPageCount()):
425 self.nb.GetPage(i).UpdateControls()
426 wx.EndBusyCursor()
427
428
429 def ResetClock(self):
430 clock = self.GetParent()
431
432 wx.BeginBusyCursor()
433
434 clock.SetClockStyle(styles.DEFAULT_CLOCK_STYLE)
435 clock.SetTickStyle(styles.TICKS_POLY, styles.HOUR)
436 clock.SetTickStyle(styles.TICKS_CIRCLE, styles.MINUTE)
437
438 clock.SetTickFont(wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT))
439
440 clock.SetHandBorderWidth(0)
441 clock.SetTickBorderWidth(0)
442 clock.SetFaceBorderWidth(0)
443
444 clock.SetHandSize(7, styles.HOUR)
445 clock.SetHandSize(5, styles.MINUTE)
446 clock.SetHandSize(1, styles.SECOND)
447
448 clock.SetTickSize(25, styles.HOUR)
449 clock.SetTickSize(5, styles.MINUTE)
450
451 clock.SetTickOffset(0)
452
453 clock.SetWindowStyle(wx.NO_BORDER)
454
455 sw = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DSHADOW)
456 clock.SetShadowColour(sw)
457
458 no_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DFACE)
459 clock.SetFaceFillColour(no_color)
460 clock.SetFaceBorderColour(no_color)
461 clock.SetBackgroundColour(no_color)
462
463 fg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
464 clock.SetForegroundColour(fg)
465
466 self.UpdateControls()
467
468 wx.EndBusyCursor()
469
470
471#
472#
473### eof