]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ButtonPanel.py
Tinderbox build fix.
[wxWidgets.git] / wxPython / demo / ButtonPanel.py
CommitLineData
66dae888
RD
1import wx
2import wx.lib.buttonpanel as bp
3import images
4
37840b8b
RD
5import random
6
7#----------------------------------------------------------------------
8
9ID_BackgroundColour = wx.NewId()
10ID_GradientFrom = wx.NewId()
11ID_GradientTo = wx.NewId()
12ID_BorderColour = wx.NewId()
13ID_CaptionColour = wx.NewId()
14ID_ButtonTextColour = wx.NewId()
15ID_SelectionBrush = wx.NewId()
16ID_SelectionPen = wx.NewId()
17ID_SeparatorColour = wx.NewId()
18
19
20#----------------------------------------------------------------------
21# Some icons for the demo
22#----------------------------------------------------------------------
23def GetMondrianData():
24 return \
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\
27ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\
28o\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'
32
33
34def GetMondrianBitmap():
35 return wx.BitmapFromImage(GetMondrianImage())
36
37
38def GetMondrianImage():
39 import cStringIO
40 stream = cStringIO.StringIO(GetMondrianData())
41 return wx.ImageFromStream(stream)
42
43
44def GetMondrianIcon():
45 icon = wx.EmptyIcon()
46 icon.CopyFromBitmap(GetMondrianBitmap())
47 return icon
48
61b35490 49
37840b8b
RD
50#----------------------------------------------------------------------
51
52class SettingsPanel(wx.MiniFrame):
53
54 def __init__(self, parent, id=wx.ID_ANY, title="Settings Panel", pos=wx.DefaultPosition,
55 size=wx.DefaultSize,
56 style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.FRAME_NO_TASKBAR
57 | wx.FRAME_FLOAT_ON_PARENT | wx.CLIP_CHILDREN):
58
59 wx.MiniFrame.__init__(self, parent, id, title, pos, size, style)
60
61 self.targetTitleBar = parent.titleBar
62 self.parent = parent
63 self.panel = wx.Panel(self, -1)
64
65 self.coloursizer_staticbox = wx.StaticBox(self.panel, -1, "Colour Options")
66 self.bottomsizer_staticbox = wx.StaticBox(self.panel, -1, "Size Options")
67 self.stylesizer_staticbox = wx.StaticBox(self.panel, -1, "ButtonPanel Styles")
68 self.defaultstyle = wx.RadioButton(self.panel, -1, "Default Style", style=wx.RB_GROUP)
69 self.gradientstyle = wx.RadioButton(self.panel, -1, "Gradient Style")
70 self.verticalgradient = wx.RadioButton(self.panel, -1, "Vertical Gradient", style=wx.RB_GROUP)
71 self.horizontalgradient = wx.RadioButton(self.panel, -1, "Horizontal Gradient")
72
73 b = self.CreateColorBitmap(wx.BLACK)
74
75 self.bakbrush = wx.BitmapButton(self.panel, ID_BackgroundColour, b, size=wx.Size(50,25))
76 self.gradientfrom = wx.BitmapButton(self.panel, ID_GradientFrom, b, size=wx.Size(50,25))
77 self.gradientto = wx.BitmapButton(self.panel, ID_GradientTo, b, size=wx.Size(50,25))
78 self.bordercolour = wx.BitmapButton(self.panel, ID_BorderColour, b, size=wx.Size(50,25))
79 self.captioncolour = wx.BitmapButton(self.panel, ID_CaptionColour, b, size=wx.Size(50,25))
80 self.textbuttoncolour = wx.BitmapButton(self.panel, ID_ButtonTextColour, b, size=wx.Size(50,25))
81 self.selectionbrush = wx.BitmapButton(self.panel, ID_SelectionBrush, b, size=wx.Size(50,25))
82 self.selectionpen = wx.BitmapButton(self.panel, ID_SelectionPen, b, size=wx.Size(50,25))
83 self.separatorcolour = wx.BitmapButton(self.panel, ID_SeparatorColour, b, size=wx.Size(50,25))
84
85 self.separatorspin = wx.SpinCtrl(self.panel, -1, "7", min=3, max=20,
86 style=wx.SP_ARROW_KEYS)
87 self.marginspin = wx.SpinCtrl(self.panel, -1, "6", min=3, max=20,
88 style=wx.SP_ARROW_KEYS)
89 self.paddingspin = wx.SpinCtrl(self.panel, -1, "6", min=3, max=20,
90 style=wx.SP_ARROW_KEYS)
91 self.borderspin = wx.SpinCtrl(self.panel, -1, "3", min=3, max=7,
92 style=wx.SP_ARROW_KEYS)
93
94 self.__set_properties()
95 self.__do_layout()
96
97 self.Bind(wx.EVT_RADIOBUTTON, self.OnDefaultStyle, self.defaultstyle)
98 self.Bind(wx.EVT_RADIOBUTTON, self.OnGradientStyle, self.gradientstyle)
99 self.Bind(wx.EVT_RADIOBUTTON, self.OnVerticalGradient, self.verticalgradient)
100 self.Bind(wx.EVT_RADIOBUTTON, self.OnHorizontalGradient, self.horizontalgradient)
101 self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_BackgroundColour)
102 self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_GradientFrom)
103 self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_GradientTo)
104 self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_BorderColour)
105 self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_CaptionColour)
106 self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_ButtonTextColour)
107 self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_SelectionBrush)
108 self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_SelectionPen)
109 self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_SeparatorColour)
110
111 self.Bind(wx.EVT_SPINCTRL, self.OnSeparator, self.separatorspin)
112 self.Bind(wx.EVT_SPINCTRL, self.OnMargins, self.marginspin)
113 self.Bind(wx.EVT_SPINCTRL, self.OnPadding, self.paddingspin)
114 self.Bind(wx.EVT_SPINCTRL, self.OnBorder, self.borderspin)
115
116 self.Bind(wx.EVT_CLOSE, self.OnClose)
117
118
119 def __set_properties(self):
120
121 self.defaultstyle.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
122 self.defaultstyle.SetValue(1)
123 self.gradientstyle.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
124 self.verticalgradient.SetValue(1)
125
126 if self.targetTitleBar.GetStyle() & bp.BP_DEFAULT_STYLE:
127 self.verticalgradient.Enable(False)
128 self.horizontalgradient.Enable(False)
129 self.defaultstyle.SetValue(1)
130 else:
131 self.gradientstyle.SetValue(1)
132
133 self.borderspin.SetValue(self.targetTitleBar.GetBPArt().GetMetric(bp.BP_BORDER_SIZE))
134 self.separatorspin.SetValue(self.targetTitleBar.GetBPArt().GetMetric(bp.BP_SEPARATOR_SIZE))
135 self.marginspin.SetValue(self.targetTitleBar.GetBPArt().GetMetric(bp.BP_MARGINS_SIZE).x)
136 self.paddingspin.SetValue(self.targetTitleBar.GetBPArt().GetMetric(bp.BP_PADDING_SIZE).x)
137
138 self.UpdateColors()
139
140
141 def __do_layout(self):
142
143 mainsizer = wx.BoxSizer(wx.VERTICAL)
144 buttonsizer = wx.BoxSizer(wx.HORIZONTAL)
145 bottomsizer = wx.StaticBoxSizer(self.bottomsizer_staticbox, wx.VERTICAL)
146 sizer_13 = wx.BoxSizer(wx.HORIZONTAL)
147 sizer_12 = wx.BoxSizer(wx.HORIZONTAL)
148 sizer_11 = wx.BoxSizer(wx.HORIZONTAL)
149 sizer_10 = wx.BoxSizer(wx.HORIZONTAL)
150 coloursizer = wx.StaticBoxSizer(self.coloursizer_staticbox, wx.HORIZONTAL)
151 rightsizer = wx.BoxSizer(wx.VERTICAL)
152 sizer_9 = wx.BoxSizer(wx.HORIZONTAL)
153 sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
154 sizer_7 = wx.BoxSizer(wx.HORIZONTAL)
155 sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
156 leftsizer = wx.BoxSizer(wx.VERTICAL)
157 sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
158 sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
159 sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
160 sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
161 sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
162 stylesizer = wx.StaticBoxSizer(self.stylesizer_staticbox, wx.VERTICAL)
163 tophsizer = wx.BoxSizer(wx.HORIZONTAL)
164 tophsizer2 = wx.BoxSizer(wx.VERTICAL)
165
166 stylesizer.Add(self.defaultstyle, 0, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 5)
167
168 tophsizer.Add(self.gradientstyle, 0, wx.LEFT|wx.RIGHT|wx.EXPAND|
169 wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
170
171 tophsizer2.Add(self.verticalgradient, 0, wx.BOTTOM|wx.ADJUST_MINSIZE, 3)
172 tophsizer2.Add(self.horizontalgradient, 0, wx.ADJUST_MINSIZE, 0)
173
174 tophsizer.Add(tophsizer2, 1, wx.LEFT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, 10)
175
176 stylesizer.Add(tophsizer, 1, wx.EXPAND, 0)
177
178 mainsizer.Add(stylesizer, 0, wx.ALL|wx.EXPAND, 5)
179
180 label_1 = wx.StaticText(self.panel, -1, "Background Brush Colour:")
181 sizer_1.Add(label_1, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
182 sizer_1.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
183 sizer_1.Add(self.bakbrush, 0, wx.ADJUST_MINSIZE, 0)
184
185 leftsizer.Add(sizer_1, 1, wx.EXPAND, 0)
186
187 label_2 = wx.StaticText(self.panel, -1, "Gradient Colour From:")
188 sizer_2.Add(label_2, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
189 sizer_2.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
190 sizer_2.Add(self.gradientfrom, 0, wx.ADJUST_MINSIZE, 0)
191
192 leftsizer.Add(sizer_2, 1, wx.EXPAND, 0)
193
194 label_3 = wx.StaticText(self.panel, -1, "Gradient Colour To:")
195 sizer_3.Add(label_3, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
196 sizer_3.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
197 sizer_3.Add(self.gradientto, 0, wx.ADJUST_MINSIZE, 0)
198
199 leftsizer.Add(sizer_3, 1, wx.EXPAND, 0)
200
201 label_4 = wx.StaticText(self.panel, -1, "Border Colour:")
202 sizer_4.Add(label_4, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
203 sizer_4.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
204 sizer_4.Add(self.bordercolour, 0, wx.ADJUST_MINSIZE, 0)
205
206 leftsizer.Add(sizer_4, 1, wx.EXPAND, 0)
207
208 label_5 = wx.StaticText(self.panel, -1, "Main Caption Colour:")
209 sizer_5.Add(label_5, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
210 sizer_5.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
211 sizer_5.Add(self.captioncolour, 0, wx.ADJUST_MINSIZE, 0)
212
213 leftsizer.Add(sizer_5, 1, wx.EXPAND, 0)
214
215 coloursizer.Add(leftsizer, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
216 coloursizer.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
217
218 label_6 = wx.StaticText(self.panel, -1, "Text Button Colour:")
219 sizer_6.Add(label_6, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
220 sizer_6.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
221 sizer_6.Add(self.textbuttoncolour, 0, wx.ADJUST_MINSIZE, 0)
222
223 rightsizer.Add(sizer_6, 1, wx.EXPAND, 0)
224
225 label_7 = wx.StaticText(self.panel, -1, "Selection Brush Colour:")
226 sizer_7.Add(label_7, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
227 sizer_7.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
228 sizer_7.Add(self.selectionbrush, 0, wx.ADJUST_MINSIZE, 0)
229
230 rightsizer.Add(sizer_7, 1, wx.EXPAND, 0)
231
232 label_8 = wx.StaticText(self.panel, -1, "Selection Pen Colour:")
233 sizer_8.Add(label_8, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
234 sizer_8.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
235 sizer_8.Add(self.selectionpen, 0, wx.ADJUST_MINSIZE, 0)
236
237 rightsizer.Add(sizer_8, 1, wx.EXPAND, 0)
238
239 label_9 = wx.StaticText(self.panel, -1, "Separator Colour:")
240 sizer_9.Add(label_9, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
241 sizer_9.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
242 sizer_9.Add(self.separatorcolour, 0, wx.ADJUST_MINSIZE, 0)
243
244 rightsizer.Add(sizer_9, 1, wx.EXPAND, 0)
245
246 coloursizer.Add(rightsizer, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
247
248 mainsizer.Add(coloursizer, 0, wx.ALL|wx.EXPAND, 5)
249
250 label_10 = wx.StaticText(self.panel, -1, "Separator Size:")
251 sizer_10.Add(label_10, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
252 sizer_10.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
253 sizer_10.Add(self.separatorspin, 0, wx.ALL|wx.ADJUST_MINSIZE, 5)
254
255 bottomsizer.Add(sizer_10, 1, wx.EXPAND, 0)
256
257 label_11 = wx.StaticText(self.panel, -1, "Margins Size:")
258 sizer_11.Add(label_11, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
259 sizer_11.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
260 sizer_11.Add(self.marginspin, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ADJUST_MINSIZE, 5)
261
262 bottomsizer.Add(sizer_11, 1, wx.EXPAND, 0)
263
264 label_12 = wx.StaticText(self.panel, -1, "Padding Size:")
265 sizer_12.Add(label_12, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
266 sizer_12.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
267 sizer_12.Add(self.paddingspin, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ADJUST_MINSIZE, 5)
268
269 bottomsizer.Add(sizer_12, 1, wx.EXPAND, 0)
270
271 label_13 = wx.StaticText(self.panel, -1, "Border Size:")
272 sizer_13.Add(label_13, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
273 sizer_13.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
274 sizer_13.Add(self.borderspin, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ADJUST_MINSIZE, 5)
275
276 bottomsizer.Add(sizer_13, 1, wx.EXPAND, 0)
277
278 mainsizer.Add(bottomsizer, 0, wx.ALL|wx.EXPAND, 5)
279
280 self.panel.SetSizer(mainsizer)
281 sizer = wx.BoxSizer()
282 sizer.Add(self.panel, 1, wx.EXPAND)
283 self.SetSizer(sizer)
284 self.Fit()
285
286
287 def CreateColorBitmap(self, c):
288
289 image = wx.EmptyImage(25, 14)
290
291 for x in xrange(25):
292 for y in xrange(14):
293 pixcol = c
294 if x == 0 or x == 24 or y == 0 or y == 13:
295 pixcol = wx.BLACK
296
297 image.SetRGB(x, y, pixcol.Red(), pixcol.Green(), pixcol.Blue())
298
299 return image.ConvertToBitmap()
300
301
302 def UpdateColors(self):
303
304 bk = self.targetTitleBar.GetBPArt().GetColor(bp.BP_BACKGROUND_COLOR)
305 self.bakbrush.SetBitmapLabel(self.CreateColorBitmap(bk))
306
307 capfrom = self.targetTitleBar.GetBPArt().GetColor(bp.BP_GRADIENT_COLOR_FROM)
308 self.gradientfrom.SetBitmapLabel(self.CreateColorBitmap(capfrom))
309
310 capto = self.targetTitleBar.GetBPArt().GetColor(bp.BP_GRADIENT_COLOR_TO)
311 self.gradientto.SetBitmapLabel(self.CreateColorBitmap(capto))
312
313 captxt = self.targetTitleBar.GetBPArt().GetColor(bp.BP_TEXT_COLOR)
314 self.captioncolour.SetBitmapLabel(self.CreateColorBitmap(captxt))
315
316 bor = self.targetTitleBar.GetBPArt().GetColor(bp.BP_BORDER_COLOR)
317 self.bordercolour.SetBitmapLabel(self.CreateColorBitmap(bor))
318
319 btntext = self.targetTitleBar.GetBPArt().GetColor(bp.BP_BUTTONTEXT_COLOR)
320 self.textbuttoncolour.SetBitmapLabel(self.CreateColorBitmap(btntext))
321
322 selb = self.targetTitleBar.GetBPArt().GetColor(bp.BP_SELECTION_BRUSH_COLOR)
323 self.selectionbrush.SetBitmapLabel(self.CreateColorBitmap(selb))
324
325 selp = self.targetTitleBar.GetBPArt().GetColor(bp.BP_SELECTION_PEN_COLOR)
326 self.selectionpen.SetBitmapLabel(self.CreateColorBitmap(selp))
327
328 sepc = self.targetTitleBar.GetBPArt().GetColor(bp.BP_SEPARATOR_COLOR)
329 self.separatorcolour.SetBitmapLabel(self.CreateColorBitmap(sepc))
330
331
332 def OnDefaultStyle(self, event):
333
334 self.verticalgradient.Enable(False)
335 self.horizontalgradient.Enable(False)
336 self.targetTitleBar.SetStyle(bp.BP_DEFAULT_STYLE)
337
338 self.targetTitleBar.Refresh()
339
340 event.Skip()
341
342
343 def OnGradientStyle(self, event):
344
345 self.verticalgradient.Enable(True)
346 self.horizontalgradient.Enable(True)
347 self.targetTitleBar.SetStyle(bp.BP_USE_GRADIENT)
348 self.targetTitleBar.Refresh()
349
350 event.Skip()
351
352
353 def OnVerticalGradient(self, event):
354
355 self.targetTitleBar.GetBPArt().SetGradientType(bp.BP_GRADIENT_VERTICAL)
356 self.targetTitleBar.SetStyle(bp.BP_USE_GRADIENT)
357 self.targetTitleBar.Refresh()
358
359 event.Skip()
360
361
362 def OnHorizontalGradient(self, event):
363
364 self.targetTitleBar.GetBPArt().SetGradientType(bp.BP_GRADIENT_HORIZONTAL)
365 self.targetTitleBar.SetStyle(bp.BP_USE_GRADIENT)
366 self.targetTitleBar.Refresh()
367
368 event.Skip()
369
370
371 def OnSetColour(self, event):
372
373 dlg = wx.ColourDialog(self.parent)
374
375 dlg.SetTitle("Color Picker")
376
377 if dlg.ShowModal() != wx.ID_OK:
378 return
379
380 var = 0
381 if event.GetId() == ID_BackgroundColour:
382 var = bp.BP_BACKGROUND_COLOR
383 elif event.GetId() == ID_GradientFrom:
384 var = bp.BP_GRADIENT_COLOR_FROM
385 elif event.GetId() == ID_GradientTo:
386 var = bp.BP_GRADIENT_COLOR_TO
387 elif event.GetId() == ID_BorderColour:
388 var = bp.BP_BORDER_COLOR
389 elif event.GetId() == ID_CaptionColour:
390 var = bp.BP_TEXT_COLOR
391 elif event.GetId() == ID_ButtonTextColour:
392 var = bp.BP_BUTTONTEXT_COLOR
393 elif event.GetId() == ID_SelectionBrush:
394 var = bp.BP_SELECTION_BRUSH_COLOR
395 elif event.GetId() == ID_SelectionPen:
396 var = bp.BP_SELECTION_PEN_COLOR
397 elif event.GetId() == ID_SeparatorColour:
398 var = bp.BP_SEPARATOR_COLOR
399 else:
400 return
401
402 self.targetTitleBar.GetBPArt().SetColor(var, dlg.GetColourData().GetColour())
403 self.targetTitleBar.Refresh()
404 self.UpdateColors()
405
406 self.parent.useredited = True
407
408
409 def OnSeparator(self, event):
410
411 self.targetTitleBar.GetBPArt().SetMetric(bp.BP_SEPARATOR_SIZE,
412 event.GetInt())
413
414 self.targetTitleBar.DoLayout()
415 self.parent.mainPanel.Layout()
416 self.parent.useredited = True
417
418 event.Skip()
419
420
421 def OnMargins(self, event):
422
423 self.targetTitleBar.GetBPArt().SetMetric(bp.BP_MARGINS_SIZE,
424 wx.Size(event.GetInt(), event.GetInt()))
425
426 self.targetTitleBar.DoLayout()
427 self.parent.mainPanel.Layout()
428
429 self.parent.useredited = True
430
431 event.Skip()
432
433
434 def OnPadding(self, event):
435
436 self.targetTitleBar.GetBPArt().SetMetric(bp.BP_PADDING_SIZE,
437 wx.Size(event.GetInt(), event.GetInt()))
438
439 self.targetTitleBar.DoLayout()
440 self.parent.mainPanel.Layout()
441 self.parent.useredited = True
442
443 event.Skip()
444
445
446 def OnBorder(self, event):
447
448 self.targetTitleBar.GetBPArt().SetMetric(bp.BP_BORDER_SIZE,
449 event.GetInt())
450
451 self.targetTitleBar.DoLayout()
452 self.parent.mainPanel.Layout()
453
454 self.parent.useredited = True
455
456 event.Skip()
457
458
459 def OnClose(self, event):
460
461 self.parent.hassettingpanel = False
462 self.Destroy()
463
464
66dae888 465#----------------------------------------------------------------------
37840b8b 466
66dae888
RD
467class ButtonPanelDemo(wx.Frame):
468
37840b8b
RD
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):
66dae888 471
37840b8b 472 wx.Frame.__init__(self, parent, id, title, pos, size, style)
66dae888 473
37840b8b
RD
474 self.useredited = False
475 self.hassettingpanel = False
476
477 self.SetIcon(GetMondrianIcon())
66dae888
RD
478 self.CreateMenuBar()
479
480 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
481 self.statusbar.SetStatusWidths([-2, -1])
482 # statusbar fields
483 statusbar_fields = [("ButtonPanel wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
484 ("Welcome To wxPython!")]
485
486 for i in range(len(statusbar_fields)):
487 self.statusbar.SetStatusText(statusbar_fields[i], i)
488
37840b8b
RD
489 self.mainPanel = wx.Panel(self, -1)
490 self.logtext = wx.TextCtrl(self.mainPanel, -1, "", style=wx.TE_MULTILINE|wx.TE_READONLY)
66dae888
RD
491
492 vSizer = wx.BoxSizer(wx.VERTICAL)
37840b8b 493 self.mainPanel.SetSizer(vSizer)
66dae888 494
37840b8b 495 self.alignments = [bp.BP_ALIGN_LEFT, bp.BP_ALIGN_RIGHT, bp.BP_ALIGN_TOP, bp.BP_ALIGN_BOTTOM]
66dae888 496
37840b8b
RD
497 self.alignment = bp.BP_ALIGN_LEFT
498 self.style = bp.BP_USE_GRADIENT
499
500 self.titleBar = bp.ButtonPanel(self.mainPanel, -1, "A Simple Test & Demo",
501 style=self.style, alignment=self.alignment)
502
503 self.created = False
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'),
508 ]
509 self.CreateButtons()
510 self.SetProperties()
511
66dae888
RD
512
513 def CreateMenuBar(self):
37840b8b 514
66dae888
RD
515 mb = wx.MenuBar()
516
517 file_menu = wx.Menu()
37840b8b 518
66dae888
RD
519 item = wx.MenuItem(file_menu, wx.ID_ANY, "&Quit")
520 file_menu.AppendItem(item)
521 self.Bind(wx.EVT_MENU, self.OnClose, item)
522
523 edit_menu = wx.Menu()
37840b8b
RD
524
525 item = wx.MenuItem(edit_menu, wx.ID_ANY, "Set Bar Text")
66dae888 526 edit_menu.AppendItem(item)
37840b8b
RD
527 self.Bind(wx.EVT_MENU, self.OnSetBarText, item)
528
529 edit_menu.AppendSeparator()
530
531 submenu = wx.Menu()
532
533 item = wx.MenuItem(submenu, wx.ID_ANY, "BP_ALIGN_LEFT", kind=wx.ITEM_RADIO)
534 submenu.AppendItem(item)
535 item.Check(True)
536 self.Bind(wx.EVT_MENU, self.OnAlignment, item)
537
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)
541
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)
545
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)
549
550 edit_menu.AppendMenu(wx.ID_ANY, "&Alignment", submenu)
551
552 submenu = wx.Menu()
553
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)
557
558 item = wx.MenuItem(submenu, wx.ID_ANY, "Gradient Style", kind=wx.ITEM_RADIO)
559 submenu.AppendItem(item)
560 item.Check(True)
561 self.Bind(wx.EVT_MENU, self.OnGradientStyle, item)
562
563 edit_menu.AppendMenu(wx.ID_ANY, "&Styles", submenu)
564
565 edit_menu.AppendSeparator()
566
567 item = wx.MenuItem(submenu, wx.ID_ANY, "Settings Panel")
66dae888 568 edit_menu.AppendItem(item)
37840b8b
RD
569 self.Bind(wx.EVT_MENU, self.OnSettingsPanel, item)
570
571 demo_menu = wx.Menu()
572
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)
66dae888 576
37840b8b
RD
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)
580
66dae888 581 help_menu = wx.Menu()
37840b8b 582
66dae888
RD
583 item = wx.MenuItem(help_menu, wx.ID_ANY, "&About...")
584 help_menu.AppendItem(item)
585 self.Bind(wx.EVT_MENU, self.OnAbout, item)
586
587 mb.Append(file_menu, "&File")
588 mb.Append(edit_menu, "&Edit")
37840b8b 589 mb.Append(demo_menu, "&Demo")
66dae888
RD
590 mb.Append(help_menu, "&Help")
591
592 self.SetMenuBar(mb)
593
594
37840b8b
RD
595 def CreateButtons(self):
596
597 # Here we (re)create the buttons for the default startup demo
66dae888 598 self.Freeze()
37840b8b
RD
599
600 if self.created:
601 sizer = self.mainPanel.GetSizer()
602 sizer.Detach(0)
603 self.titleBar.Hide()
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)
607 self.SetProperties()
608
609 self.indices = []
61b35490 610
37840b8b
RD
611 for count, png in enumerate(self.pngs):
612
61b35490
RD
613 shortHelp = "Button %d"%(count+1)
614
37840b8b
RD
615 if count < 2:
616 # First 2 buttons are togglebuttons
617 kind = wx.ITEM_CHECK
61b35490 618 longHelp = "ButtonPanel Toggle Button No %d"%(count+1)
37840b8b
RD
619 else:
620 kind = wx.ITEM_NORMAL
61b35490
RD
621 longHelp = "Simple Button without label No %d"%(count+1)
622
37840b8b 623 btn = bp.ButtonInfo(self.titleBar, wx.NewId(),
61b35490
RD
624 png[0], kind=kind,
625 shortHelp=shortHelp, longHelp=longHelp)
37840b8b
RD
626
627 self.titleBar.AddButton(btn)
628 self.Bind(wx.EVT_BUTTON, self.OnButton, id=btn.GetId())
629
630 self.indices.append(btn.GetId())
631
632 if count < 2:
633 # First 2 buttons have also a text
634 btn.SetText(png[1])
635
636 if count == 2:
637 # Append a separator after the second button
638 self.titleBar.AddSeparator()
639
640 if count == 1:
641 # Add a wx.TextCtrl to ButtonPanel
642 self.titleBar.AddControl(wx.TextCtrl(self.titleBar, -1, "Hello wxPython!"))
643 btn.SetTextAlignment(bp.BP_BUTTONTEXT_ALIGN_RIGHT)
644
645 # Add a wx.Choice to ButtonPanel
646 self.titleBar.AddControl(wx.Choice(self.titleBar, -1,
647 choices=["Hello", "From", "wxPython!"]))
648
649 self.strings = ["First", "Second", "Third", "Fourth"]
650
651 self.ChangeLayout()
652 self.Thaw()
653 self.titleBar.DoLayout()
654
655 self.created = True
66dae888 656
66dae888 657
37840b8b
RD
658 def ButtonOnly(self):
659
660 # Here we (re)create the buttons for the button-only demo
661 self.Freeze()
662
663 if self.created:
664 sizer = self.mainPanel.GetSizer()
665 sizer.Detach(0)
61b35490
RD
666 self.titleBar.Hide()
667 wx.CallAfter(self.titleBar.Destroy)
37840b8b
RD
668 self.titleBar = bp.ButtonPanel(self.mainPanel, -1, "A Simple Test & Demo",
669 style=self.style, alignment=self.alignment)
670 self.SetProperties()
671
672 # Buttons are created completely random, with random images, toggle behavior
673 # and text
674
675 self.indices = []
61b35490 676
37840b8b
RD
677 for count in xrange(8):
678
679 itemImage = random.randint(0, 3)
680 hasText = random.randint(0, 1)
681 itemKind = random.randint(0, 1)
682
683 btn = bp.ButtonInfo(self.titleBar, wx.NewId(), self.pngs[itemImage][0],
684 kind=itemKind)
685
686 if hasText:
687 btn.SetText(self.pngs[itemImage][1])
688 rightText = random.randint(0, 1)
689 if rightText:
690 btn.SetTextAlignment(bp.BP_BUTTONTEXT_ALIGN_RIGHT)
66dae888 691
66dae888 692 self.titleBar.AddButton(btn)
37840b8b
RD
693 self.Bind(wx.EVT_BUTTON, self.OnButton, id=btn.GetId())
694
695 self.indices.append(btn.GetId())
66dae888 696
37840b8b
RD
697 if count in [0, 3, 5]:
698 self.titleBar.AddSeparator()
699
700 self.strings = ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth"]
66dae888 701
37840b8b 702 self.ChangeLayout()
66dae888 703 self.Thaw()
37840b8b
RD
704 self.titleBar.DoLayout()
705
66dae888 706
37840b8b 707 def ChangeLayout(self):
66dae888 708
37840b8b
RD
709 # Change the layout after a switch in ButtonPanel alignment
710 self.Freeze()
711
712 if self.alignment in [bp.BP_ALIGN_LEFT, bp.BP_ALIGN_RIGHT]:
713 vSizer = wx.BoxSizer(wx.VERTICAL)
714 else:
715 vSizer = wx.BoxSizer(wx.HORIZONTAL)
66dae888 716
37840b8b
RD
717 self.mainPanel.SetSizer(vSizer)
718
719 vSizer.Add(self.titleBar, 0, wx.EXPAND)
720 vSizer.Add((20, 20))
721 vSizer.Add(self.logtext, 1, wx.EXPAND|wx.ALL, 5)
722
723 vSizer.Layout()
724 self.mainPanel.Layout()
725 self.Thaw()
726
727
728 def SetProperties(self):
729
730 # No resetting if the user is using the Settings Panel
731 if self.useredited:
732 return
733
734 # Sets the colours for the two demos: called only if the user didn't
735 # modify the colours and sizes using the Settings Panel
736 bpArt = self.titleBar.GetBPArt()
737
738 if self.style & bp.BP_USE_GRADIENT:
739 # set the color the text is drawn with
740 bpArt.SetColor(bp.BP_TEXT_COLOR, wx.WHITE)
741
742 # These default to white and whatever is set in the system
743 # settings for the wx.SYS_COLOUR_ACTIVECAPTION. We'll use
744 # some specific settings to ensure a consistent look for the
745 # demo.
746 bpArt.SetColor(bp.BP_BORDER_COLOR, wx.Colour(120,23,224))
747 bpArt.SetColor(bp.BP_GRADIENT_COLOR_FROM, wx.Colour(60,11,112))
748 bpArt.SetColor(bp.BP_GRADIENT_COLOR_TO, wx.Colour(120,23,224))
749 bpArt.SetColor(bp.BP_BUTTONTEXT_COLOR, wx.Colour(70,143,255))
750 bpArt.SetColor(bp.BP_SEPARATOR_COLOR,
751 bp.BrightenColour(wx.Colour(60, 11, 112), 0.85))
752 bpArt.SetColor(bp.BP_SELECTION_BRUSH_COLOR, wx.Color(225, 225, 255))
753 bpArt.SetColor(bp.BP_SELECTION_PEN_COLOR, wx.SystemSettings_GetColour(wx.SYS_COLOUR_ACTIVECAPTION))
754
755 else:
756
757 background = self.titleBar.GetBackgroundColour()
758 bpArt.SetColor(bp.BP_TEXT_COLOR, wx.BLUE)
759 bpArt.SetColor(bp.BP_BORDER_COLOR,
760 bp.BrightenColour(background, 0.85))
761 bpArt.SetColor(bp.BP_SEPARATOR_COLOR,
762 bp.BrightenColour(background, 0.85))
763 bpArt.SetColor(bp.BP_BUTTONTEXT_COLOR, wx.BLACK)
764 bpArt.SetColor(bp.BP_SELECTION_BRUSH_COLOR, wx.Colour(242, 242, 235))
765 bpArt.SetColor(bp.BP_SELECTION_PEN_COLOR, wx.Colour(206, 206, 195))
766
767 self.titleBar.SetStyle(self.style)
768
769
770 def OnAlignment(self, event):
771
772 # Here we change the alignment property of ButtonPanel
773 current = event.GetId()
774 edit_menu = self.GetMenuBar().FindMenu("Edit")
775 edit_menu = self.GetMenuBar().GetMenu(edit_menu)
776 menu = edit_menu.FindItem("BP_ALIGN_LEFT")
777
778 alignment = self.alignments[current - menu]
779 self.alignment = alignment
66dae888 780
37840b8b
RD
781 self.ChangeLayout()
782 self.titleBar.SetAlignment(alignment)
783 self.mainPanel.Layout()
784
66dae888
RD
785 event.Skip()
786
787
37840b8b
RD
788 def OnDefaultStyle(self, event):
789
790 # Restore the ButtonPanel default style (no gradient)
791 self.style = bp.BP_DEFAULT_STYLE
792 self.SetProperties()
793
794 event.Skip()
795
796
797 def OnGradientStyle(self, event):
798
799 # Use gradients to paint ButtonPanel background
800 self.style = bp.BP_USE_GRADIENT
801 self.SetProperties()
802
803 event.Skip()
804
805
806 def OnDefaultDemo(self, event):
807
808 # Reload the default startup demo
809 self.CreateButtons()
810 event.Skip()
811
812
813 def OnButtonOnly(self, event):
814
815 # Reload the button-only demo
816 self.ButtonOnly()
817 event.Skip()
818
819
66dae888 820 def OnButton(self, event):
37840b8b 821
66dae888 822 btn = event.GetId()
37840b8b
RD
823 indx = self.indices.index(btn)
824
66dae888
RD
825 self.logtext.AppendText("Event Fired From " + self.strings[indx] + " Button\n")
826 event.Skip()
827
828
37840b8b
RD
829 def OnSetBarText(self, event):
830
831 dlg = wx.TextEntryDialog(self, "Enter The Text You Wish To Display On The Bar (Clear If No Text):",
832 "Set Text", self.titleBar.GetBarText())
833
834 if dlg.ShowModal() == wx.ID_OK:
835
836 val = dlg.GetValue()
837 self.titleBar.SetBarText(val)
838 self.titleBar.DoLayout()
839 self.mainPanel.Layout()
840
841
842 def OnSettingsPanel(self, event):
843
844 if self.hassettingpanel:
845 self.settingspanel.Raise()
846 return
847
848 self.settingspanel = SettingsPanel(self, -1)
849 self.settingspanel.Show()
850 self.hassettingpanel = True
851
852
66dae888 853 def OnClose(self, event):
37840b8b 854
66dae888 855 self.Destroy()
37840b8b 856 event.Skip()
66dae888
RD
857
858
859 def OnAbout(self, event):
860
861 msg = "This Is The About Dialog Of The ButtonPanel Demo.\n\n" + \
862 "Author: Andrea Gavana @ 02 Oct 2006\n\n" + \
863 "Please Report Any Bug/Requests Of Improvements\n" + \
864 "To Me At The Following Adresses:\n\n" + \
865 "andrea.gavana@gmail.com\n" + "gavana@kpo.kz\n\n" + \
866 "Based On Eran C++ Implementation (wxWidgets Forum).\n\n" + \
867 "Welcome To wxPython " + wx.VERSION_STRING + "!!"
868
869 dlg = wx.MessageDialog(self, msg, "ButtonPanel wxPython Demo",
870 wx.OK | wx.ICON_INFORMATION)
871 dlg.ShowModal()
872 dlg.Destroy()
873
37840b8b 874
66dae888
RD
875#----------------------------------------------------------------------
876
877class TestPanel(wx.Panel):
878 def __init__(self, parent, log):
879 self.log = log
880 wx.Panel.__init__(self, parent, -1)
881
882 b = wx.Button(self, -1, " Test ButtonPanel ", (50,50))
883 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
884
885
886 def OnButton(self, evt):
887 self.win = ButtonPanelDemo(self)
888 self.win.Show(True)
889
890
891#----------------------------------------------------------------------
892
893def runTest(frame, nb, log):
894 win = TestPanel(nb, log)
895 return win
896
897#----------------------------------------------------------------------
898
899
900
979f2f9c 901overview = bp.__doc__
66dae888
RD
902
903
904
905if __name__ == '__main__':
906 import sys,os
907 import run
908 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
61b35490 909
66dae888
RD
910
911