]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/analogclock/setup.py
   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. 
  10 import lib_setup
.colourselect 
as csel
 
  11 import lib_setup
.fontselect 
as fsel
 
  12 import lib_setup
.buttontreectrlpanel 
as bt
 
  14 #---------------------------------------------------------------------- 
  16 _window_styles 
= ['wx.SIMPLE_BORDER', 'wx.DOUBLE_BORDER', 'wx.SUNKEN_BORDER', 
  17                   'wx.RAISED_BORDER', 'wx.STATIC_BORDER', 'wx.NO_BORDER'] 
  19 #---------------------------------------------------------------------- 
  21 class _GroupBase(wx
.Panel
): 
  22     def __init__(self
, parent
, title
, group
): 
  23         wx
.Panel
.__init
__(self
, parent
) 
  26         self
.clock  
= self
.parent
.clock
 
  28         self
.target 
= {"Hours":   styles
.HOUR
, 
  29                        "Minutes": styles
.MINUTE
, 
  30                        "Seconds": styles
.SECOND
}.get(title
) 
  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
) 
  39     def OnSelectFont(self
, evt
): 
  40         self
.clock
.SetTickFont(evt
.val
, self
.target
) 
  43     def OnSelectColour(self
, evt
): 
  44         obj 
= evt
.obj
; val 
= evt
.val
 
  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
) 
  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
) 
  62         elif hasattr(self
, "sw") and obj 
== self
.sw
: 
  63             self
.clock
.SetShadowColour(val
) 
  65         elif hasattr(self
, "bg") and obj 
== self
.bg
: 
  66             self
.clock
.SetBackgroundColour(val
) 
  68         elif hasattr(self
, "fg") and obj 
== self
.fg
: 
  69             self
.clock
.SetForegroundColour(val
) 
  70             self
.parent
.GetGrandParent().UpdateControls() 
  73     def OnSpin(self
, evt
): 
  74         obj 
= evt
.GetEventObject(); val 
= evt
.GetInt() 
  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
) 
  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
) 
  90         elif hasattr(self
, "of") and obj 
== self
.of
: 
  91             self
.clock
.SetTickOffset(val
, self
.target
) 
  94     def OnChoice(self
, evt
): 
  95         self
.clock
.SetWindowStyle(eval(evt
.GetString())) 
  98     def UpdateControls(self
): 
  99         if hasattr(self
, "ft"): 
 100             self
.ft
.SetValue(self
.clock
.GetTickFont(self
.target
)[0]) 
 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()) 
 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()) 
 118         if hasattr(self
, "sw"): 
 119             self
.sw
.SetValue(self
.clock
.GetShadowColour()) 
 121         if hasattr(self
, "bg"): 
 122             self
.bg
.SetValue(self
.clock
.GetBackgroundColour()) 
 124         if hasattr(self
, "fg"): 
 125             self
.fg
.SetValue(self
.clock
.GetForegroundColour()) 
 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()) 
 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]) 
 141         if hasattr(self
, "of"): 
 142             self
.of
.SetValue(self
.clock
.GetTickOffset(self
.target
)[0]) 
 144         if hasattr(self
, "ws"): 
 145             for style 
in _window_styles
: 
 146                 if self
.clock
.GetWindowStyleFlag() & eval(style
): 
 147                     self
.ws
.SetStringSelection(style
) 
 150 #---------------------------------------------------------------------- 
 152 class _Group_1(_GroupBase
): 
 153     def __init__(self
, parent
, title
, group
="Hands"): 
 154         _GroupBase
.__init
__(self
, parent
, title
, group
) 
 156         box 
= wx
.StaticBoxSizer(wx
.StaticBox(self
, label
=title
), wx
.VERTICAL
) 
 158         sizer 
= self
.sizer 
= wx
.GridBagSizer(2, 6) 
 160         p 
= wx
.StaticText(self
, label
="Border:") 
 161         sizer
