3 import wx
.lib
.foldpanelbar
as fpb
6 # ----------------------------------------------------------------------------
7 # Extended Demo Implementation
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 # ----------------------------------------------------------------------------
14 #----------------------------------------------------------------------
15 # different icons for the collapsed/expanded states.
16 # Taken from standard Windows XP collapsed/expanded states.
17 #----------------------------------------------------------------------
19 def GetCollapsedIconData():
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'
40 def GetCollapsedIconBitmap():
41 return wx
.BitmapFromImage(GetCollapsedIconImage())
43 def GetCollapsedIconImage():
45 stream
= cStringIO
.StringIO(GetCollapsedIconData())
46 return wx
.ImageFromStream(stream
)
48 #----------------------------------------------------------------------
49 def GetExpandedIconData():
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\
72 def GetExpandedIconBitmap():
73 return wx
.BitmapFromImage(GetExpandedIconImage())
75 def GetExpandedIconImage():
77 stream
= cStringIO
.StringIO(GetExpandedIconData())
78 return wx
.ImageFromStream(stream
)
80 #----------------------------------------------------------------------
81 def GetMondrianData():
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'
91 def GetMondrianBitmap():
92 return wx
.BitmapFromImage(GetMondrianImage())
94 def GetMondrianImage():
96 stream
= cStringIO
.StringIO(GetMondrianData())
97 return wx
.ImageFromStream(stream
)
99 def GetMondrianIcon():
100 icon
= wx
.EmptyIcon()
101 icon
.CopyFromBitmap(GetMondrianBitmap())
104 # ----------------------------------------------------------------------------
105 # Beginning Of Extended Demo
106 # ----------------------------------------------------------------------------
108 class Extended(wx
.Frame
):
110 def __init__(self
, parent
, id=wx
.ID_ANY
, title
="", pos
=wx
.DefaultPosition
,
111 size
=(700,650), style
=wx
.DEFAULT_FRAME_STYLE
):
113 wx
.Frame
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
117 self
.SetIcon(GetMondrianIcon())
118 self
.SetMenuBar(self
.CreateMenuBar())
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)
125 self
._leftWindow
1 = wx
.SashLayoutWindow(self
, 101, wx
.DefaultPosition
,
126 wx
.Size(200, 1000), wx
.NO_BORDER |
127 wx
.SW_3D | wx
.CLIP_CHILDREN
)
129 self
._leftWindow
1.SetDefaultSize(wx
.Size(220, 1000))
130 self
._leftWindow
1.SetOrientation(wx
.LAYOUT_VERTICAL
)
131 self
._leftWindow
1.SetAlignment(wx
.LAYOUT_LEFT
)
132 self
._leftWindow
1.SetSashVisible(wx
.SASH_RIGHT
, True)
133 self
._leftWindow
1.SetExtraBorderSize(10)
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...",
143 self
.ID_WINDOW_TOP
= 100
144 self
.ID_WINDOW_LEFT1
= 101
145 self
.ID_WINDOW_RIGHT1
= 102
146 self
.ID_WINDOW_BOTTOM
= 103
148 self
._leftWindow
1.Bind(wx
.EVT_SASH_DRAGGED_RANGE
, self
.OnFoldPanelBarDrag
,
150 self
.Bind(wx
.EVT_SIZE
, self
.OnSize
)
151 self
.Bind(wx
.EVT_SCROLL
, self
.OnSlideColour
)
153 self
.ReCreateFoldPanel(0)
156 def OnSize(self
, event
):
158 wx
.LayoutAlgorithm().LayoutWindow(self
, self
.remainingSpace
)
162 def OnQuit(self
, event
):
167 def OnAbout(self
, event
):
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 Jorgen Bodde C++ demo implementation.\n\n" + \
175 "Welcome To wxPython " + wx
.VERSION_STRING
+ "!!"
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"))
184 def OnToggleWindow(self
, event
):
186 self
._leftWindow
1.Show(not self
._leftWindow
1.IsShown())
187 # Leaves bits of itself behind sometimes
188 wx
.LayoutAlgorithm().LayoutWindow(self
, self
.remainingSpace
)
189 self
.remainingSpace
.Refresh()
194 def OnFoldPanelBarDrag(self
, event
):
196 if event
.GetDragStatus() == wx
.SASH_STATUS_OUT_OF_RANGE
:
199 if event
.GetId() == self
.ID_WINDOW_LEFT1
:
200 self
._leftWindow
1.SetDefaultSize(wx
.Size(event
.GetDragRect().width
, 1000))
203 # Leaves bits of itself behind sometimes
204 wx
.LayoutAlgorithm().LayoutWindow(self
, self
.remainingSpace
)
205 self
.remainingSpace
.Refresh()
210 def ReCreateFoldPanel(self
, fpb_flags
):
212 # delete earlier panel
213 self
._leftWindow
1.DestroyChildren()
215 # recreate the foldpanelbar
217 self
._pnl
= fpb
.FoldPanelBar(self
._leftWindow
1, -1, wx
.DefaultPosition
,
218 wx
.Size(-1,-1), fpb
.FPB_DEFAULT_STYLE
, fpb_flags
)
220 Images
= wx
.ImageList(16,16)
221 Images
.Add(GetExpandedIconBitmap())
222 Images
.Add(GetCollapsedIconBitmap())
224 item
= self
._pnl
.AddFoldPanel("Caption Colours", collapsed
=False,
227 self
._pnl
.AddFoldPanelWindow(item
, wx
.StaticText(item
, -1, "Adjust The First Colour"),
228 fpb
.FPB_ALIGN_WIDTH
, 5, 20)
230 # RED color spin control
231 self
._rslider
1 = wx
.Slider(item
, -1, 0, 0, 255)
232 self
._pnl
.AddFoldPanelWindow(item
, self
._rslider
1, fpb
.FPB_ALIGN_WIDTH
, 2, 20)
234 # GREEN color spin control
235 self
._gslider
1 = wx
.Slider(item
, -1, 0, 0, 255)
236 self
._pnl
.AddFoldPanelWindow(item
, self
._gslider
1, fpb
.FPB_ALIGN_WIDTH
, 0, 20)
238 # BLUE color spin control
239 self
._bslider
1 = wx
.Slider(item
, -1, 0, 0, 255)
240 self
._pnl
.AddFoldPanelWindow(item
, self
._bslider
1, fpb
.FPB_ALIGN_WIDTH
, 0, 20)
242 self
._pnl
.AddFoldPanelSeparator(item
)
244 self
._pnl
.AddFoldPanelWindow(item
, wx
.StaticText(item
, -1, "Adjust The Second Colour"),
245 fpb
.FPB_ALIGN_WIDTH
, 5, 20)
247 # RED color spin control
248 self
._rslider
2 = wx
.Slider(item
, -1, 0, 0, 255)
249 self
._pnl
.AddFoldPanelWindow(item
, self
._rslider
2, fpb
.FPB_ALIGN_WIDTH
, 2, 20)
251 # GREEN color spin control
252 self
._gslider
2 = wx
.Slider(item
, -1, 0, 0, 255)
253 self
._pnl
.AddFoldPanelWindow(item
, self
._gslider
2, fpb
.FPB_ALIGN_WIDTH
, 0, 20)
255 # BLUE color spin control
256 self
._bslider
2 = wx
.Slider(item
, -1, 0, 0, 255)
257 self
._pnl
.AddFoldPanelWindow(item
, self
._bslider
2, fpb
.FPB_ALIGN_WIDTH
, 0, 20)
259 self
._pnl
.AddFoldPanelSeparator(item
)
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
)
265 # read back current gradients and set the sliders
266 # for the colour which is now taken as default
268 style
= self
._pnl
.GetCaptionStyle(item
)
269 col
= style
.GetFirstColour()
271 self
._rslider
1.SetValue(col
.Red())
272 self
._gslider
1.SetValue(col
.Green())
273 self
._bslider
1.SetValue(col
.Blue())
275 col
= style
.GetSecondColour()
276 self
._rslider
2.SetValue(col
.Red())
277 self
._gslider
2.SetValue(col
.Green())
278 self
._bslider
2.SetValue(col
.Blue())
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
283 item
= self
._pnl
.AddFoldPanel("Caption Style", False, foldIcons
=Images
)
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()
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)
295 currStyle
.SetValue(True)
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")
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
)
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)
313 self
._pnl
.AddFoldPanelSeparator(item
)
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)
319 # one more panel to finish it
321 cs
= fpb
.CaptionBarStyle()
322 cs
.SetCaptionStyle(fpb
.CAPTIONBAR_RECTANGLE
)
324 item
= self
._pnl
.AddFoldPanel("Misc Stuff", collapsed
=True, foldIcons
=Images
,
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)
334 button2
.Bind(wx
.EVT_BUTTON
, self
.OnCollapseMe
)
335 self
.radiocontrols
= [currStyle
, radio1
, radio2
, radio3
, radio4
]
337 self
._leftWindow
1.SizeWindows()
340 def OnCreateBottomStyle(self
, event
):
342 # recreate with style collapse to bottom, which means
343 # all panels that are collapsed are placed at the bottom,
346 if event
.IsChecked():
347 self
.GetMenuBar().Check(self
._singlestyle
, False)
348 self
.GetMenuBar().Check(self
._exclusivestyle
, False)
349 self
._flags
= self
._flags
& ~fpb
.FPB_SINGLE_FOLD
350 self
._flags
= self
._flags
& ~fpb
.FPB_EXCLUSIVE_FOLD
351 self
._flags
= self
._flags | fpb
.FPB_COLLAPSE_TO_BOTTOM
353 self
._flags
= self
._flags
& ~fpb
.FPB_COLLAPSE_TO_BOTTOM
355 self
.ReCreateFoldPanel(self
._flags
)
358 def OnCreateNormalStyle(self
, event
):
360 # recreate with style where only one panel at the time is
361 # allowed to be opened
363 if event
.IsChecked():
364 self
.GetMenuBar().Check(self
._bottomstyle
, False)
365 self
.GetMenuBar().Check(self
._exclusivestyle
, False)
366 self
._flags
= self
._flags
& ~fpb
.FPB_EXCLUSIVE_FOLD
367 self
._flags
= self
._flags
& ~fpb
.FPB_COLLAPSE_TO_BOTTOM
368 self
._flags
= self
._flags | fpb
.FPB_SINGLE_FOLD
370 self
._flags
= self
._flags
& ~fpb
.FPB_SINGLE_FOLD
372 self
.ReCreateFoldPanel(self
._flags
)
375 def OnCreateExclusiveStyle(self
, event
):
377 # recreate with style where only one panel at the time is
378 # allowed to be opened and the others are collapsed to bottom
380 if event
.IsChecked():
381 self
.GetMenuBar().Check(self
._singlestyle
, False)
382 self
.GetMenuBar().Check(self
._bottomstyle
, False)
383 self
._flags
= self
._flags
& ~fpb
.FPB_SINGLE_FOLD
384 self
._flags
= self
._flags
& ~fpb
.FPB_COLLAPSE_TO_BOTTOM
385 self
._flags
= self
._flags | fpb
.FPB_EXCLUSIVE_FOLD
387 self
._flags
= self
._flags
& ~fpb
.FPB_EXCLUSIVE_FOLD
389 self
.ReCreateFoldPanel(self
._flags
)
392 def OnCollapseMe(self
, event
):
394 for i
in range(0, self
._pnl
.GetCount()):
395 item
= self
._pnl
.GetFoldPanel(i
)
396 self
._pnl
.Collapse(item
)
399 def OnExpandMe(self
, event
):
401 col1
= wx
.Colour(self
._rslider
1.GetValue(), self
._gslider
1.GetValue(),
402 self
._bslider
1.GetValue())
403 col2
= wx
.Colour(self
._rslider
2.GetValue(), self
._gslider
2.GetValue(),
404 self
._bslider
2.GetValue())
406 style
= fpb
.CaptionBarStyle()
408 style
.SetFirstColour(col1
)
409 style
.SetSecondColour(col2
)
412 for items
in self
.radiocontrols
:
415 counter
= counter
+ 1
418 mystyle
= fpb
.CAPTIONBAR_GRADIENT_V
420 mystyle
= fpb
.CAPTIONBAR_GRADIENT_H
422 mystyle
= fpb
.CAPTIONBAR_SINGLE
424 mystyle
= fpb
.CAPTIONBAR_RECTANGLE
426 mystyle
= fpb
.CAPTIONBAR_FILLED_RECTANGLE
428 style
.SetCaptionStyle(mystyle
)
429 self
._pnl
.ApplyCaptionStyleAll(style
)
432 def OnSlideColour(self
, event
):
434 col1
= wx
.Colour(self
._rslider
1.GetValue(), self
._gslider
1.GetValue(),
435 self
._bslider
1.GetValue())
436 col2
= wx
.Colour(self
._rslider
2.GetValue(), self
._gslider
2.GetValue(),
437 self
._bslider
2.GetValue())
439 style
= fpb
.CaptionBarStyle()
442 for items
in self
.radiocontrols
:
446 counter
= counter
+ 1
449 mystyle
= fpb
.CAPTIONBAR_GRADIENT_V
451 mystyle
= fpb
.CAPTIONBAR_GRADIENT_H
453 mystyle
= fpb
.CAPTIONBAR_SINGLE
455 mystyle
= fpb
.CAPTIONBAR_RECTANGLE
457 mystyle
= fpb
.CAPTIONBAR_FILLED_RECTANGLE
459 style
.SetFirstColour(col1
)
460 style
.SetSecondColour(col2
)
461 style
.SetCaptionStyle(mystyle
)
463 item
= self
._pnl
.GetFoldPanel(0)
464 self
._pnl
.ApplyCaptionStyle(item
, style
)
467 def OnStyleChange(self
, event
):
469 style
= fpb
.CaptionBarStyle()
471 eventid
= event
.GetId()
473 if eventid
== self
.ID_USE_HGRADIENT
:
474 style
.SetCaptionStyle(fpb
.CAPTIONBAR_GRADIENT_H
)
476 elif eventid
== self
.ID_USE_VGRADIENT
:
477 style
.SetCaptionStyle(fpb
.CAPTIONBAR_GRADIENT_V
)
479 elif eventid
== self
.ID_USE_SINGLE
:
480 style
.SetCaptionStyle(fpb
.CAPTIONBAR_SINGLE
)
482 elif eventid
== self
.ID_USE_RECTANGLE
:
483 style
.SetCaptionStyle(fpb
.CAPTIONBAR_RECTANGLE
)
485 elif eventid
== self
.ID_USE_FILLED_RECTANGLE
:
486 style
.SetCaptionStyle(fpb
.CAPTIONBAR_FILLED_RECTANGLE
)
489 raise "ERROR: Undefined Style Selected For CaptionBar: " + repr(eventid
)
491 col1
= wx
.Colour(self
._rslider
1.GetValue(), self
._gslider
1.GetValue(),
492 self
._bslider
1.GetValue())
493 col2
= wx
.Colour(self
._rslider
2.GetValue(), self
._gslider
2.GetValue(),
494 self
._bslider
2.GetValue())
496 style
.SetFirstColour(col1
)
497 style
.SetSecondColour(col2
)
499 if self
._single
.GetValue():
500 item
= self
._pnl
.GetFoldPanel(1)
501 self
._pnl
.ApplyCaptionStyle(item
, style
)
503 self
._pnl
.ApplyCaptionStyleAll(style
)
506 def CreateMenuBar(self
, with_window
=False):
509 file_menu
= wx
.Menu()
511 FPBTEST_QUIT
= wx
.NewId()
512 FPBTEST_REFRESH
= wx
.NewId()
513 FPB_BOTTOM_FOLD
= wx
.NewId()
514 FPB_SINGLE_FOLD
= wx
.NewId()
515 FPB_EXCLUSIVE_FOLD
= wx
.NewId()
516 FPBTEST_TOGGLE_WINDOW
= wx
.NewId()
517 FPBTEST_ABOUT
= wx
.NewId()
519 file_menu
.Append(FPBTEST_QUIT
, "&Exit")
525 option_menu
= wx
.Menu()
526 option_menu
.Append(FPBTEST_REFRESH
, "&Refresh picture")
528 # make fold panel menu
531 fpb_menu
.AppendCheckItem(FPB_BOTTOM_FOLD
, "Create with &fpb.FPB_COLLAPSE_TO_BOTTOM")
534 fpb_menu
.AppendCheckItem(FPB_SINGLE_FOLD
, "Create with &fpb.FPB_SINGLE_FOLD")
537 fpb_menu
.AppendCheckItem(FPB_EXCLUSIVE_FOLD
, "Create with &fpb.FPB_EXCLUSIVE_FOLD")
539 fpb_menu
.AppendSeparator()
540 fpb_menu
.Append(FPBTEST_TOGGLE_WINDOW
, "&Toggle FoldPanelBar")
542 help_menu
= wx
.Menu()
543 help_menu
.Append(FPBTEST_ABOUT
, "&About")
545 menu_bar
= wx
.MenuBar()
547 menu_bar
.Append(file_menu
, "&File")
548 menu_bar
.Append(fpb_menu
, "&FoldPanel")
551 menu_bar
.Append(option_menu
, "&Options")
553 menu_bar
.Append(help_menu
, "&Help")
555 self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, id=FPBTEST_ABOUT
)
556 self
.Bind(wx
.EVT_MENU
, self
.OnQuit
, id=FPBTEST_QUIT
)
557 self
.Bind(wx
.EVT_MENU
, self
.OnToggleWindow
, id=FPBTEST_TOGGLE_WINDOW
)
558 self
.Bind(wx
.EVT_MENU
, self
.OnCreateBottomStyle
, id=FPB_BOTTOM_FOLD
)
559 self
.Bind(wx
.EVT_MENU
, self
.OnCreateNormalStyle
, id=FPB_SINGLE_FOLD
)
560 self
.Bind(wx
.EVT_MENU
, self
.OnCreateExclusiveStyle
, id=FPB_EXCLUSIVE_FOLD
)
562 self
._bottomstyle
= FPB_BOTTOM_FOLD
563 self
._singlestyle
= FPB_SINGLE_FOLD
564 self
._exclusivestyle
= FPB_EXCLUSIVE_FOLD
569 # ----------------------------------------------------------------------------
570 # Collapsed Demo Implementation
571 # ----------------------------------------------------------------------------
573 class FoldTestPanel(wx
.Panel
):
575 def __init__(self
, parent
, id, pos
=wx
.DefaultPosition
, size
=wx
.DefaultSize
,
576 style
=wx
.NO_BORDER | wx
.TAB_TRAVERSAL
):
578 wx
.Panel
.__init
__(self
, parent
, id, pos
, size
, style
)
580 self
.CreateControls()
581 self
.GetSizer().Fit(self
)
582 self
.GetSizer().SetSizeHints(self
)
583 self
.GetSizer().Layout()
585 self
.Bind(fpb
.EVT_CAPTIONBAR
, self
.OnPressCaption
)
588 def OnPressCaption(self
, event
):
591 def CreateControls(self
):
593 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
596 subpanel
= wx
.Panel(self
, wx
.ID_ANY
, wx
.DefaultPosition
, wx
.DefaultSize
,
597 wx
.NO_BORDER | wx
.TAB_TRAVERSAL
)
598 sizer
.Add(subpanel
, 1, wx
.GROW | wx
.ADJUST_MINSIZE
, 5)
600 subsizer
= wx
.BoxSizer(wx
.VERTICAL
)
601 subpanel
.SetSizer(subsizer
)
602 itemstrings
= ["One", "Two", "Three"]
604 item5
= wx
.Choice(subpanel
, wx
.ID_ANY
, wx
.DefaultPosition
, wx
.DefaultSize
,
607 subsizer
.Add(item5
, 0, wx
.GROW | wx
.ALL
, 5)
609 item6
= wx
.TextCtrl(subpanel
, wx
.ID_ANY
, "", wx
.DefaultPosition
, wx
.DefaultSize
,
611 subsizer
.Add(item6
, 1, wx
.GROW | wx
.ALL
, 5)
613 item7
= wx
.RadioButton(subpanel
, wx
.ID_ANY
, "I Like This", wx
.DefaultPosition
,
616 subsizer
.Add(item7
, 0, wx
.ALIGN_LEFT | wx
.ALL
, 5)
618 item8
= wx
.RadioButton(subpanel
, wx
.ID_ANY
, "I Hate It", wx
.DefaultPosition
,
620 item8
.SetValue(False)
621 subsizer
.Add(item8
, 0, wx
.ALIGN_LEFT | wx
.ALL
, 5)
624 # ----------------------------------------------------------------------------
626 class Collapsed(wx
.Frame
):
628 def __init__(self
, parent
, id=wx
.ID_ANY
, title
="", pos
=wx
.DefaultPosition
,
629 size
=(400,300), style
=wx
.DEFAULT_FRAME_STYLE
):
631 wx
.Frame
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
633 self
.SetIcon(GetMondrianIcon())
634 self
.SetMenuBar(self
.CreateMenuBar())
636 self
.statusbar
= self
.CreateStatusBar(2, wx
.ST_SIZEGRIP
)
637 self
.statusbar
.SetStatusWidths([-4, -3])
638 self
.statusbar
.SetStatusText("Andrea Gavana @ 23 Mar 2005", 0)
639 self
.statusbar
.SetStatusText("Welcome to wxPython!", 1)
644 def CreateFoldBar(self
, vertical
=True):
647 self
.SetSize((500,600))
649 self
.SetSize((700,300))
651 newstyle
= (vertical
and [fpb
.FPB_VERTICAL
] or [fpb
.FPB_HORIZONTAL
])[0]
653 bar
= fpb
.FoldPanelBar(self
, wx
.ID_ANY
, wx
.DefaultPosition
, wx
.DefaultSize
,
654 fpb
.FPB_DEFAULT_STYLE | newstyle
, fpb
.FPB_COLLAPSE_TO_BOTTOM
)
656 item
= bar
.AddFoldPanel("Test me", collapsed
=False)
657 button1
= wx
.Button(item
, wx
.ID_ANY
, "Collapse Me")
658 button1
.Bind(wx
.EVT_BUTTON
, self
.OnCollapseMe
)
660 bar
.AddFoldPanelWindow(item
, button1
, fpb
.FPB_ALIGN_LEFT
)
662 item
= bar
.AddFoldPanel("Test me too!", collapsed
=True)
664 button2
= wx
.Button(item
, wx
.ID_ANY
, "Expand First One")
665 button2
.Bind(wx
.EVT_BUTTON
, self
.OnExpandMe
)
667 bar
.AddFoldPanelWindow(item
, button2
)
668 bar
.AddFoldPanelSeparator(item
)
670 newfoldpanel
= FoldTestPanel(item
, wx
.ID_ANY
)
671 bar
.AddFoldPanelWindow(item
, newfoldpanel
)
673 bar
.AddFoldPanelSeparator(item
)
675 bar
.AddFoldPanelWindow(item
, wx
.TextCtrl(item
, wx
.ID_ANY
, "Comment"),
676 fpb
.FPB_ALIGN_LEFT
, fpb
.FPB_DEFAULT_SPACING
, 20)
678 item
= bar
.AddFoldPanel("Some Opinions ...", collapsed
=False)
679 bar
.AddFoldPanelWindow(item
, wx
.CheckBox(item
, wx
.ID_ANY
, "I Like This"))
682 # do not add this for horizontal for better presentation
683 bar
.AddFoldPanelWindow(item
, wx
.CheckBox(item
, wx
.ID_ANY
, "And also this"))
684 bar
.AddFoldPanelWindow(item
, wx
.CheckBox(item
, wx
.ID_ANY
, "And gimme this too"))
686 bar
.AddFoldPanelSeparator(item
)
688 bar
.AddFoldPanelWindow(item
, wx
.CheckBox(item
, wx
.ID_ANY
, "Check this too if you like"))
691 # do not add this for horizontal for better presentation
692 bar
.AddFoldPanelWindow(item
, wx
.CheckBox(item
, wx
.ID_ANY
, "What about this"))
694 item
= bar
.AddFoldPanel("Choose one ...", collapsed
=False)
695 bar
.AddFoldPanelWindow(item
, wx
.StaticText(item
, wx
.ID_ANY
, "Enter your comment"))
696 bar
.AddFoldPanelWindow(item
, wx
.TextCtrl(item
, wx
.ID_ANY
, "Comment"),
697 fpb
.FPB_ALIGN_WIDTH
, fpb
.FPB_DEFAULT_SPACING
, 20)
699 if hasattr(self
, "pnl"):
704 size
= self
.GetClientSize()
705 self
.pnl
.SetDimensions(0, 0, size
.GetWidth(), size
.GetHeight())
708 def CreateMenuBar(self
):
710 FoldPanelBarTest_Quit
= wx
.NewId()
711 FoldPanelBarTest_About
= wx
.NewId()
712 FoldPanelBarTest_Horizontal
= wx
.NewId()
713 FoldPanelBarTest_Vertical
= wx
.NewId()
716 menuFile
.Append(FoldPanelBarTest_Horizontal
, "&Horizontal\tAlt-H")
717 menuFile
.Append(FoldPanelBarTest_Vertical
, "&Vertical\tAlt-V")
718 menuFile
.AppendSeparator()
719 menuFile
.Append(FoldPanelBarTest_Quit
, "E&xit\tAlt-X", "Quit This Program")
722 helpMenu
.Append(FoldPanelBarTest_About
, "&About...\tF1", "Show About Dialog")
724 self
.FoldPanelBarTest_Vertical
= FoldPanelBarTest_Vertical
725 self
.FoldPanelBarTest_Horizontal
= FoldPanelBarTest_Horizontal
727 self
.Bind(wx
.EVT_MENU
, self
.OnQuit
, id=FoldPanelBarTest_Quit
)
728 self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, id=FoldPanelBarTest_About
)
729 self
.Bind(wx
.EVT_MENU
, self
.OnOrientation
, id=FoldPanelBarTest_Horizontal
)
730 self
.Bind(wx
.EVT_MENU
, self
.OnOrientation
, id=FoldPanelBarTest_Vertical
)
733 value
.Append(menuFile
, "&File")
734 value
.Append(helpMenu
, "&Help")
739 def OnOrientation(self
, event
):
740 self
.CreateFoldBar(event
.GetId() == self
.FoldPanelBarTest_Vertical
)
743 def OnQuit(self
, event
):
744 # True is to force the frame to close
748 def OnAbout(self
, event
):
750 msg
= "This is the about dialog of the FoldPanelBarTest application.\n\n" + \
751 "Welcome To wxPython " + wx
.VERSION_STRING
+ "!!"
752 dlg
= wx
.MessageDialog(self
, msg
, "About FoldPanelBarTest",
753 wx
.OK | wx
.ICON_INFORMATION
)
758 def OnCollapseMe(self
, event
):
760 item
= self
.pnl
.GetFoldPanel(0)
761 self
.pnl
.Collapse(item
)
763 def OnExpandMe(self
, event
):
765 self
.pnl
.Expand(self
.pnl
.GetFoldPanel(0))
766 self
.pnl
.Collapse(self
.pnl
.GetFoldPanel(1))
770 # ----------------------------------------------------------------------------
771 # NotCollapsed Implementation
772 # ----------------------------------------------------------------------------
774 class NotCollapsed(wx
.Frame
):
775 def __init__(self
, parent
, id=wx
.ID_ANY
, title
="", pos
=wx
.DefaultPosition
,
776 size
=(400,300), style
=wx
.DEFAULT_FRAME_STYLE
):
778 wx
.Frame
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
780 self
.SetIcon(GetMondrianIcon())
781 self
.SetMenuBar(self
.CreateMenuBar())
783 self
.statusbar
= self
.CreateStatusBar(2, wx
.ST_SIZEGRIP
)
784 self
.statusbar
.SetStatusWidths([-4, -3])
785 self
.statusbar
.SetStatusText("Andrea Gavana @ 23 Mar 2005", 0)
786 self
.statusbar
.SetStatusText("Welcome to wxPython!", 1)
788 pnl
= fpb
.FoldPanelBar(self
, wx
.ID_ANY
, wx
.DefaultPosition
, wx
.DefaultSize
,
789 fpb
.FPB_DEFAULT_STYLE | fpb
.FPB_VERTICAL
)
791 item
= pnl
.AddFoldPanel("Test Me", collapsed
=False)
793 button1
= wx
.Button(item
, wx
.ID_ANY
, "Collapse Me")
795 pnl
.AddFoldPanelWindow(item
, button1
, fpb
.FPB_ALIGN_LEFT
)
796 pnl
.AddFoldPanelSeparator(item
)
798 button1
.Bind(wx
.EVT_BUTTON
, self
.OnCollapseMe
)
800 item
= pnl
.AddFoldPanel("Test Me Too!", collapsed
=True)
801 button2
= wx
.Button(item
, wx
.ID_ANY
, "Expand First One")
802 pnl
.AddFoldPanelWindow(item
, button2
, fpb
.FPB_ALIGN_LEFT
)
803 pnl
.AddFoldPanelSeparator(item
)
805 button2
.Bind(wx
.EVT_BUTTON
, self
.OnExpandMe
)
807 newfoldpanel
= FoldTestPanel(item
, wx
.ID_ANY
)
808 pnl
.AddFoldPanelWindow(item
, newfoldpanel
)
810 pnl
.AddFoldPanelSeparator(item
)
812 pnl
.AddFoldPanelWindow(item
, wx
.TextCtrl(item
, wx
.ID_ANY
, "Comment"),
813 fpb
.FPB_ALIGN_LEFT
, fpb
.FPB_DEFAULT_SPACING
, 20)
815 item
= pnl
.AddFoldPanel("Some Opinions ...", collapsed
=False)
816 pnl
.AddFoldPanelWindow(item
, wx
.CheckBox(item
, wx
.ID_ANY
, "I Like This"))
817 pnl
.AddFoldPanelWindow(item
, wx
.CheckBox(item
, wx
.ID_ANY
, "And Also This"))
818 pnl
.AddFoldPanelWindow(item
, wx
.CheckBox(item
, wx
.ID_ANY
, "And Gimme This Too"))
820 pnl
.AddFoldPanelSeparator(item
)
822 pnl
.AddFoldPanelWindow(item
, wx
.CheckBox(item
, wx
.ID_ANY
, "Check This Too If You Like"))
823 pnl
.AddFoldPanelWindow(item
, wx
.CheckBox(item
, wx
.ID_ANY
, "What About This"))
825 item
= pnl
.AddFoldPanel("Choose One ...", collapsed
=False)
826 pnl
.AddFoldPanelWindow(item
, wx
.StaticText(item
, wx
.ID_ANY
, "Enter Your Comment"))
827 pnl
.AddFoldPanelWindow(item
, wx
.TextCtrl(item
, wx
.ID_ANY
, "Comment"),
828 fpb
.FPB_ALIGN_WIDTH
, fpb
.FPB_DEFAULT_SPACING
, 20, 20)
832 def CreateMenuBar(self
):
834 FoldPanelBarTest_Quit
= wx
.NewId()
835 FoldPanelBarTest_About
= wx
.NewId()
838 menuFile
.Append(FoldPanelBarTest_Quit
, "E&xit\tAlt-X", "Quit This Program")
841 helpMenu
.Append(FoldPanelBarTest_About
, "&About...\tF1", "Show About Dialog")
843 self
.Bind(wx
.EVT_MENU
, self
.OnQuit
, id=FoldPanelBarTest_Quit
)
844 self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, id=FoldPanelBarTest_About
)
847 value
.Append(menuFile
, "&File")
848 value
.Append(helpMenu
, "&Help")
855 def OnQuit(self
, event
):
857 # True is to force the frame to close
861 def OnAbout(self
, event
):
863 msg
= "This is the about dialog of the FoldPanelBarTest application.\n\n" + \
864 "Welcome To wxPython " + wx
.VERSION_STRING
+ "!!"
865 dlg
= wx
.MessageDialog(self
, msg
, "About FoldPanelBarTest",
866 wx
.OK | wx
.ICON_INFORMATION
)
871 def OnCollapseMe(self
, event
):
873 item
= self
.pnl
.GetFoldPanel(0)
874 self
.pnl
.Collapse(item
)
876 def OnExpandMe(self
, event
):
878 self
.pnl
.Expand(self
.pnl
.GetFoldPanel(0))
879 self
.pnl
.Collapse(self
.pnl
.GetFoldPanel(1))
882 #---------------------------------------------------------------------------
883 #---------------------------------------------------------------------------
885 class TestPanel(wx
.Panel
):
886 def __init__(self
, parent
, log
):
888 wx
.Panel
.__init
__(self
, parent
, -1)
890 vsizer
= wx
.BoxSizer(wx
.VERTICAL
)
891 b
= wx
.Button(self
, -1, "FoldPanelBar Extended Demo")
892 vsizer
.Add(b
, 0, wx
.ALL
, 5)
893 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton1
, b
)
895 b
= wx
.Button(self
, -1, "FoldPanelBar Collapsed Demo")
896 vsizer
.Add(b
, 0, wx
.ALL
, 5)
897 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton2
, b
)
899 b
= wx
.Button(self
, -1, "FoldPanelBar NotCollapsed Demo")
900 vsizer
.Add(b
, 0, wx
.ALL
, 5)
901 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton3
, b
)
904 bdr
.Add(vsizer
, 0, wx
.ALL
, 50)
907 def OnButton1(self
, evt
):
908 frame
= Extended(self
, title
="FoldPanelBar Extended Demo")
911 def OnButton2(self
, evt
):
912 frame
= Collapsed(self
, title
="FoldPanelBar Collapsed Demo")
915 def OnButton3(self
, evt
):
916 frame
= NotCollapsed(self
, title
="FoldPanelBar NotCollapsed Demo")
920 #---------------------------------------------------------------------------
923 def runTest(frame
, nb
, log
):
924 win
= TestPanel(nb
, log
)
928 #---------------------------------------------------------------------------
931 overview
= fpb
.__doc
__
934 if __name__
== '__main__':
937 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])