2 import wx
.lib
.buttonpanel
as bp
7 #----------------------------------------------------------------------
9 ID_BackgroundColour
= wx
.NewId()
10 ID_GradientFrom
= wx
.NewId()
11 ID_GradientTo
= wx
.NewId()
12 ID_BorderColour
= wx
.NewId()
13 ID_CaptionColour
= wx
.NewId()
14 ID_ButtonTextColour
= wx
.NewId()
15 ID_SelectionBrush
= wx
.NewId()
16 ID_SelectionPen
= wx
.NewId()
17 ID_SeparatorColour
= wx
.NewId()
20 #----------------------------------------------------------------------
21 # Some icons for the demo
22 #----------------------------------------------------------------------
23 def GetMondrianData():
25 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\
26 \x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID\
27 ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\
28 o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\
29 \xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\
30 \x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\
31 \x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82'
34 def GetMondrianBitmap():
35 return wx
.BitmapFromImage(GetMondrianImage())
38 def GetMondrianImage():
40 stream
= cStringIO
.StringIO(GetMondrianData())
41 return wx
.ImageFromStream(stream
)
44 def GetMondrianIcon():
46 icon
.CopyFromBitmap(GetMondrianBitmap())
49 #----------------------------------------------------------------------
51 class SettingsPanel(wx
.MiniFrame
):
53 def __init__(self
, parent
, id=wx
.ID_ANY
, title
="Settings Panel", pos
=wx
.DefaultPosition
,
55 style
=wx
.SYSTEM_MENU | wx
.CAPTION | wx
.CLOSE_BOX | wx
.FRAME_NO_TASKBAR
56 | wx
.FRAME_FLOAT_ON_PARENT | wx
.CLIP_CHILDREN
):
58 wx
.MiniFrame
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
60 self
.targetTitleBar
= parent
.titleBar
62 self
.panel
= wx
.Panel(self
, -1)
64 self
.coloursizer_staticbox
= wx
.StaticBox(self
.panel
, -1, "Colour Options")
65 self
.bottomsizer_staticbox
= wx
.StaticBox(self
.panel
, -1, "Size Options")
66 self
.stylesizer_staticbox
= wx
.StaticBox(self
.panel
, -1, "ButtonPanel Styles")
67 self
.defaultstyle
= wx
.RadioButton(self
.panel
, -1, "Default Style", style
=wx
.RB_GROUP
)
68 self
.gradientstyle
= wx
.RadioButton(self
.panel
, -1, "Gradient Style")
69 self
.verticalgradient
= wx
.RadioButton(self
.panel
, -1, "Vertical Gradient", style
=wx
.RB_GROUP
)
70 self
.horizontalgradient
= wx
.RadioButton(self
.panel
, -1, "Horizontal Gradient")
72 b
= self
.CreateColorBitmap(wx
.BLACK
)
74 self
.bakbrush
= wx
.BitmapButton(self
.panel
, ID_BackgroundColour
, b
, size
=wx
.Size(50,25))
75 self
.gradientfrom
= wx
.BitmapButton(self
.panel
, ID_GradientFrom
, b
, size
=wx
.Size(50,25))
76 self
.gradientto
= wx
.BitmapButton(self
.panel
, ID_GradientTo
, b
, size
=wx
.Size(50,25))
77 self
.bordercolour
= wx
.BitmapButton(self
.panel
, ID_BorderColour
, b
, size
=wx
.Size(50,25))
78 self
.captioncolour
= wx
.BitmapButton(self
.panel
, ID_CaptionColour
, b
, size
=wx
.Size(50,25))
79 self
.textbuttoncolour
= wx
.BitmapButton(self
.panel
, ID_ButtonTextColour
, b
, size
=wx
.Size(50,25))
80 self
.selectionbrush
= wx
.BitmapButton(self
.panel
, ID_SelectionBrush
, b
, size
=wx
.Size(50,25))
81 self
.selectionpen
= wx
.BitmapButton(self
.panel
, ID_SelectionPen
, b
, size
=wx
.Size(50,25))
82 self
.separatorcolour
= wx
.BitmapButton(self
.panel
, ID_SeparatorColour
, b
, size
=wx
.Size(50,25))
84 self
.separatorspin
= wx
.SpinCtrl(self
.panel
, -1, "7", min=3, max=20,
85 style
=wx
.SP_ARROW_KEYS
)
86 self
.marginspin
= wx
.SpinCtrl(self
.panel
, -1, "6", min=3, max=20,
87 style
=wx
.SP_ARROW_KEYS
)
88 self
.paddingspin
= wx
.SpinCtrl(self
.panel
, -1, "6", min=3, max=20,
89 style
=wx
.SP_ARROW_KEYS
)
90 self
.borderspin
= wx
.SpinCtrl(self
.panel
, -1, "3", min=3, max=7,
91 style
=wx
.SP_ARROW_KEYS
)
93 self
.__set
_properties
()
96 self
.Bind(wx
.EVT_RADIOBUTTON
, self
.OnDefaultStyle
, self
.defaultstyle
)
97 self
.Bind(wx
.EVT_RADIOBUTTON
, self
.OnGradientStyle
, self
.gradientstyle
)
98 self
.Bind(wx
.EVT_RADIOBUTTON
, self
.OnVerticalGradient
, self
.verticalgradient
)
99 self
.Bind(wx
.EVT_RADIOBUTTON
, self
.OnHorizontalGradient
, self
.horizontalgradient
)
100 self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_BackgroundColour
)
101 self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_GradientFrom
)
102 self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_GradientTo
)
103 self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_BorderColour
)
104 self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_CaptionColour
)
105 self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_ButtonTextColour
)
106 self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_SelectionBrush
)
107 self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_SelectionPen
)
108 self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_SeparatorColour
)
110 self
.Bind(wx
.EVT_SPINCTRL
, self
.OnSeparator
, self
.separatorspin
)
111 self
.Bind(wx
.EVT_SPINCTRL
, self
.OnMargins
, self
.marginspin
)
112 self
.Bind(wx
.EVT_SPINCTRL
, self
.OnPadding
, self
.paddingspin
)
113 self
.Bind(wx
.EVT_SPINCTRL
, self
.OnBorder
, self
.borderspin
)
115 self
.Bind(wx
.EVT_CLOSE
, self
.OnClose
)
118 def __set_properties(self
):
120 self
.defaultstyle
.SetFont(wx
.Font(8, wx
.DEFAULT
, wx
.NORMAL
, wx
.BOLD
, 0, ""))
121 self
.defaultstyle
.SetValue(1)
122 self
.gradientstyle
.SetFont(wx
.Font(8, wx
.DEFAULT
, wx
.NORMAL
, wx
.BOLD
, 0, ""))
123 self
.verticalgradient
.SetValue(1)
125 if self
.targetTitleBar
.GetStyle() & bp
.BP_DEFAULT_STYLE
:
126 self
.verticalgradient
.Enable(False)
127 self
.horizontalgradient
.Enable(False)
128 self
.defaultstyle
.SetValue(1)
130 self
.gradientstyle
.SetValue(1)
132 self
.borderspin
.SetValue(self
.targetTitleBar
.GetBPArt().GetMetric(bp
.BP_BORDER_SIZE
))
133 self
.separatorspin
.SetValue(self
.targetTitleBar
.GetBPArt().GetMetric(bp
.BP_SEPARATOR_SIZE
))
134 self
.marginspin
.SetValue(self
.targetTitleBar
.GetBPArt().GetMetric(bp
.BP_MARGINS_SIZE
).x
)
135 self
.paddingspin
.SetValue(self
.targetTitleBar
.GetBPArt().GetMetric(bp
.BP_PADDING_SIZE
).x
)
140 def __do_layout(self
):
142 mainsizer
= wx
.BoxSizer(wx
.VERTICAL
)
143 buttonsizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
144 bottomsizer
= wx
.StaticBoxSizer(self
.bottomsizer_staticbox
, wx
.VERTICAL
)
145 sizer_13
= wx
.BoxSizer(wx
.HORIZONTAL
)
146 sizer_12
= wx
.BoxSizer(wx
.HORIZONTAL
)
147 sizer_11
= wx
.BoxSizer(wx
.HORIZONTAL
)
148 sizer_10
= wx
.BoxSizer(wx
.HORIZONTAL
)
149 coloursizer
= wx
.StaticBoxSizer(self
.coloursizer_staticbox
, wx
.HORIZONTAL
)
150 rightsizer
= wx
.BoxSizer(wx
.VERTICAL
)
151 sizer_9
= wx
.BoxSizer(wx
.HORIZONTAL
)
152 sizer_8
= wx
.BoxSizer(wx
.HORIZONTAL
)
153 sizer_7
= wx
.BoxSizer(wx
.HORIZONTAL
)
154 sizer_6
= wx
.BoxSizer(wx
.HORIZONTAL
)
155 leftsizer
= wx
.BoxSizer(wx
.VERTICAL
)
156 sizer_5
= wx
.BoxSizer(wx
.HORIZONTAL
)
157 sizer_4
= wx
.BoxSizer(wx
.HORIZONTAL
)
158 sizer_3
= wx
.BoxSizer(wx
.HORIZONTAL
)
159 sizer_2
= wx
.BoxSizer(wx
.HORIZONTAL
)
160 sizer_1
= wx
.BoxSizer(wx
.HORIZONTAL
)
161 stylesizer
= wx
.StaticBoxSizer(self
.stylesizer_staticbox
, wx
.VERTICAL
)
162 tophsizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
163 tophsizer2
= wx
.BoxSizer(wx
.VERTICAL
)
165 stylesizer
.Add(self
.defaultstyle
, 0, wx
.ALL|wx
.EXPAND|wx
.ADJUST_MINSIZE
, 5)
167 tophsizer
.Add(self
.gradientstyle
, 0, wx
.LEFT|wx
.RIGHT|wx
.EXPAND|
168 wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
170 tophsizer2
.Add(self
.verticalgradient
, 0, wx
.BOTTOM|wx
.ADJUST_MINSIZE
, 3)
171 tophsizer2
.Add(self
.horizontalgradient
, 0, wx
.ADJUST_MINSIZE
, 0)
173 tophsizer
.Add(tophsizer2
, 1, wx
.LEFT|wx
.EXPAND|wx
.ALIGN_CENTER_VERTICAL
, 10)
175 stylesizer
.Add(tophsizer
, 1, wx
.EXPAND
, 0)
177 mainsizer
.Add(stylesizer
, 0, wx
.ALL|wx
.EXPAND
, 5)
179 label_1
= wx
.StaticText(self
.panel
, -1, "Background Brush Colour:")
180 sizer_1
.Add(label_1
, 0, wx
.ALL|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
181 sizer_1
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
182 sizer_1
.Add(self
.bakbrush
, 0, wx
.ADJUST_MINSIZE
, 0)
184 leftsizer
.Add(sizer_1
, 1, wx
.EXPAND
, 0)
186 label_2
= wx
.StaticText(self
.panel
, -1, "Gradient Colour From:")
187 sizer_2
.Add(label_2
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
188 sizer_2
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
189 sizer_2
.Add(self
.gradientfrom
, 0, wx
.ADJUST_MINSIZE
, 0)
191 leftsizer
.Add(sizer_2
, 1, wx
.EXPAND
, 0)
193 label_3
= wx
.StaticText(self
.panel
, -1, "Gradient Colour To:")
194 sizer_3
.Add(label_3
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
195 sizer_3
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
196 sizer_3
.Add(self
.gradientto
, 0, wx
.ADJUST_MINSIZE
, 0)
198 leftsizer
.Add(sizer_3
, 1, wx
.EXPAND
, 0)
200 label_4
= wx
.StaticText(self
.panel
, -1, "Border Colour:")
201 sizer_4
.Add(label_4
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
202 sizer_4
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
203 sizer_4
.Add(self
.bordercolour
, 0, wx
.ADJUST_MINSIZE
, 0)
205 leftsizer
.Add(sizer_4
, 1, wx
.EXPAND
, 0)
207 label_5
= wx
.StaticText(self
.panel
, -1, "Main Caption Colour:")
208 sizer_5
.Add(label_5
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
209 sizer_5
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
210 sizer_5
.Add(self
.captioncolour
, 0, wx
.ADJUST_MINSIZE
, 0)
212 leftsizer
.Add(sizer_5
, 1, wx
.EXPAND
, 0)
214 coloursizer
.Add(leftsizer
, 0, wx
.ALL|wx
.ALIGN_CENTER_VERTICAL
, 5)
215 coloursizer
.Add((20, 20), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
217 label_6
= wx
.StaticText(self
.panel
, -1, "Text Button Colour:")
218 sizer_6
.Add(label_6
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
219 sizer_6
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
220 sizer_6
.Add(self
.textbuttoncolour
, 0, wx
.ADJUST_MINSIZE
, 0)
222 rightsizer
.Add(sizer_6
, 1, wx
.EXPAND
, 0)
224 label_7
= wx
.StaticText(self
.panel
, -1, "Selection Brush Colour:")
225 sizer_7
.Add(label_7
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
226 sizer_7
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
227 sizer_7
.Add(self
.selectionbrush
, 0, wx
.ADJUST_MINSIZE
, 0)
229 rightsizer
.Add(sizer_7
, 1, wx
.EXPAND
, 0)
231 label_8
= wx
.StaticText(self
.panel
, -1, "Selection Pen Colour:")
232 sizer_8
.Add(label_8
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
233 sizer_8
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
234 sizer_8
.Add(self
.selectionpen
, 0, wx
.ADJUST_MINSIZE
, 0)
236 rightsizer
.Add(sizer_8
, 1, wx
.EXPAND
, 0)
238 label_9
= wx
.StaticText(self
.panel
, -1, "Separator Colour:")
239 sizer_9
.Add(label_9
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
240 sizer_9
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
241 sizer_9
.Add(self
.separatorcolour
, 0, wx
.ADJUST_MINSIZE
, 0)
243 rightsizer
.Add(sizer_9
, 1, wx
.EXPAND
, 0)
245 coloursizer
.Add(rightsizer
, 0, wx
.ALL|wx
.ALIGN_CENTER_VERTICAL
, 5)
247 mainsizer
.Add(coloursizer
, 0, wx
.ALL|wx
.EXPAND
, 5)
249 label_10
= wx
.StaticText(self
.panel
, -1, "Separator Size:")
250 sizer_10
.Add(label_10
, 0, wx
.ALL|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
251 sizer_10
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
252 sizer_10
.Add(self
.separatorspin
, 0, wx
.ALL|wx
.ADJUST_MINSIZE
, 5)
254 bottomsizer
.Add(sizer_10
, 1, wx
.EXPAND
, 0)
256 label_11
= wx
.StaticText(self
.panel
, -1, "Margins Size:")
257 sizer_11
.Add(label_11
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
258 sizer_11
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
259 sizer_11
.Add(self
.marginspin
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ADJUST_MINSIZE
, 5)
261 bottomsizer
.Add(sizer_11
, 1, wx
.EXPAND
, 0)
263 label_12
= wx
.StaticText(self
.panel
, -1, "Padding Size:")
264 sizer_12
.Add(label_12
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
265 sizer_12
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
266 sizer_12
.Add(self
.paddingspin
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ADJUST_MINSIZE
, 5)
268 bottomsizer
.Add(sizer_12
, 1, wx
.EXPAND
, 0)
270 label_13
= wx
.StaticText(self
.panel
, -1, "Border Size:")
271 sizer_13
.Add(label_13
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5)
272 sizer_13
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0)
273 sizer_13
.Add(self
.borderspin
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ADJUST_MINSIZE
, 5)
275 bottomsizer
.Add(sizer_13
, 1, wx
.EXPAND
, 0)
277 mainsizer
.Add(bottomsizer
, 0, wx
.ALL|wx
.EXPAND
, 5)
279 self
.panel
.SetSizer(mainsizer
)
280 sizer
= wx
.BoxSizer()
281 sizer
.Add(self
.panel
, 1, wx
.EXPAND
)
286 def CreateColorBitmap(self
, c
):
288 image
= wx
.EmptyImage(25, 14)
293 if x
== 0 or x
== 24 or y
== 0 or y
== 13:
296 image
.SetRGB(x
, y
, pixcol
.Red(), pixcol
.Green(), pixcol
.Blue())
298 return image
.ConvertToBitmap()
301 def UpdateColors(self
):
303 bk
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_BACKGROUND_COLOR
)
304 self
.bakbrush
.SetBitmapLabel(self
.CreateColorBitmap(bk
))
306 capfrom
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_GRADIENT_COLOR_FROM
)
307 self
.gradientfrom
.SetBitmapLabel(self
.CreateColorBitmap(capfrom
))
309 capto
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_GRADIENT_COLOR_TO
)
310 self
.gradientto
.SetBitmapLabel(self
.CreateColorBitmap(capto
))
312 captxt
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_TEXT_COLOR
)
313 self
.captioncolour
.SetBitmapLabel(self
.CreateColorBitmap(captxt
))
315 bor
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_BORDER_COLOR
)
316 self
.bordercolour
.SetBitmapLabel(self
.CreateColorBitmap(bor
))
318 btntext
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_BUTTONTEXT_COLOR
)
319 self
.textbuttoncolour
.SetBitmapLabel(self
.CreateColorBitmap(btntext
))
321 selb
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_SELECTION_BRUSH_COLOR
)
322 self
.selectionbrush
.SetBitmapLabel(self
.CreateColorBitmap(selb
))
324 selp
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_SELECTION_PEN_COLOR
)
325 self
.selectionpen
.SetBitmapLabel(self
.CreateColorBitmap(selp
))
327 sepc
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_SEPARATOR_COLOR
)
328 self
.separatorcolour
.SetBitmapLabel(self
.CreateColorBitmap(sepc
))
331 def OnDefaultStyle(self
, event
):
333 self
.verticalgradient
.Enable(False)
334 self
.horizontalgradient
.Enable(False)
335 self
.targetTitleBar
.SetStyle(bp
.BP_DEFAULT_STYLE
)
337 self
.targetTitleBar
.Refresh()
342 def OnGradientStyle(self
, event
):
344 self
.verticalgradient
.Enable(True)
345 self
.horizontalgradient
.Enable(True)
346 self
.targetTitleBar
.SetStyle(bp
.BP_USE_GRADIENT
)
347 self
.targetTitleBar
.Refresh()
352 def OnVerticalGradient(self
, event
):
354 self
.targetTitleBar
.GetBPArt().SetGradientType(bp
.BP_GRADIENT_VERTICAL
)
355 self
.targetTitleBar
.SetStyle(bp
.BP_USE_GRADIENT
)
356 self
.targetTitleBar
.Refresh()
361 def OnHorizontalGradient(self
, event
):
363 self
.targetTitleBar
.GetBPArt().SetGradientType(bp
.BP_GRADIENT_HORIZONTAL
)
364 self
.targetTitleBar
.SetStyle(bp
.BP_USE_GRADIENT
)
365 self
.targetTitleBar
.Refresh()
370 def OnSetColour(self
, event
):
372 dlg
= wx
.ColourDialog(self
.parent
)
374 dlg
.SetTitle("Color Picker")
376 if dlg
.ShowModal() != wx
.ID_OK
:
380 if event
.GetId() == ID_BackgroundColour
:
381 var
= bp
.BP_BACKGROUND_COLOR
382 elif event
.GetId() == ID_GradientFrom
:
383 var
= bp
.BP_GRADIENT_COLOR_FROM
384 elif event
.GetId() == ID_GradientTo
:
385 var
= bp
.BP_GRADIENT_COLOR_TO
386 elif event
.GetId() == ID_BorderColour
:
387 var
= bp
.BP_BORDER_COLOR
388 elif event
.GetId() == ID_CaptionColour
:
389 var
= bp
.BP_TEXT_COLOR
390 elif event
.GetId() == ID_ButtonTextColour
:
391 var
= bp
.BP_BUTTONTEXT_COLOR
392 elif event
.GetId() == ID_SelectionBrush
:
393 var
= bp
.BP_SELECTION_BRUSH_COLOR
394 elif event
.GetId() == ID_SelectionPen
:
395 var
= bp
.BP_SELECTION_PEN_COLOR
396 elif event
.GetId() == ID_SeparatorColour
:
397 var
= bp
.BP_SEPARATOR_COLOR
401 self
.targetTitleBar
.GetBPArt().SetColor(var
, dlg
.GetColourData().GetColour())
402 self
.targetTitleBar
.Refresh()
405 self
.parent
.useredited
= True
408 def OnSeparator(self
, event
):
410 self
.targetTitleBar
.GetBPArt().SetMetric(bp
.BP_SEPARATOR_SIZE
,
413 self
.targetTitleBar
.DoLayout()
414 self
.parent
.mainPanel
.Layout()
415 self
.parent
.useredited
= True
420 def OnMargins(self
, event
):
422 self
.targetTitleBar
.GetBPArt().SetMetric(bp
.BP_MARGINS_SIZE
,
423 wx
.Size(event
.GetInt(), event
.GetInt()))
425 self
.targetTitleBar
.DoLayout()
426 self
.parent
.mainPanel
.Layout()
428 self
.parent
.useredited
= True
433 def OnPadding(self
, event
):
435 self
.targetTitleBar
.GetBPArt().SetMetric(bp
.BP_PADDING_SIZE
,
436 wx
.Size(event
.GetInt(), event
.GetInt()))
438 self
.targetTitleBar
.DoLayout()
439 self
.parent
.mainPanel
.Layout()
440 self
.parent
.useredited
= True
445 def OnBorder(self
, event
):
447 self
.targetTitleBar
.GetBPArt().SetMetric(bp
.BP_BORDER_SIZE
,
450 self
.targetTitleBar
.DoLayout()
451 self
.parent
.mainPanel
.Layout()
453 self
.parent
.useredited
= True
458 def OnClose(self
, event
):
460 self
.parent
.hassettingpanel
= False
465 #----------------------------------------------------------------------
467 class ButtonPanelDemo(wx
.Frame
):
469 def __init__(self
, parent
, id=wx
.ID_ANY
, title
="ButtonPanel wxPython Demo ;-)",
470 pos
=wx
.DefaultPosition
, size
=(640, 400), style
=wx
.DEFAULT_FRAME_STYLE
):
472 wx
.Frame
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
474 self
.useredited
= False
475 self
.hassettingpanel
= False
477 self
.SetIcon(GetMondrianIcon())
480 self
.statusbar
= self
.CreateStatusBar(2, wx
.ST_SIZEGRIP
)
481 self
.statusbar
.SetStatusWidths([-2, -1])
483 statusbar_fields
= [("ButtonPanel wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
484 ("Welcome To wxPython!")]
486 for i
in range(len(statusbar_fields
)):
487 self
.statusbar
.SetStatusText(statusbar_fields
[i
], i
)
489 self
.mainPanel
= wx
.Panel(self
, -1)
490 self
.logtext
= wx
.TextCtrl(self
.mainPanel
, -1, "", style
=wx
.TE_MULTILINE|wx
.TE_READONLY
)
492 vSizer
= wx
.BoxSizer(wx
.VERTICAL
)
493 self
.mainPanel
.SetSizer(vSizer
)
495 self
.alignments
= [bp
.BP_ALIGN_LEFT
, bp
.BP_ALIGN_RIGHT
, bp
.BP_ALIGN_TOP
, bp
.BP_ALIGN_BOTTOM
]
497 self
.alignment
= bp
.BP_ALIGN_LEFT
498 self
.style
= bp
.BP_USE_GRADIENT
500 self
.titleBar
= bp
.ButtonPanel(self
.mainPanel
, -1, "A Simple Test & Demo",
501 style
=self
.style
, alignment
=self
.alignment
)
504 self
.pngs
= [ (images
.get_bp_btn1Bitmap(), 'label1'),
505 (images
.get_bp_btn2Bitmap(), 'label2'),
506 (images
.get_bp_btn3Bitmap(), 'label3'),
507 (images
.get_bp_btn4Bitmap(), 'label4'),
513 def CreateMenuBar(self
):
517 file_menu
= wx
.Menu()
519 item
= wx
.MenuItem(file_menu
, wx
.ID_ANY
, "&Quit")
520 file_menu
.AppendItem(item
)
521 self
.Bind(wx
.EVT_MENU
, self
.OnClose
, item
)
523 edit_menu
= wx
.Menu()
525 item
= wx
.MenuItem(edit_menu
, wx
.ID_ANY
, "Set Bar Text")
526 edit_menu
.AppendItem(item
)
527 self
.Bind(wx
.EVT_MENU
, self
.OnSetBarText
, item
)
529 edit_menu
.AppendSeparator()
533 item
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "BP_ALIGN_LEFT", kind
=wx
.ITEM_RADIO
)
534 submenu
.AppendItem(item
)
536 self
.Bind(wx
.EVT_MENU
, self
.OnAlignment
, item
)
538 item
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "BP_ALIGN_RIGHT", kind
=wx
.ITEM_RADIO
)
539 submenu
.AppendItem(item
)
540 self
.Bind(wx
.EVT_MENU
, self
.OnAlignment
, item
)
542 item
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "BP_ALIGN_TOP", kind
=wx
.ITEM_RADIO
)
543 submenu
.AppendItem(item
)
544 self
.Bind(wx
.EVT_MENU
, self
.OnAlignment
, item
)
546 item
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "BP_ALIGN_BOTTOM", kind
=wx
.ITEM_RADIO
)
547 submenu
.AppendItem(item
)
548 self
.Bind(wx
.EVT_MENU
, self
.OnAlignment
, item
)
550 edit_menu
.AppendMenu(wx
.ID_ANY
, "&Alignment", submenu
)
554 item
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "Default Style", kind
=wx
.ITEM_RADIO
)
555 submenu
.AppendItem(item
)
556 self
.Bind(wx
.EVT_MENU
, self
.OnDefaultStyle
, item
)
558 item
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "Gradient Style", kind
=wx
.ITEM_RADIO
)
559 submenu
.AppendItem(item
)
561 self
.Bind(wx
.EVT_MENU
, self
.OnGradientStyle
, item
)
563 edit_menu
.AppendMenu(wx
.ID_ANY
, "&Styles", submenu
)
565 edit_menu
.AppendSeparator()
567 item
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "Settings Panel")
568 edit_menu
.AppendItem(item
)
569 self
.Bind(wx
.EVT_MENU
, self
.OnSettingsPanel
, item
)
571 demo_menu
= wx
.Menu()
573 item
= wx
.MenuItem(demo_menu
, wx
.ID_ANY
, "Default Demo", kind
=wx
.ITEM_RADIO
)
574 demo_menu
.AppendItem(item
)
575 self
.Bind(wx
.EVT_MENU
, self
.OnDefaultDemo
, item
)
577 item
= wx
.MenuItem(demo_menu
, wx
.ID_ANY
, "Button Only Demo", kind
=wx
.ITEM_RADIO
)
578 demo_menu
.AppendItem(item
)
579 self
.Bind(wx
.EVT_MENU
, self
.OnButtonOnly
, item
)
581 help_menu
= wx
.Menu()
583 item
= wx
.MenuItem(help_menu
, wx
.ID_ANY
, "&About...")
584 help_menu
.AppendItem(item
)
585 self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, item
)
587 mb
.Append(file_menu
, "&File")
588 mb
.Append(edit_menu
, "&Edit")
589 mb
.Append(demo_menu
, "&Demo")
590 mb
.Append(help_menu
, "&Help")
595 def CreateButtons(self
):
597 # Here we (re)create the buttons for the default startup demo
601 sizer
= self
.mainPanel
.GetSizer()
604 wx
.CallAfter(self
.titleBar
.Destroy
)
605 self
.titleBar
= bp
.ButtonPanel(self
.mainPanel
, -1, "A Simple Test & Demo",
606 style
=self
.style
, alignment
=self
.alignment
)
610 for count
, png
in enumerate(self
.pngs
):
613 # First 2 buttons are togglebuttons
616 kind
= wx
.ITEM_NORMAL
618 btn
= bp
.ButtonInfo(self
.titleBar
, wx
.NewId(),
622 self
.titleBar
.AddButton(btn
)
623 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, id=btn
.GetId())
625 self
.indices
.append(btn
.GetId())
628 # First 2 buttons have also a text
632 # Append a separator after the second button
633 self
.titleBar
.AddSeparator()
636 # Add a wx.TextCtrl to ButtonPanel
637 self
.titleBar
.AddControl(wx
.TextCtrl(self
.titleBar
, -1, "Hello wxPython!"))
638 btn
.SetTextAlignment(bp
.BP_BUTTONTEXT_ALIGN_RIGHT
)
640 # Add a wx.Choice to ButtonPanel
641 self
.titleBar
.AddControl(wx
.Choice(self
.titleBar
, -1,
642 choices
=["Hello", "From", "wxPython!"]))
644 self
.strings
= ["First", "Second", "Third", "Fourth"]
648 self
.titleBar
.DoLayout()
653 def ButtonOnly(self
):
655 # Here we (re)create the buttons for the button-only demo
659 sizer
= self
.mainPanel
.GetSizer()
661 self
.titleBar
.Destroy()
662 self
.titleBar
= bp
.ButtonPanel(self
.mainPanel
, -1, "A Simple Test & Demo",
663 style
=self
.style
, alignment
=self
.alignment
)
666 # Buttons are created completely random, with random images, toggle behavior
670 for count
in xrange(8):
672 itemImage
= random
.randint(0, 3)
673 hasText
= random
.randint(0, 1)
674 itemKind
= random
.randint(0, 1)
676 btn
= bp
.ButtonInfo(self
.titleBar
, wx
.NewId(), self
.pngs
[itemImage
][0],
680 btn
.SetText(self
.pngs
[itemImage
][1])
681 rightText
= random
.randint(0, 1)
683 btn
.SetTextAlignment(bp
.BP_BUTTONTEXT_ALIGN_RIGHT
)
685 self
.titleBar
.AddButton(btn
)
686 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, id=btn
.GetId())
688 self
.indices
.append(btn
.GetId())
690 if count
in [0, 3, 5]:
691 self
.titleBar
.AddSeparator()
693 self
.strings
= ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth"]
697 self
.titleBar
.DoLayout()
700 def ChangeLayout(self
):
702 # Change the layout after a switch in ButtonPanel alignment
705 if self
.alignment
in [bp
.BP_ALIGN_LEFT
, bp
.BP_ALIGN_RIGHT
]:
706 vSizer
= wx
.BoxSizer(wx
.VERTICAL
)
708 vSizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
710 self
.mainPanel
.SetSizer(vSizer
)
712 vSizer
.Add(self
.titleBar
, 0, wx
.EXPAND
)
714 vSizer
.Add(self
.logtext
, 1, wx
.EXPAND|wx
.ALL
, 5)
717 self
.mainPanel
.Layout()
721 def SetProperties(self
):
723 # No resetting if the user is using the Settings Panel
727 # Sets the colours for the two demos: called only if the user didn't
728 # modify the colours and sizes using the Settings Panel
729 bpArt
= self
.titleBar
.GetBPArt()
731 if self
.style
& bp
.BP_USE_GRADIENT
:
732 # set the color the text is drawn with
733 bpArt
.SetColor(bp
.BP_TEXT_COLOR
, wx
.WHITE
)
735 # These default to white and whatever is set in the system
736 # settings for the wx.SYS_COLOUR_ACTIVECAPTION. We'll use
737 # some specific settings to ensure a consistent look for the
739 bpArt
.SetColor(bp
.BP_BORDER_COLOR
, wx
.Colour(120,23,224))
740 bpArt
.SetColor(bp
.BP_GRADIENT_COLOR_FROM
, wx
.Colour(60,11,112))
741 bpArt
.SetColor(bp
.BP_GRADIENT_COLOR_TO
, wx
.Colour(120,23,224))
742 bpArt
.SetColor(bp
.BP_BUTTONTEXT_COLOR
, wx
.Colour(70,143,255))
743 bpArt
.SetColor(bp
.BP_SEPARATOR_COLOR
,
744 bp
.BrightenColour(wx
.Colour(60, 11, 112), 0.85))
745 bpArt
.SetColor(bp
.BP_SELECTION_BRUSH_COLOR
, wx
.Color(225, 225, 255))
746 bpArt
.SetColor(bp
.BP_SELECTION_PEN_COLOR
, wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_ACTIVECAPTION
))
750 background
= self
.titleBar
.GetBackgroundColour()
751 bpArt
.SetColor(bp
.BP_TEXT_COLOR
, wx
.BLUE
)
752 bpArt
.SetColor(bp
.BP_BORDER_COLOR
,
753 bp
.BrightenColour(background
, 0.85))
754 bpArt
.SetColor(bp
.BP_SEPARATOR_COLOR
,
755 bp
.BrightenColour(background
, 0.85))
756 bpArt
.SetColor(bp
.BP_BUTTONTEXT_COLOR
, wx
.BLACK
)
757 bpArt
.SetColor(bp
.BP_SELECTION_BRUSH_COLOR
, wx
.Colour(242, 242, 235))
758 bpArt
.SetColor(bp
.BP_SELECTION_PEN_COLOR
, wx
.Colour(206, 206, 195))
760 self
.titleBar
.SetStyle(self
.style
)
763 def OnAlignment(self
, event
):
765 # Here we change the alignment property of ButtonPanel
766 current
= event
.GetId()
767 edit_menu
= self
.GetMenuBar().FindMenu("Edit")
768 edit_menu
= self
.GetMenuBar().GetMenu(edit_menu
)
769 menu
= edit_menu
.FindItem("BP_ALIGN_LEFT")
771 alignment
= self
.alignments
[current
- menu
]
772 self
.alignment
= alignment
775 self
.titleBar
.SetAlignment(alignment
)
776 self
.mainPanel
.Layout()
781 def OnDefaultStyle(self
, event
):
783 # Restore the ButtonPanel default style (no gradient)
784 self
.style
= bp
.BP_DEFAULT_STYLE
790 def OnGradientStyle(self
, event
):
792 # Use gradients to paint ButtonPanel background
793 self
.style
= bp
.BP_USE_GRADIENT
799 def OnDefaultDemo(self
, event
):
801 # Reload the default startup demo
806 def OnButtonOnly(self
, event
):
808 # Reload the button-only demo
813 def OnButton(self
, event
):
816 indx
= self
.indices
.index(btn
)
818 self
.logtext
.AppendText("Event Fired From " + self
.strings
[indx
] + " Button\n")
822 def OnSetBarText(self
, event
):
824 dlg
= wx
.TextEntryDialog(self
, "Enter The Text You Wish To Display On The Bar (Clear If No Text):",
825 "Set Text", self
.titleBar
.GetBarText())
827 if dlg
.ShowModal() == wx
.ID_OK
:
830 self
.titleBar
.SetBarText(val
)
831 self
.titleBar
.DoLayout()
832 self
.mainPanel
.Layout()
835 def OnSettingsPanel(self
, event
):
837 if self
.hassettingpanel
:
838 self
.settingspanel
.Raise()
841 self
.settingspanel
= SettingsPanel(self
, -1)
842 self
.settingspanel
.Show()
843 self
.hassettingpanel
= True
846 def OnClose(self
, event
):
852 def OnAbout(self
, event
):
854 msg
= "This Is The About Dialog Of The ButtonPanel Demo.\n\n" + \
855 "Author: Andrea Gavana @ 02 Oct 2006\n\n" + \
856 "Please Report Any Bug/Requests Of Improvements\n" + \
857 "To Me At The Following Adresses:\n\n" + \
858 "andrea.gavana@gmail.com\n" + "gavana@kpo.kz\n\n" + \
859 "Based On Eran C++ Implementation (wxWidgets Forum).\n\n" + \
860 "Welcome To wxPython " + wx
.VERSION_STRING
+ "!!"
862 dlg
= wx
.MessageDialog(self
, msg
, "ButtonPanel wxPython Demo",
863 wx
.OK | wx
.ICON_INFORMATION
)
869 #----------------------------------------------------------------------
871 class TestPanel(wx
.Panel
):
872 def __init__(self
, parent
, log
):
874 wx
.Panel
.__init
__(self
, parent
, -1)
876 b
= wx
.Button(self
, -1, " Test ButtonPanel ", (50,50))
877 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
)
880 def OnButton(self
, evt
):
881 self
.win
= ButtonPanelDemo(self
)
885 #----------------------------------------------------------------------
887 def runTest(frame
, nb
, log
):
888 win
= TestPanel(nb
, log
)
891 #----------------------------------------------------------------------
895 overview
= bp
.__doc
__
899 if __name__
== '__main__':
902 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])