.Add(p
, pos
=(0, 0), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 163         p 
= self
.bc 
= csel
.ColourSelect(self
) 
 164         sizer
.Add(p
, pos
=(0, 1), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 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
) 
 170         p 
= wx
.StaticText(self
, label
="Fill:") 
 171         sizer
.Add(p
, pos
=(1, 0), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 173         p 
= self
.fc 
= csel
.ColourSelect(self
) 
 174         sizer
.Add(p
, pos
=(1, 1), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 176         p 
= self
.ls 
= wx
.StaticText(self
, label
="Size:") 
 177         sizer
.Add(p
, pos
=(2, 0), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 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
) 
 187 #---------------------------------------------------------------------- 
 189 class _Group_2(_Group_1
): 
 190     def __init__(self
, parent
, title
, group
="Ticks"): 
 191         _Group_1
.__init
__(self
, parent
, title
, group
) 
 195         p 
= wx
.StaticText(self
, label
="Offset:") 
 196         sizer
.Add(p
, pos
=(3, 0), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 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
) 
 202         p 
= wx
.StaticText(self
, label
="Font:") 
 203         sizer
.Add(p
, pos
=(4, 0), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 205         p 
= self
.ft 
= fsel
.FontSelect(self
) 
 206         sizer
.Add(p
, pos
=(4, 1), span
=(1, 3), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 208         self
.GetSizer().Layout() 
 210 #---------------------------------------------------------------------- 
 212 class _Group_3(_Group_1
): 
 213     def __init__(self
, parent
, title
, group
="Face"): 
 214         _Group_1
.__init
__(self
, parent
, title
, group
) 
 218         for widget 
in [self
.ls
, self
.sz
]: 
 223         p 
= wx
.StaticText(self
, label
="Shadow:") 
 224         sizer
.Add(p
, pos
=(2, 0), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 226         p 
= self
.sw 
= csel
.ColourSelect(self
) 
 227         sizer
.Add(p
, pos
=(2, 1), span
=(1, 3), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 229         self
.GetSizer().Layout() 
 231 #---------------------------------------------------------------------- 
 233 class _Group_4(_GroupBase
): 
 234     def __init__(self
, parent
, title
, group
="Window"): 
 235         _GroupBase
.__init
__(self
, parent
, title
, group
) 
 237         box 
= wx
.StaticBoxSizer(wx
.StaticBox(self
, label
=title
), wx
.VERTICAL
) 
 239         sizer 
= self
.sizer 
= wx
.GridBagSizer(2, 6) 
 241         p 
= wx
.StaticText(self
, label
="Foreground:") 
 242         sizer
.Add(p
, pos
=(0, 0), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 244         p 
= self
.fg 
= csel
.ColourSelect(self
) 
 245         sizer
.Add(p
, pos
=(0, 1), span
=(1, 3), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 247         p 
= wx
.StaticText(self
, label
="Background:") 
 248         sizer
.Add(p
, pos
=(1, 0), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 250         p 
= self
.bg 
= csel
.ColourSelect(self
) 
 251         sizer
.Add(p
, pos
=(1, 1), span
=(1, 3), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 253         p 
= wx
.StaticText(self
, label
="Style:") 
 254         sizer
.Add(p
, pos
=(2, 0), flag
=wx
.ALIGN_CENTRE_VERTICAL
) 
 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
) 
 263 #---------------------------------------------------------------------- 
 265 class _PageBase(wx
.Panel
): 
 266     def __init__(self
, parent
): 
 267         wx
.Panel
.__init
__(self
, parent
) 
 269         self
.clock 
= self
.GetGrandParent().GetParent() 
 270         self
.sizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 271         self
.SetSizer(self
.sizer
) 
 274     def UpdateControls(self
): 
 275         [group
.UpdateControls() for group 
in self
.GetChildren()] 
 277 #---------------------------------------------------------------------- 
 279 class StylesPanel(bt
.ButtonTreeCtrlPanel
): 
 280     def __init__(self
, parent
): 
 281         bt
.ButtonTreeCtrlPanel
.__init
__(self
, parent
) 
 283         self
.clock 
= self
.GetGrandParent().GetParent() 
 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
] 
 291         clockStyle 
= self
.clock
.GetClockStyle() 
 292         hourStyle
, minuteStyle 
= self
.clock
.GetTickStyle() 
 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
) 
 299                 value 
= bool(getattr(styles
, label
) & minuteStyle
) 
 300                 self
.AddItem(label
, parent
=g3
, style
=wx
.RB_SINGLE
, value
=value
) 
 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
) 
 308         self
.EnsureFirstVisible() 
 310         self
.Bind(bt
.EVT_CHANGED
, self
.OnChanged
) 
 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
] 
 320         self
.clock
.SetClockStyle(clockStyle
) 
 321         self
.clock
.SetTickStyle(hourStyle
, styles
.HOUR
) 
 322         self
.clock
.SetTickStyle(minuteStyle
, styles
.MINUTE
) 
 325     def UpdateControls(self
): 
 326         clockStyle 
= self
.clock
.GetClockStyle() 
 327         hourStyle
, minuteStyle 
= self
.clock
.GetTickStyle() 
 329         [g1
, g2
, g3
] = self
.groups
 
 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
) 
 337                 item 
= self
.GetItemByLabel(label
, g3
) 
 338                 value 
= bool(getattr(styles
, label
) & minuteStyle
) 
 339                 self
.SetItemValue(item
, value
) 
 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
) 
 348 #---------------------------------------------------------------------- 
 350 class HandsPanel(_PageBase
): 
 351     def __init__(self
, parent
): 
 352         _PageBase
.__init
__(self
, parent
) 
 354         [self
.sizer
.Add(_Group_1(self
, title
), 1, 
 355                         flag
=wx
.EXPAND|wx
.ALL
, border
=6) \
 
 356          for title 
in ["Hours", "Minutes", "Seconds"]] 
 358 #---------------------------------------------------------------------- 
 360 class TicksPanel(_PageBase
): 
 361     def __init__(self
, parent
): 
 362         _PageBase
.__init
__(self
, parent
) 
 364         [self
.sizer
.Add(_Group_2(self
, title
), 1, 
 365                         flag
=wx
.EXPAND|wx
.ALL
, border
=6) \
 
 366          for title 
in ["Hours", "Minutes"]] 
 368 #---------------------------------------------------------------------- 
 370 class MiscPanel(_PageBase
): 
 371     def __init__(self
, parent
): 
 372         _PageBase
.__init
__(self
, parent
) 
 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) 
 379 #---------------------------------------------------------------------- 
 381 class Setup(wx
.Dialog
): 
 382     """AnalogClock customization dialog.""" 
 384     def __init__(self
, parent
): 
 385         wx
.Dialog
.__init
__(self
, parent
, title
="AnalogClock Setup") 
 387         sizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 389         nb 
= self
.nb 
= wx
.Notebook(self
) 
 390         for s 
in ["Styles", "Hands", "Ticks", "Misc"]: 
 391             page 
= eval(s 
+ "Panel(nb)"); page
.Fit() 
 394         sizer
.Add(nb
, 1, flag 
= wx
.EXPAND|wx
.ALL
, border
=6) 
 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) 
 403         self
.Bind(wx
.EVT_SHOW
, self
.OnShow
) 
 404         self
.Bind(wx
.EVT_CLOSE
, self
.OnClose
) 
 405         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
) 
 407         self
.customcolours 
= [None] * 16 
 409         self
.SetSizerAndFit(sizer
) 
 412     def OnShow(self
, evt
): 
 414             self
.UpdateControls() 
 418     def OnClose(self
, evt
): 
 422     def OnButton(self
, evt
): 
 423         if evt
.GetEventObject().GetLabel() == "Reset": 
 428     def UpdateControls(self
): 
 430         for i 
in range(self
.nb
.GetPageCount()): 
 431             self
.nb
.GetPage(i
).UpdateControls() 
 435     def ResetClock(self
): 
 436         clock 
= self
.GetParent() 
 440         clock
.SetClockStyle(styles
.DEFAULT_CLOCK_STYLE
) 
 441         clock
.SetTickStyle(styles
.TICKS_POLY
, styles
.HOUR
) 
 442         clock
.SetTickStyle(styles
.TICKS_CIRCLE
, styles
.MINUTE
) 
 444         clock
.SetTickFont(wx
.SystemSettings
.GetFont(wx
.SYS_DEFAULT_GUI_FONT
)) 
 446         clock
.SetHandBorderWidth(0) 
 447         clock
.SetTickBorderWidth(0) 
 448         clock
.SetFaceBorderWidth(0) 
 450         clock
.SetHandSize(7, styles
.HOUR
) 
 451         clock
.SetHandSize(5, styles
.MINUTE
) 
 452         clock
.SetHandSize(1, styles
.SECOND
) 
 454         clock
.SetTickSize(25, styles
.HOUR
) 
 455         clock
.SetTickSize(5,  styles
.MINUTE
) 
 457         clock
.SetTickOffset(0) 
 459         clock
.SetWindowStyle(wx
.NO_BORDER
) 
 461         sw 
= wx
.SystemSettings
.GetColour(wx
.SYS_COLOUR_3DSHADOW
) 
 462         clock
.SetShadowColour(sw
) 
 464         no_color 
= wx
.SystemSettings
.GetColour(wx
.SYS_COLOUR_3DFACE
) 
 465         clock
.SetFaceFillColour(no_color
) 
 466         clock
.SetFaceBorderColour(no_color
) 
 467         clock
.SetBackgroundColour(no_color
) 
 469         fg 
= wx
.SystemSettings
.GetColour(wx
.SYS_COLOUR_WINDOWTEXT
) 
 470         clock
.SetForegroundColour(fg
) 
 472         self
.UpdateControls()