]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/FoldPanelBar.py
better handling of empty MDI parent frame visibility: show it only when there are...
[wxWidgets.git] / wxPython / demo / FoldPanelBar.py
1
2 import wx
3 import wx.lib.foldpanelbar as fpb
4
5
6 # ----------------------------------------------------------------------------
7 # Extended Demo Implementation
8 #
9 # This demo shows how to use custom CaptionBar styles and custom icons for
10 # the caption bars. here i used the standard Windows XP icons for the
11 # collapsed and expanded state.
12 # ----------------------------------------------------------------------------
13
14 #----------------------------------------------------------------------
15 # different icons for the collapsed/expanded states.
16 # Taken from standard Windows XP collapsed/expanded states.
17 #----------------------------------------------------------------------
18
19 def GetCollapsedIconData():
20 return \
21 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
22 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
23 \x00\x01\x8eIDAT8\x8d\xa5\x93-n\xe4@\x10\x85?g\x03\n6lh)\xc4\xd2\x12\xc3\x81\
24 \xd6\xa2I\x90\x154\xb9\x81\x8f1G\xc8\x11\x16\x86\xcd\xa0\x99F\xb3A\x91\xa1\
25 \xc9J&\x96L"5lX\xcc\x0bl\xf7v\xb2\x7fZ\xa5\x98\xebU\xbdz\xf5\\\x9deW\x9f\xf8\
26 H\\\xbfO|{y\x9dT\x15P\x04\x01\x01UPUD\x84\xdb/7YZ\x9f\xa5\n\xce\x97aRU\x8a\
27 \xdc`\xacA\x00\x04P\xf0!0\xf6\x81\xa0\xf0p\xff9\xfb\x85\xe0|\x19&T)K\x8b\x18\
28 \xf9\xa3\xe4\xbe\xf3\x8c^#\xc9\xd5\n\xa8*\xc5?\x9a\x01\x8a\xd2b\r\x1cN\xc3\
29 \x14\t\xce\x97a\xb2F0Ks\xd58\xaa\xc6\xc5\xa6\xf7\xdfya\xe7\xbdR\x13M2\xf9\
30 \xf9qKQ\x1fi\xf6-\x00~T\xfac\x1dq#\x82,\xe5q\x05\x91D\xba@\xefj\xba1\xf0\xdc\
31 zzW\xcff&\xb8,\x89\xa8@Q\xd6\xaaf\xdfRm,\xee\xb1BDxr#\xae\xf5|\xddo\xd6\xe2H\
32 \x18\x15\x84\xa0q@]\xe54\x8d\xa3\xedf\x05M\xe3\xd8Uy\xc4\x15\x8d\xf5\xd7\x8b\
33 ~\x82\x0fh\x0e"\xb0\xad,\xee\xb8c\xbb\x18\xe7\x8e;6\xa5\x89\x04\xde\xff\x1c\
34 \x16\xef\xe0p\xfa>\x19\x11\xca\x8d\x8d\xe0\x93\x1b\x01\xd8m\xf3(;x\xa5\xef=\
35 \xb7w\xf3\x1d$\x7f\xc1\xe0\xbd\xa7\xeb\xa0(,"Kc\x12\xc1+\xfd\xe8\tI\xee\xed)\
36 \xbf\xbcN\xc1{D\x04k\x05#\x12\xfd\xf2a\xde[\x81\x87\xbb\xdf\x9cr\x1a\x87\xd3\
37 0)\xba>\x83\xd5\xb97o\xe0\xaf\x04\xff\x13?\x00\xd2\xfb\xa9`z\xac\x80w\x00\
38 \x00\x00\x00IEND\xaeB`\x82'
39
40 def GetCollapsedIconBitmap():
41 return wx.BitmapFromImage(GetCollapsedIconImage())
42
43 def GetCollapsedIconImage():
44 import cStringIO
45 stream = cStringIO.StringIO(GetCollapsedIconData())
46 return wx.ImageFromStream(stream)
47
48 #----------------------------------------------------------------------
49 def GetExpandedIconData():
50 return \
51 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
52 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
53 \x00\x01\x9fIDAT8\x8d\x95\x93\xa1\x8e\xdc0\x14EO\xb2\xc4\xd0\xd2\x12\xb7(mI\
54 \xa4%V\xd1lQT4[4-\x9a\xfe\xc1\xc2|\xc6\xc2~BY\x83:A3E\xd3\xa0*\xa4\xd2\x90H!\
55 \x95\x0c\r\r\x1fK\x81g\xb2\x99\x84\xb4\x0fY\xd6\xbb\xc7\xf7>=\'Iz\xc3\xbcv\
56 \xfbn\xb8\x9c\x15 \xe7\xf3\xc7\x0fw\xc9\xbc7\x99\x03\x0e\xfbn0\x99F+\x85R\
57 \x80RH\x10\x82\x08\xde\x05\x1ef\x90+\xc0\xe1\xd8\ryn\xd0Z-\\A\xb4\xd2\xf7\
58 \x9e\xfbwoF\xc8\x088\x1c\xbbae\xb3\xe8y&\x9a\xdf\xf5\xbd\xe7\xfem\x84\xa4\
59 \x97\xccYf\x16\x8d\xdb\xb2a]\xfeX\x18\xc9s\xc3\xe1\x18\xe7\x94\x12cb\xcc\xb5\
60 \xfa\xb1l8\xf5\x01\xe7\x84\xc7\xb2Y@\xb2\xcc0\x02\xb4\x9a\x88%\xbe\xdc\xb4\
61 \x9e\xb6Zs\xaa74\xadg[6\x88<\xb7]\xc6\x14\x1dL\x86\xe6\x83\xa0\x81\xba\xda\
62 \x10\x02x/\xd4\xd5\x06\r\x840!\x9c\x1fM\x92\xf4\x86\x9f\xbf\xfe\x0c\xd6\x9ae\
63 \xd6u\x8d \xf4\xf5\x165\x9b\x8f\x04\xe1\xc5\xcb\xdb$\x05\x90\xa97@\x04lQas\
64 \xcd*7\x14\xdb\x9aY\xcb\xb8\\\xe9E\x10|\xbc\xf2^\xb0E\x85\xc95_\x9f\n\xaa/\
65 \x05\x10\x81\xce\xc9\xa8\xf6><G\xd8\xed\xbbA)X\xd9\x0c\x01\x9a\xc6Q\x14\xd9h\
66 [\x04\xda\xd6c\xadFkE\xf0\xc2\xab\xd7\xb7\xc9\x08\x00\xf8\xf6\xbd\x1b\x8cQ\
67 \xd8|\xb9\x0f\xd3\x9a\x8a\xc7\x08\x00\x9f?\xdd%\xde\x07\xda\x93\xc3{\x19C\
68 \x8a\x9c\x03\x0b8\x17\xe8\x9d\xbf\x02.>\x13\xc0n\xff{PJ\xc5\xfdP\x11""<\xbc\
69 \xff\x87\xdf\xf8\xbf\xf5\x17FF\xaf\x8f\x8b\xd3\xe6K\x00\x00\x00\x00IEND\xaeB\
70 `\x82'
71
72 def GetExpandedIconBitmap():
73 return wx.BitmapFromImage(GetExpandedIconImage())
74
75 def GetExpandedIconImage():
76 import cStringIO
77 stream = cStringIO.StringIO(GetExpandedIconData())
78 return wx.ImageFromStream(stream)
79
80 #----------------------------------------------------------------------
81 def GetMondrianData():
82 return \
83 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\
84 \x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID\
85 ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\
86 o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\
87 \xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\
88 \x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\
89 \x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82'
90
91 def GetMondrianBitmap():
92 return wx.BitmapFromImage(GetMondrianImage())
93
94 def GetMondrianImage():
95 import cStringIO
96 stream = cStringIO.StringIO(GetMondrianData())
97 return wx.ImageFromStream(stream)
98
99 def GetMondrianIcon():
100 icon = wx.EmptyIcon()
101 icon.CopyFromBitmap(GetMondrianBitmap())
102 return icon
103
104 # ----------------------------------------------------------------------------
105 # Beginning Of Extended Demo
106 # ----------------------------------------------------------------------------
107
108 class Extended(wx.Frame):
109
110 def __init__(self, parent, id=wx.ID_ANY, title="", pos=wx.DefaultPosition,
111 size=(700,650), style=wx.DEFAULT_FRAME_STYLE):
112
113 wx.Frame.__init__(self, parent, id, title, pos, size, style)
114
115 self._flags = 0
116
117 self.SetIcon(GetMondrianIcon())
118 self.SetMenuBar(self.CreateMenuBar())
119
120 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
121 self.statusbar.SetStatusWidths([-4, -3])
122 self.statusbar.SetStatusText("Andrea Gavana @ 23 Mar 2005", 0)
123 self.statusbar.SetStatusText("Welcome to wxPython!", 1)
124
125 self._leftWindow1 = wx.SashLayoutWindow(self, 101, wx.DefaultPosition,
126 wx.Size(200, 1000), wx.NO_BORDER |
127 wx.SW_3D | wx.CLIP_CHILDREN)
128
129 self._leftWindow1.SetDefaultSize(wx.Size(220, 1000))
130 self._leftWindow1.SetOrientation(wx.LAYOUT_VERTICAL)
131 self._leftWindow1.SetAlignment(wx.LAYOUT_LEFT)
132 self._leftWindow1.SetSashVisible(wx.SASH_RIGHT, True)
133 self._leftWindow1.SetExtraBorderSize(10)
134
135 self._pnl = 0
136
137 # will occupy the space not used by the Layout Algorithm
138 self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)
139 wx.StaticText(self.remainingSpace, -1,
140 "Use your imagination for what kinds of things to put in this window...",
141 (15,30))
142
143 self.ID_WINDOW_TOP = 100
144 self.ID_WINDOW_LEFT1 = 101
145 self.ID_WINDOW_RIGHT1 = 102
146 self.ID_WINDOW_BOTTOM = 103
147
148 self._leftWindow1.Bind(wx.EVT_SASH_DRAGGED_RANGE, self.OnFoldPanelBarDrag,
149 id=100, id2=103)
150 self.Bind(wx.EVT_SIZE, self.OnSize)
151 self.Bind(wx.EVT_SCROLL, self.OnSlideColour)
152
153 self.ReCreateFoldPanel(0)
154
155
156 def OnSize(self, event):
157
158 wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
159 event.Skip()
160
161
162 def OnQuit(self, event):
163
164 self.Destroy()
165
166
167 def OnAbout(self, event):
168
169 msg = "This is the about dialog of the FoldPanelBar demo.\n\n" + \
170 "Author: Andrea Gavana @ 23 Mar 2005\n\n" + \
171 "Please report any bug/requests or improvements\n" + \
172 "To me at the following adresses:\n\n" + \
173 "andrea.gavana@agip.it\n" + "andrea_gavana@tin.it\n\n" + \
174 "Based On Julian Smart C++ demo implementation.\n\n" + \
175 "Welcome To wxPython " + wx.VERSION_STRING + "!!"
176
177 dlg = wx.MessageDialog(self, msg, "FoldPanelBar Extended Demo",
178 wx.OK | wx.ICON_INFORMATION)
179 dlg.SetFont(wx.Font(8, wx.NORMAL, wx.NORMAL, wx.NORMAL, False, "Verdana"))
180 dlg.ShowModal()
181 dlg.Destroy()
182
183
184 def OnToggleWindow(self, event):
185
186 self._leftWindow1.Show(not self._leftWindow1.IsShown())
187 # Leaves bits of itself behind sometimes
188 wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
189 self.remainingSpace.Refresh()
190
191 event.Skip()
192
193
194 def OnFoldPanelBarDrag(self, event):
195
196 if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
197 return
198
199 if event.GetId() == self.ID_WINDOW_LEFT1:
200 self._leftWindow1.SetDefaultSize(wx.Size(event.GetDragRect().width, 1000))
201
202
203 # Leaves bits of itself behind sometimes
204 wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
205 self.remainingSpace.Refresh()
206
207 event.Skip()
208
209
210 def ReCreateFoldPanel(self, fpb_flags):
211
212 # delete earlier panel
213 self._leftWindow1.DestroyChildren()
214
215 # recreate the foldpanelbar
216
217 self._pnl = fpb.FoldPanelBar(self._leftWindow1, -1, wx.DefaultPosition,
218 wx.Size(-1,-1), fpb.FPB_DEFAULT_STYLE, fpb_flags)
219
220 Images = wx.ImageList(16,16)
221 Images.Add(GetExpandedIconBitmap())
222 Images.Add(GetCollapsedIconBitmap())
223
224 item = self._pnl.AddFoldPanel("Caption Colours", collapsed=False,
225 foldIcons=Images)
226
227 self._pnl.AddFoldPanelWindow(item, wx.StaticText(item, -1, "Adjust The First Colour"),
228 fpb.FPB_ALIGN_WIDTH, 5, 20)
229
230 # RED color spin control
231 self._rslider1 = wx.Slider(item, -1, 0, 0, 255)
232 self._pnl.AddFoldPanelWindow(item, self._rslider1, fpb.FPB_ALIGN_WIDTH, 2, 20)
233
234 # GREEN color spin control
235 self._gslider1 = wx.Slider(item, -1, 0, 0, 255)
236 self._pnl.AddFoldPanelWindow(item, self._gslider1, fpb.FPB_ALIGN_WIDTH, 0, 20)
237
238 # BLUE color spin control
239 self._bslider1 = wx.Slider(item, -1, 0, 0, 255)
240 self._pnl.AddFoldPanelWindow(item, self._bslider1, fpb.FPB_ALIGN_WIDTH, 0, 20)
241
242 self._pnl.AddFoldPanelSeparator(item)
243
244 self._pnl.AddFoldPanelWindow(item, wx.StaticText(item, -1, "Adjust The Second Colour"),
245 fpb.FPB_ALIGN_WIDTH, 5, 20)
246
247 # RED color spin control
248 self._rslider2 = wx.Slider(item, -1, 0, 0, 255)
249 self._pnl.AddFoldPanelWindow(item, self._rslider2, fpb.FPB_ALIGN_WIDTH, 2, 20)
250
251 # GREEN color spin control
252 self._gslider2 = wx.Slider(item, -1, 0, 0, 255)
253 self._pnl.AddFoldPanelWindow(item, self._gslider2, fpb.FPB_ALIGN_WIDTH, 0, 20)
254
255 # BLUE color spin control
256 self._bslider2 = wx.Slider(item, -1, 0, 0, 255)
257 self._pnl.AddFoldPanelWindow(item, self._bslider2, fpb.FPB_ALIGN_WIDTH, 0, 20)
258
259 self._pnl.AddFoldPanelSeparator(item)
260
261 button1 = wx.Button(item, wx.ID_ANY, "Apply To All")
262 button1.Bind(wx.EVT_BUTTON, self.OnExpandMe)
263 self._pnl.AddFoldPanelWindow(item, button1)
264
265 # read back current gradients and set the sliders
266 # for the colour which is now taken as default
267
268 style = self._pnl.GetCaptionStyle(item)
269 col = style.GetFirstColour()
270
271 self._rslider1.SetValue(col.Red())
272 self._gslider1.SetValue(col.Green())
273 self._bslider1.SetValue(col.Blue())
274
275 col = style.GetSecondColour()
276 self._rslider2.SetValue(col.Red())
277 self._gslider2.SetValue(col.Green())
278 self._bslider2.SetValue(col.Blue())
279
280 # put down some caption styles from which the user can
281 # select to show how the current or all caption bars will look like
282
283 item = self._pnl.AddFoldPanel("Caption Style", False, foldIcons=Images)
284
285 self.ID_USE_VGRADIENT = wx.NewId()
286 self.ID_USE_HGRADIENT = wx.NewId()
287 self.ID_USE_SINGLE = wx.NewId()
288 self.ID_USE_RECTANGLE = wx.NewId()
289 self.ID_USE_FILLED_RECTANGLE = wx.NewId()
290
291 currStyle = wx.RadioButton(item, self.ID_USE_VGRADIENT, "&Vertical Gradient")
292 self._pnl.AddFoldPanelWindow(item, currStyle, fpb.FPB_ALIGN_WIDTH,
293 fpb.FPB_DEFAULT_SPACING, 10)
294
295 currStyle.SetValue(True)
296
297 radio1 = wx.RadioButton(item, self.ID_USE_HGRADIENT, "&Horizontal Gradient")
298 radio2 = wx.RadioButton(item, self.ID_USE_SINGLE, "&Single Colour")
299 radio3 = wx.RadioButton(item, self.ID_USE_RECTANGLE, "&Rectangle Box")
300 radio4 = wx.RadioButton(item, self.ID_USE_FILLED_RECTANGLE, "&Filled Rectangle Box")
301
302 currStyle.Bind(wx.EVT_RADIOBUTTON, self.OnStyleChange)
303 radio1.Bind(wx.EVT_RADIOBUTTON, self.OnStyleChange)
304 radio2.Bind(wx.EVT_RADIOBUTTON, self.OnStyleChange)
305 radio3.Bind(wx.EVT_RADIOBUTTON, self.OnStyleChange)
306 radio4.Bind(wx.EVT_RADIOBUTTON, self.OnStyleChange)
307
308 self._pnl.AddFoldPanelWindow(item, radio1, fpb.FPB_ALIGN_WIDTH, fpb.FPB_DEFAULT_SPACING, 10)
309 self._pnl.AddFoldPanelWindow(item, radio2, fpb.FPB_ALIGN_WIDTH, fpb.FPB_DEFAULT_SPACING, 10)
310 self._pnl.AddFoldPanelWindow(item, radio3, fpb.FPB_ALIGN_WIDTH, fpb.FPB_DEFAULT_SPACING, 10)
311 self._pnl.AddFoldPanelWindow(item, radio4, fpb.FPB_ALIGN_WIDTH, fpb.FPB_DEFAULT_SPACING, 10)
312
313 self._pnl.AddFoldPanelSeparator(item)
314
315 self._single = wx.CheckBox(item, -1, "&Only This Caption")
316 self._pnl.AddFoldPanelWindow(item, self._single, fpb.FPB_ALIGN_WIDTH,
317 fpb.FPB_DEFAULT_SPACING, 10)
318
319 # one more panel to finish it
320
321 cs = fpb.CaptionBarStyle()
322 cs.SetCaptionStyle(fpb.CAPTIONBAR_RECTANGLE)
323
324 item = self._pnl.AddFoldPanel("Misc Stuff", collapsed=True, foldIcons=Images,
325 cbstyle=cs)
326
327 button2 = wx.Button(item, wx.NewId(), "Collapse All")
328 self._pnl.AddFoldPanelWindow(item, button2)
329 self._pnl.AddFoldPanelWindow(item, wx.StaticText(item, -1, "Enter Some Comments"),
330 fpb.FPB_ALIGN_WIDTH, 5, 20)
331 self._pnl.AddFoldPanelWindow(item, wx.TextCtrl(item, -1, "Comments"),
332 fpb.FPB_ALIGN_WIDTH, fpb.FPB_DEFAULT_SPACING, 10)
333
334 button2.Bind(wx.EVT_BUTTON, self.OnCollapseMe)
335 self.radiocontrols = [currStyle, radio1, radio2, radio3, radio4]
336
337 self._leftWindow1.SizeWindows()
338
339
340 def OnCreateBottomStyle(self, event):
341
342 # recreate with style collapse to bottom, which means
343 # all panels that are collapsed are placed at the bottom,
344 # or normal
345
346 if event.IsChecked():
347 self._flags = self._flags | fpb.FPB_COLLAPSE_TO_BOTTOM
348 else:
349 self._flags = self._flags & ~fpb.FPB_COLLAPSE_TO_BOTTOM
350
351 self.ReCreateFoldPanel(self._flags)
352
353
354 def OnCreateNormalStyle(self, event):
355
356 # recreate with style where only one panel at the time is
357 # allowed to be opened
358
359 # TODO: Not yet implemented even in the C++ class!!!!
360
361 if event.IsChecked():
362 self._flags = self._flags | fpb.FPB_SINGLE_FOLD
363 else:
364 self._flags = self._flags & ~fpb.FPB_SINGLE_FOLD
365
366 self.ReCreateFoldPanel(self._flags)
367
368
369 def OnCollapseMe(self, event):
370
371 for i in range(0, self._pnl.GetCount()):
372 item = self._pnl.GetFoldPanel(i)
373 self._pnl.Collapse(item)
374
375
376 def OnExpandMe(self, event):
377
378 col1 = wx.Colour(self._rslider1.GetValue(), self._gslider1.GetValue(),
379 self._bslider1.GetValue())
380 col2 = wx.Colour(self._rslider2.GetValue(), self._gslider2.GetValue(),
381 self._bslider2.GetValue())
382
383 style = fpb.CaptionBarStyle()
384
385 style.SetFirstColour(col1)
386 style.SetSecondColour(col2)
387
388 counter = 0
389 for items in self.radiocontrols:
390 if items.GetValue():
391 break
392 counter = counter + 1
393
394 if counter == 0:
395 mystyle = fpb.CAPTIONBAR_GRADIENT_V
396 elif counter == 1:
397 mystyle = fpb.CAPTIONBAR_GRADIENT_H
398 elif counter == 2:
399 mystyle = fpb.CAPTIONBAR_SINGLE
400 elif counter == 3:
401 mystyle = fpb.CAPTIONBAR_RECTANGLE
402 else:
403 mystyle = fpb.CAPTIONBAR_FILLED_RECTANGLE
404
405 style.SetCaptionStyle(mystyle)
406 self._pnl.ApplyCaptionStyleAll(style)
407
408
409 def OnSlideColour(self, event):
410
411 col1 = wx.Colour(self._rslider1.GetValue(), self._gslider1.GetValue(),
412 self._bslider1.GetValue())
413 col2 = wx.Colour(self._rslider2.GetValue(), self._gslider2.GetValue(),
414 self._bslider2.GetValue())
415
416 style = fpb.CaptionBarStyle()
417
418 counter = 0
419 for items in self.radiocontrols:
420 if items.GetValue():
421 break
422
423 counter = counter + 1
424
425 if counter == 0:
426 mystyle = fpb.CAPTIONBAR_GRADIENT_V
427 elif counter == 1:
428 mystyle = fpb.CAPTIONBAR_GRADIENT_H
429 elif counter == 2:
430 mystyle = fpb.CAPTIONBAR_SINGLE
431 elif counter == 3:
432 mystyle = fpb.CAPTIONBAR_RECTANGLE
433 else:
434 mystyle = fpb.CAPTIONBAR_FILLED_RECTANGLE
435
436 style.SetFirstColour(col1)
437 style.SetSecondColour(col2)
438 style.SetCaptionStyle(mystyle)
439
440 item = self._pnl.GetFoldPanel(0)
441 self._pnl.ApplyCaptionStyle(item, style)
442
443
444 def OnStyleChange(self, event):
445
446 style = fpb.CaptionBarStyle()
447
448 eventid = event.GetId()
449
450 if eventid == self.ID_USE_HGRADIENT:
451 style.SetCaptionStyle(fpb.CAPTIONBAR_GRADIENT_H)
452
453 elif eventid == self.ID_USE_VGRADIENT:
454 style.SetCaptionStyle(fpb.CAPTIONBAR_GRADIENT_V)
455
456 elif eventid == self.ID_USE_SINGLE:
457 style.SetCaptionStyle(fpb.CAPTIONBAR_SINGLE)
458
459 elif eventid == self.ID_USE_RECTANGLE:
460 style.SetCaptionStyle(fpb.CAPTIONBAR_RECTANGLE)
461
462 elif eventid == self.ID_USE_FILLED_RECTANGLE:
463 style.SetCaptionStyle(fpb.CAPTIONBAR_FILLED_RECTANGLE)
464
465 else:
466 raise "ERROR: Undefined Style Selected For CaptionBar: " + repr(eventid)
467
468 col1 = wx.Colour(self._rslider1.GetValue(), self._gslider1.GetValue(),
469 self._bslider1.GetValue())
470 col2 = wx.Colour(self._rslider2.GetValue(), self._gslider2.GetValue(),
471 self._bslider2.GetValue())
472
473 style.SetFirstColour(col1)
474 style.SetSecondColour(col2)
475
476 if self._single.GetValue():
477 item = self._pnl.GetFoldPanel(1)
478 self._pnl.ApplyCaptionStyle(item, style)
479 else:
480 self._pnl.ApplyCaptionStyleAll(style)
481
482
483 def CreateMenuBar(self, with_window=False):
484
485 # Make a menubar
486 file_menu = wx.Menu()
487
488 FPBTEST_QUIT = wx.NewId()
489 FPBTEST_REFRESH = wx.NewId()
490 FPB_BOTTOM_STICK = wx.NewId()
491 FPB_SINGLE_FOLD = wx.NewId()
492 FPBTEST_TOGGLE_WINDOW = wx.NewId()
493 FPBTEST_ABOUT = wx.NewId()
494
495 file_menu.Append(FPBTEST_QUIT, "&Exit")
496
497 option_menu = None
498
499 if with_window:
500 # Dummy option
501 option_menu = wx.Menu()
502 option_menu.Append(FPBTEST_REFRESH, "&Refresh picture")
503
504 # make fold panel menu
505
506 fpb_menu = wx.Menu()
507 fpb_menu.AppendCheckItem(FPB_BOTTOM_STICK, "Create with &fpb.FPB_COLLAPSE_TO_BOTTOM")
508
509 # Not Yet Implemented In The C++ class!!!
510 # fpb_menu.AppendCheckItem(FPB_SINGLE_FOLD, _T("Create with &FPB_SINGLE_FOLD"))
511
512 fpb_menu.AppendSeparator()
513 fpb_menu.Append(FPBTEST_TOGGLE_WINDOW, "&Toggle FoldPanelBar")
514
515 help_menu = wx.Menu()
516 help_menu.Append(FPBTEST_ABOUT, "&About")
517
518 menu_bar = wx.MenuBar()
519
520 menu_bar.Append(file_menu, "&File")
521 menu_bar.Append(fpb_menu, "&FoldPanel")
522
523 if option_menu:
524 menu_bar.Append(option_menu, "&Options")
525
526 menu_bar.Append(help_menu, "&Help")
527
528 self.Bind(wx.EVT_MENU, self.OnAbout, id=FPBTEST_ABOUT)
529 self.Bind(wx.EVT_MENU, self.OnQuit, id=FPBTEST_QUIT)
530 self.Bind(wx.EVT_MENU, self.OnToggleWindow, id=FPBTEST_TOGGLE_WINDOW)
531 self.Bind(wx.EVT_MENU, self.OnCreateBottomStyle, id=FPB_BOTTOM_STICK)
532 self.Bind(wx.EVT_MENU, self.OnCreateNormalStyle, id=FPB_SINGLE_FOLD)
533
534 return menu_bar
535
536
537 # ----------------------------------------------------------------------------
538 # Collapsed Demo Implementation
539 # ----------------------------------------------------------------------------
540
541 class FoldTestPanel(wx.Panel):
542
543 def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize,
544 style=wx.NO_BORDER | wx.TAB_TRAVERSAL):
545
546 wx.Panel.__init__(self, parent, id, pos, size, style)
547
548 self.CreateControls()
549 self.GetSizer().Fit(self)
550 self.GetSizer().SetSizeHints(self)
551 self.GetSizer().Layout()
552
553 self.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
554
555
556 def OnPressCaption(self, event):
557 event.Skip()
558
559 def CreateControls(self):
560
561 sizer = wx.BoxSizer(wx.VERTICAL)
562 self.SetSizer(sizer)
563
564 subpanel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
565 wx.NO_BORDER | wx.TAB_TRAVERSAL)
566 sizer.Add(subpanel, 1, wx.GROW | wx.ADJUST_MINSIZE, 5)
567
568 subsizer = wx.BoxSizer(wx.VERTICAL)
569 subpanel.SetSizer(subsizer)
570 itemstrings = ["One", "Two", "Three"]
571
572 item5 = wx.Choice(subpanel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
573 itemstrings, 0)
574
575 subsizer.Add(item5, 0, wx.GROW | wx.ALL, 5)
576
577 item6 = wx.TextCtrl(subpanel, wx.ID_ANY, "", wx.DefaultPosition, wx.DefaultSize,
578 wx.TE_MULTILINE)
579 subsizer.Add(item6, 1, wx.GROW | wx.ALL, 5)
580
581 item7 = wx.RadioButton(subpanel, wx.ID_ANY, "I Like This", wx.DefaultPosition,
582 wx.DefaultSize, 0)
583 item7.SetValue(True)
584 subsizer.Add(item7, 0, wx.ALIGN_LEFT | wx.ALL, 5)
585
586 item8 = wx.RadioButton(subpanel, wx.ID_ANY, "I Hate It", wx.DefaultPosition,
587 wx.DefaultSize, 0)
588 item8.SetValue(False)
589 subsizer.Add(item8, 0, wx.ALIGN_LEFT | wx.ALL, 5)
590
591
592 # ----------------------------------------------------------------------------
593
594 class Collapsed(wx.Frame):
595
596 def __init__(self, parent, id=wx.ID_ANY, title="", pos=wx.DefaultPosition,
597 size=(400,300), style=wx.DEFAULT_FRAME_STYLE):
598
599 wx.Frame.__init__(self, parent, id, title, pos, size, style)
600
601 self.SetIcon(GetMondrianIcon())
602 self.SetMenuBar(self.CreateMenuBar())
603
604 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
605 self.statusbar.SetStatusWidths([-4, -3])
606 self.statusbar.SetStatusText("Andrea Gavana @ 23 Mar 2005", 0)
607 self.statusbar.SetStatusText("Welcome to wxPython!", 1)
608
609 self.CreateFoldBar()
610
611
612 def CreateFoldBar(self, vertical=True):
613
614 if vertical:
615 self.SetSize((500,600))
616 else:
617 self.SetSize((700,300))
618
619 newstyle = (vertical and [fpb.FPB_VERTICAL] or [fpb.FPB_HORIZONTAL])[0]
620
621 bar = fpb.FoldPanelBar(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
622 fpb.FPB_DEFAULT_STYLE | newstyle, fpb.FPB_COLLAPSE_TO_BOTTOM)
623
624 item = bar.AddFoldPanel("Test me", collapsed=False)
625 button1 = wx.Button(item, wx.ID_ANY, "Collapse Me")
626 button1.Bind(wx.EVT_BUTTON, self.OnCollapseMe)
627
628 bar.AddFoldPanelWindow(item, button1, fpb.FPB_ALIGN_LEFT)
629
630 item = bar.AddFoldPanel("Test me too!", collapsed=True)
631
632 button2 = wx.Button(item, wx.ID_ANY, "Expand First One")
633 button2.Bind(wx.EVT_BUTTON, self.OnExpandMe)
634
635 bar.AddFoldPanelWindow(item, button2)
636 bar.AddFoldPanelSeparator(item)
637
638 newfoldpanel = FoldTestPanel(item, wx.ID_ANY)
639 bar.AddFoldPanelWindow(item, newfoldpanel)
640
641 bar.AddFoldPanelSeparator(item)
642
643 bar.AddFoldPanelWindow(item, wx.TextCtrl(item, wx.ID_ANY, "Comment"),
644 fpb.FPB_ALIGN_LEFT, fpb.FPB_DEFAULT_SPACING, 20)
645
646 item = bar.AddFoldPanel("Some Opinions ...", collapsed=False)
647 bar.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "I Like This"))
648
649 if vertical:
650 # do not add this for horizontal for better presentation
651 bar.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "And also this"))
652 bar.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "And gimme this too"))
653
654 bar.AddFoldPanelSeparator(item)
655
656 bar.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "Check this too if you like"))
657
658 if vertical:
659 # do not add this for horizontal for better presentation
660 bar.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "What about this"))
661
662 item = bar.AddFoldPanel("Choose one ...", collapsed=False)
663 bar.AddFoldPanelWindow(item, wx.StaticText(item, wx.ID_ANY, "Enter your comment"))
664 bar.AddFoldPanelWindow(item, wx.TextCtrl(item, wx.ID_ANY, "Comment"),
665 fpb.FPB_ALIGN_WIDTH, fpb.FPB_DEFAULT_SPACING, 20)
666
667 if hasattr(self, "pnl"):
668 self.pnl.Destroy()
669
670 self.pnl = bar
671
672 size = self.GetClientSize()
673 self.pnl.SetDimensions(0, 0, size.GetWidth(), size.GetHeight())
674
675
676 def CreateMenuBar(self):
677
678 FoldPanelBarTest_Quit = wx.NewId()
679 FoldPanelBarTest_About = wx.NewId()
680 FoldPanelBarTest_Horizontal = wx.NewId()
681 FoldPanelBarTest_Vertical = wx.NewId()
682
683 menuFile = wx.Menu()
684 menuFile.Append(FoldPanelBarTest_Horizontal, "&Horizontal\tAlt-H")
685 menuFile.Append(FoldPanelBarTest_Vertical, "&Vertical\tAlt-V")
686 menuFile.AppendSeparator()
687 menuFile.Append(FoldPanelBarTest_Quit, "E&xit\tAlt-X", "Quit This Program")
688
689 helpMenu = wx.Menu()
690 helpMenu.Append(FoldPanelBarTest_About, "&About...\tF1", "Show About Dialog")
691
692 self.FoldPanelBarTest_Vertical = FoldPanelBarTest_Vertical
693 self.FoldPanelBarTest_Horizontal = FoldPanelBarTest_Horizontal
694
695 self.Bind(wx.EVT_MENU, self.OnQuit, id=FoldPanelBarTest_Quit)
696 self.Bind(wx.EVT_MENU, self.OnAbout, id=FoldPanelBarTest_About)
697 self.Bind(wx.EVT_MENU, self.OnOrientation, id=FoldPanelBarTest_Horizontal)
698 self.Bind(wx.EVT_MENU, self.OnOrientation, id=FoldPanelBarTest_Vertical)
699
700 value = wx.MenuBar()
701 value.Append(menuFile, "&File")
702 value.Append(helpMenu, "&Help")
703
704 return value
705
706
707 def OnOrientation(self, event):
708 self.CreateFoldBar(event.GetId() == self.FoldPanelBarTest_Vertical)
709
710
711 def OnQuit(self, event):
712 # True is to force the frame to close
713 self.Close(True)
714
715
716 def OnAbout(self, event):
717
718 msg = "This is the about dialog of the FoldPanelBarTest application.\n\n" + \
719 "Welcome To wxPython " + wx.VERSION_STRING + "!!"
720 dlg = wx.MessageDialog(self, msg, "About FoldPanelBarTest",
721 wx.OK | wx.ICON_INFORMATION)
722 dlg.ShowModal()
723 dlg.Destroy()
724
725
726 def OnCollapseMe(self, event):
727
728 item = self.pnl.GetFoldPanel(0)
729 self.pnl.Collapse(item)
730
731 def OnExpandMe(self, event):
732
733 self.pnl.Expand(self.pnl.GetFoldPanel(0))
734 self.pnl.Collapse(self.pnl.GetFoldPanel(1))
735
736
737
738 # ----------------------------------------------------------------------------
739 # NotCollapsed Implementation
740 # ----------------------------------------------------------------------------
741
742 class NotCollapsed(wx.Frame):
743 def __init__(self, parent, id=wx.ID_ANY, title="", pos=wx.DefaultPosition,
744 size=(400,300), style=wx.DEFAULT_FRAME_STYLE):
745
746 wx.Frame.__init__(self, parent, id, title, pos, size, style)
747
748 self.SetIcon(GetMondrianIcon())
749 self.SetMenuBar(self.CreateMenuBar())
750
751 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
752 self.statusbar.SetStatusWidths([-4, -3])
753 self.statusbar.SetStatusText("Andrea Gavana @ 23 Mar 2005", 0)
754 self.statusbar.SetStatusText("Welcome to wxPython!", 1)
755
756 pnl = fpb.FoldPanelBar(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
757 fpb.FPB_DEFAULT_STYLE | fpb.FPB_VERTICAL)
758
759 item = pnl.AddFoldPanel("Test Me", collapsed=False)
760
761 button1 = wx.Button(item, wx.ID_ANY, "Collapse Me")
762
763 pnl.AddFoldPanelWindow(item, button1, fpb.FPB_ALIGN_LEFT)
764 pnl.AddFoldPanelSeparator(item)
765
766 button1.Bind(wx.EVT_BUTTON, self.OnCollapseMe)
767
768 item = pnl.AddFoldPanel("Test Me Too!", collapsed=True)
769 button2 = wx.Button(item, wx.ID_ANY, "Expand First One")
770 pnl.AddFoldPanelWindow(item, button2, fpb.FPB_ALIGN_LEFT)
771 pnl.AddFoldPanelSeparator(item)
772
773 button2.Bind(wx.EVT_BUTTON, self.OnExpandMe)
774
775 newfoldpanel = FoldTestPanel(item, wx.ID_ANY)
776 pnl.AddFoldPanelWindow(item, newfoldpanel)
777
778 pnl.AddFoldPanelSeparator(item)
779
780 pnl.AddFoldPanelWindow(item, wx.TextCtrl(item, wx.ID_ANY, "Comment"),
781 fpb.FPB_ALIGN_LEFT, fpb.FPB_DEFAULT_SPACING, 20)
782
783 item = pnl.AddFoldPanel("Some Opinions ...", collapsed=False)
784 pnl.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "I Like This"))
785 pnl.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "And Also This"))
786 pnl.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "And Gimme This Too"))
787
788 pnl.AddFoldPanelSeparator(item)
789
790 pnl.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "Check This Too If You Like"))
791 pnl.AddFoldPanelWindow(item, wx.CheckBox(item, wx.ID_ANY, "What About This"))
792
793 item = pnl.AddFoldPanel("Choose One ...", collapsed=False)
794 pnl.AddFoldPanelWindow(item, wx.StaticText(item, wx.ID_ANY, "Enter Your Comment"))
795 pnl.AddFoldPanelWindow(item, wx.TextCtrl(item, wx.ID_ANY, "Comment"),
796 fpb.FPB_ALIGN_WIDTH, fpb.FPB_DEFAULT_SPACING, 20, 20)
797 self.pnl = pnl
798
799
800 def CreateMenuBar(self):
801
802 FoldPanelBarTest_Quit = wx.NewId()
803 FoldPanelBarTest_About = wx.NewId()
804
805 menuFile = wx.Menu()
806 menuFile.Append(FoldPanelBarTest_Quit, "E&xit\tAlt-X", "Quit This Program")
807
808 helpMenu = wx.Menu()
809 helpMenu.Append(FoldPanelBarTest_About, "&About...\tF1", "Show About Dialog")
810
811 self.Bind(wx.EVT_MENU, self.OnQuit, id=FoldPanelBarTest_Quit)
812 self.Bind(wx.EVT_MENU, self.OnAbout, id=FoldPanelBarTest_About)
813
814 value = wx.MenuBar()
815 value.Append(menuFile, "&File")
816 value.Append(helpMenu, "&Help")
817
818 return value
819
820
821 # Event Handlers
822
823 def OnQuit(self, event):
824
825 # True is to force the frame to close
826 self.Close(True)
827
828
829 def OnAbout(self, event):
830
831 msg = "This is the about dialog of the FoldPanelBarTest application.\n\n" + \
832 "Welcome To wxPython " + wx.VERSION_STRING + "!!"
833 dlg = wx.MessageDialog(self, msg, "About FoldPanelBarTest",
834 wx.OK | wx.ICON_INFORMATION)
835 dlg.ShowModal()
836 dlg.Destroy()
837
838
839 def OnCollapseMe(self, event):
840
841 item = self.pnl.GetFoldPanel(0)
842 self.pnl.Collapse(item)
843
844 def OnExpandMe(self, event):
845
846 self.pnl.Expand(self.pnl.GetFoldPanel(0))
847 self.pnl.Collapse(self.pnl.GetFoldPanel(1))
848
849
850 #---------------------------------------------------------------------------
851 #---------------------------------------------------------------------------
852
853 class TestPanel(wx.Panel):
854 def __init__(self, parent, log):
855 self.log = log
856 wx.Panel.__init__(self, parent, -1)
857
858 vsizer = wx.BoxSizer(wx.VERTICAL)
859 b = wx.Button(self, -1, "FoldPanelBar Extended Demo")
860 vsizer.Add(b, 0, wx.ALL, 5)
861 self.Bind(wx.EVT_BUTTON, self.OnButton1, b)
862
863 b = wx.Button(self, -1, "FoldPanelBar Collapsed Demo")
864 vsizer.Add(b, 0, wx.ALL, 5)
865 self.Bind(wx.EVT_BUTTON, self.OnButton2, b)
866
867 b = wx.Button(self, -1, "FoldPanelBar NotCollapsed Demo")
868 vsizer.Add(b, 0, wx.ALL, 5)
869 self.Bind(wx.EVT_BUTTON, self.OnButton3, b)
870
871 bdr = wx.BoxSizer()
872 bdr.Add(vsizer, 0, wx.ALL, 50)
873 self.SetSizer(bdr)
874
875 def OnButton1(self, evt):
876 frame = Extended(self, title="FoldPanelBar Extended Demo")
877 frame.Show()
878
879 def OnButton2(self, evt):
880 frame = Collapsed(self, title="FoldPanelBar Collapsed Demo")
881 frame.Show()
882
883 def OnButton3(self, evt):
884 frame = NotCollapsed(self, title="FoldPanelBar NotCollapsed Demo")
885 frame.Show()
886
887
888 #---------------------------------------------------------------------------
889
890
891 def runTest(frame, nb, log):
892 win = TestPanel(nb, log)
893 return win
894
895
896 #---------------------------------------------------------------------------
897
898
899 overview = fpb.__doc__
900
901
902 if __name__ == '__main__':
903 import sys,os
904 import run
905 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
906