2 import wx
.lib
.flatnotebook
as fnb
7 #----------------------------------------------------------------------
10 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\
11 \x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID\
12 ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\
13 o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\
14 \xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\
15 \x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\
16 \x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82'
19 def GetMondrianBitmap():
20 return wx
.BitmapFromImage(GetMondrianImage())
23 def GetMondrianImage():
25 stream
= cStringIO
.StringIO(GetMondrianData())
26 return wx
.ImageFromStream(stream
)
29 def GetMondrianIcon():
31 icon
.CopyFromBitmap(GetMondrianBitmap())
33 #----------------------------------------------------------------------
36 MENU_EDIT_DELETE_ALL
= wx
.NewId()
37 MENU_EDIT_ADD_PAGE
= wx
.NewId()
38 MENU_EDIT_DELETE_PAGE
= wx
.NewId()
39 MENU_EDIT_SET_SELECTION
= wx
.NewId()
40 MENU_EDIT_ADVANCE_SELECTION_FWD
= wx
.NewId()
41 MENU_EDIT_ADVANCE_SELECTION_BACK
= wx
.NewId()
42 MENU_SET_ALL_TABS_SHAPE_ANGLE
= wx
.NewId()
43 MENU_SHOW_IMAGES
= wx
.NewId()
44 MENU_USE_VC71_STYLE
= wx
.NewId()
45 MENU_USE_DEFAULT_STYLE
= wx
.NewId()
46 MENU_USE_FANCY_STYLE
= wx
.NewId()
47 MENU_SELECT_GRADIENT_COLOR_FROM
= wx
.NewId()
48 MENU_SELECT_GRADIENT_COLOR_TO
= wx
.NewId()
49 MENU_SELECT_GRADIENT_COLOR_BORDER
= wx
.NewId()
50 MENU_SET_PAGE_IMAGE_INDEX
= wx
.NewId()
51 MENU_HIDE_X
= wx
.NewId()
52 MENU_HIDE_NAV_BUTTONS
= wx
.NewId()
53 MENU_USE_MOUSE_MIDDLE_BTN
= wx
.NewId()
54 MENU_DRAW_BORDER
= wx
.NewId()
55 MENU_USE_BOTTOM_TABS
= wx
.NewId()
56 MENU_ENABLE_TAB
= wx
.NewId()
57 MENU_DISABLE_TAB
= wx
.NewId()
58 MENU_ENABLE_DRAG_N_DROP
= wx
.NewId()
59 MENU_DCLICK_CLOSES_TAB
= wx
.NewId()
60 MENU_USE_VC8_STYLE
= wx
.NewId()
62 MENU_SET_ACTIVE_TEXT_COLOR
= wx
.NewId()
63 MENU_DRAW_TAB_X
= wx
.NewId()
64 MENU_SET_ACTIVE_TAB_COLOR
= wx
.NewId()
65 MENU_SET_TAB_AREA_COLOR
= wx
.NewId()
66 MENU_SELECT_NONACTIVE_TEXT_COLOR
= wx
.NewId()
67 MENU_GRADIENT_BACKGROUND
= wx
.NewId()
68 MENU_COLORFUL_TABS
= wx
.NewId()
69 MENU_SMART_TABS
= wx
.NewId()
70 MENU_USE_DROP_ARROW_BUTTON
= wx
.NewId()
71 MENU_ALLOW_FOREIGN_DND
= wx
.NewId()
74 class FlatNotebookDemo(wx
.Frame
):
76 def __init__(self
, parent
, log
):
78 wx
.Frame
.__init
__(self
, parent
, title
="FlatNotebook Demo", size
=(800,600))
81 self
._bShowImages
= False
82 self
._bVCStyle
= False
83 self
._newPageCounter
= 0
85 self
._ImageList
= wx
.ImageList(16, 16)
86 self
._ImageList
.Add(images
.get_book_redBitmap())
87 self
._ImageList
.Add(images
.get_book_greenBitmap())
88 self
._ImageList
.Add(images
.get_book_blueBitmap())
90 self
.statusbar
= self
.CreateStatusBar(2, wx
.ST_SIZEGRIP
)
91 self
.statusbar
.SetStatusWidths([-2, -1])
93 statusbar_fields
= [("FlatNotebook wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
94 ("Welcome To wxPython!")]
96 for i
in range(len(statusbar_fields
)):
97 self
.statusbar
.SetStatusText(statusbar_fields
[i
], i
)
99 self
.SetIcon(GetMondrianIcon())
101 self
.CreateRightClickMenu()
104 self
.Bind(fnb
.EVT_FLATNOTEBOOK_PAGE_CHANGING
, self
.OnPageChanging
)
105 self
.Bind(fnb
.EVT_FLATNOTEBOOK_PAGE_CHANGED
, self
.OnPageChanged
)
106 self
.Bind(fnb
.EVT_FLATNOTEBOOK_PAGE_CLOSING
, self
.OnPageClosing
)
108 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnDropDownArrowUI
, id=MENU_USE_DROP_ARROW_BUTTON
)
109 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnHideNavigationButtonsUI
, id=MENU_HIDE_NAV_BUTTONS
)
110 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnAllowForeignDndUI
, id=MENU_ALLOW_FOREIGN_DND
)
113 def CreateMenuBar(self
):
115 self
._menuBar
= wx
.MenuBar(wx
.MB_DOCKABLE
)
116 self
._fileMenu
= wx
.Menu()
117 self
._editMenu
= wx
.Menu()
118 self
._visualMenu
= wx
.Menu()
120 item
= wx
.MenuItem(self
._fileMenu
, wx
.ID_ANY
, "&Close\tCtrl-Q", "Close demo window")
121 self
.Bind(wx
.EVT_MENU
, self
.OnQuit
, item
)
122 self
._fileMenu
.AppendItem(item
)
124 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_ADD_PAGE
, "New Page\tCtrl+N", "Add New Page")
125 self
.Bind(wx
.EVT_MENU
, self
.OnAddPage
, item
)
126 self
._editMenu
.AppendItem(item
)
128 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_DELETE_PAGE
, "Delete Page\tCtrl+F4", "Delete Page")
129 self
.Bind(wx
.EVT_MENU
, self
.OnDeletePage
, item
)
130 self
._editMenu
.AppendItem(item
)
132 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_DELETE_ALL
, "Delete All Pages", "Delete All Pages")
133 self
.Bind(wx
.EVT_MENU
, self
.OnDeleteAll
, item
)
134 self
._editMenu
.AppendItem(item
)
136 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_SET_SELECTION
, "Set Selection", "Set Selection")
137 self
.Bind(wx
.EVT_MENU
, self
.OnSetSelection
, item
)
138 self
._editMenu
.AppendItem(item
)
140 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_ADVANCE_SELECTION_FWD
, "Advance Selection Forward",
141 "Advance Selection Forward")
142 self
.Bind(wx
.EVT_MENU
, self
.OnAdvanceSelectionFwd
, item
)
143 self
._editMenu
.AppendItem(item
)
145 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_ADVANCE_SELECTION_BACK
, "Advance Selection Backward",
146 "Advance Selection Backward")
147 self
.Bind(wx
.EVT_MENU
, self
.OnAdvanceSelectionBack
, item
)
148 self
._editMenu
.AppendItem(item
)
150 item
= wx
.MenuItem(self
._editMenu
, MENU_SET_ALL_TABS_SHAPE_ANGLE
, "Set an inclination of tab header borders",
151 "Set the shape of tab header")
152 self
.Bind(wx
.EVT_MENU
, self
.OnSetAllPagesShapeAngle
, item
)
153 self
._visualMenu
.AppendItem(item
)
155 item
= wx
.MenuItem(self
._editMenu
, MENU_SET_PAGE_IMAGE_INDEX
, "Set image index of selected page",
157 self
.Bind(wx
.EVT_MENU
, self
.OnSetPageImage
, item
)
158 self
._editMenu
.AppendItem(item
)
160 item
= wx
.MenuItem(self
._editMenu
, MENU_SHOW_IMAGES
, "Show Images", "Show Images", wx
.ITEM_CHECK
)
161 self
.Bind(wx
.EVT_MENU
, self
.OnShowImages
, item
)
162 self
._editMenu
.AppendItem(item
)
164 styleMenu
= wx
.Menu()
165 item
= wx
.MenuItem(styleMenu
, MENU_USE_DEFAULT_STYLE
, "Use Default Style", "Use VC71 Style", wx
.ITEM_RADIO
)
166 self
.Bind(wx
.EVT_MENU
, self
.OnDefaultStyle
, item
)
167 styleMenu
.AppendItem(item
)
169 item
= wx
.MenuItem(styleMenu
, MENU_USE_VC71_STYLE
, "Use VC71 Style", "Use VC71 Style", wx
.ITEM_RADIO
)
170 self
.Bind(wx
.EVT_MENU
, self
.OnVC71Style
, item
)
171 styleMenu
.AppendItem(item
)
173 item
= wx
.MenuItem(styleMenu
, MENU_USE_VC8_STYLE
, "Use VC8 Style", "Use VC8 Style", wx
.ITEM_RADIO
)
174 self
.Bind(wx
.EVT_MENU
, self
.OnVC8Style
, item
)
175 styleMenu
.AppendItem(item
)
177 item
= wx
.MenuItem(styleMenu
, MENU_USE_FANCY_STYLE
, "Use Fancy Style", "Use Fancy Style", wx
.ITEM_RADIO
)
178 self
.Bind(wx
.EVT_MENU
, self
.OnFancyStyle
, item
)
179 styleMenu
.AppendItem(item
)
181 self
._visualMenu
.AppendMenu(wx
.ID_ANY
, "Tabs Style", styleMenu
)
183 item
= wx
.MenuItem(self
._visualMenu
, MENU_SELECT_GRADIENT_COLOR_FROM
, "Select fancy tab style 'from' color",
184 "Select fancy tab style 'from' color")
185 self
._visualMenu
.AppendItem(item
)
187 item
= wx
.MenuItem(self
._visualMenu
, MENU_SELECT_GRADIENT_COLOR_TO
, "Select fancy tab style 'to' color",
188 "Select fancy tab style 'to' color")
189 self
._visualMenu
.AppendItem(item
)
191 item
= wx
.MenuItem(self
._visualMenu
, MENU_SELECT_GRADIENT_COLOR_BORDER
, "Select fancy tab style 'border' color",
192 "Select fancy tab style 'border' color")
193 self
._visualMenu
.AppendItem(item
)
195 self
._editMenu
.AppendSeparator()
197 self
.Bind(wx
.EVT_MENU_RANGE
, self
.OnSelectColor
, id=MENU_SELECT_GRADIENT_COLOR_FROM
,
198 id2
=MENU_SELECT_GRADIENT_COLOR_BORDER
)
200 item
= wx
.MenuItem(self
._editMenu
, MENU_HIDE_NAV_BUTTONS
, "Hide Navigation Buttons",
201 "Hide Navigation Buttons", wx
.ITEM_CHECK
)
202 self
._editMenu
.AppendItem(item
)
204 item
= wx
.MenuItem(self
._editMenu
, MENU_HIDE_X
, "Hide X Button", "Hide X Button", wx
.ITEM_CHECK
)
205 self
._editMenu
.AppendItem(item
)
207 item
= wx
.MenuItem(self
._editMenu
, MENU_SMART_TABS
, "Smart tabbing", "Smart tabbing", wx
.ITEM_CHECK
)
208 self
._editMenu
.AppendItem(item
)
209 self
.Bind(wx
.EVT_MENU
, self
.OnSmartTabs
, item
)
212 item
= wx
.MenuItem(self
._editMenu
, MENU_USE_DROP_ARROW_BUTTON
, "Use drop down button for tab navigation",
213 "Use drop down arrow for quick tab navigation", wx
.ITEM_CHECK
)
214 self
._editMenu
.AppendItem(item
)
215 self
.Bind(wx
.EVT_MENU
, self
.OnDropDownArrow
, item
)
217 self
._editMenu
.AppendSeparator()
219 item
= wx
.MenuItem(self
._editMenu
, MENU_USE_MOUSE_MIDDLE_BTN
, "Use Mouse Middle Button as 'X' button",
220 "Use Mouse Middle Button as 'X' button", wx
.ITEM_CHECK
)
221 self
._editMenu
.AppendItem(item
)
223 item
= wx
.MenuItem(self
._editMenu
, MENU_DCLICK_CLOSES_TAB
, "Mouse double click closes tab",
224 "Mouse double click closes tab", wx
.ITEM_CHECK
)
225 self
.Bind(wx
.EVT_MENU
, self
.OnDClickCloseTab
, item
)
226 self
._editMenu
.AppendItem(item
)
229 self
._editMenu
.AppendSeparator()
231 item
= wx
.MenuItem(self
._editMenu
, MENU_USE_BOTTOM_TABS
, "Use Bottoms Tabs", "Use Bottoms Tabs",
233 self
._editMenu
.AppendItem(item
)
235 self
.Bind(wx
.EVT_MENU_RANGE
, self
.OnStyle
, id=MENU_HIDE_X
, id2
=MENU_USE_BOTTOM_TABS
)
237 item
= wx
.MenuItem(self
._editMenu
, MENU_ENABLE_TAB
, "Enable Tab", "Enable Tab")
238 self
.Bind(wx
.EVT_MENU
, self
.OnEnableTab
, item
)
239 self
._editMenu
.AppendItem(item
)
241 item
= wx
.MenuItem(self
._editMenu
, MENU_DISABLE_TAB
, "Disable Tab", "Disable Tab")
242 self
.Bind(wx
.EVT_MENU
, self
.OnDisableTab
, item
)
243 self
._editMenu
.AppendItem(item
)
245 item
= wx
.MenuItem(self
._editMenu
, MENU_ENABLE_DRAG_N_DROP
, "Enable Drag And Drop of Tabs",
246 "Enable Drag And Drop of Tabs", wx
.ITEM_CHECK
)
247 self
.Bind(wx
.EVT_MENU
, self
.OnEnableDrag
, item
)
248 self
._editMenu
.AppendItem(item
)
251 item
= wx
.MenuItem(self
._editMenu
, MENU_ALLOW_FOREIGN_DND
, "Enable Drag And Drop of Tabs from foreign notebooks",
252 "Enable Drag And Drop of Tabs from foreign notebooks", wx
.ITEM_CHECK
)
253 self
.Bind(wx
.EVT_MENU
, self
.OnAllowForeignDnd
, item
)
254 self
._editMenu
.AppendItem(item
)
257 item
= wx
.MenuItem(self
._visualMenu
, MENU_DRAW_BORDER
, "Draw Border around tab area",
258 "Draw Border around tab area", wx
.ITEM_CHECK
)
259 self
.Bind(wx
.EVT_MENU
, self
.OnStyle
, item
)
260 self
._visualMenu
.AppendItem(item
)
263 item
= wx
.MenuItem(self
._visualMenu
, MENU_DRAW_TAB_X
, "Draw X button On Active Tab",
264 "Draw X button On Active Tab", wx
.ITEM_CHECK
)
265 self
.Bind(wx
.EVT_MENU
, self
.OnDrawTabX
, item
)
266 self
._visualMenu
.AppendItem(item
)
268 item
= wx
.MenuItem(self
._visualMenu
, MENU_SET_ACTIVE_TAB_COLOR
, "Select Active Tab Color",
269 "Select Active Tab Color")
270 self
.Bind(wx
.EVT_MENU
, self
.OnSelectColor
, item
)
271 self
._visualMenu
.AppendItem(item
)
273 item
= wx
.MenuItem(self
._visualMenu
, MENU_SET_TAB_AREA_COLOR
, "Select Tab Area Color",
274 "Select Tab Area Color")
275 self
.Bind(wx
.EVT_MENU
, self
.OnSelectColor
, item
)
276 self
._visualMenu
.AppendItem(item
)
278 item
= wx
.MenuItem(self
._visualMenu
, MENU_SET_ACTIVE_TEXT_COLOR
, "Select active tab text color",
279 "Select active tab text color")
280 self
.Bind(wx
.EVT_MENU
, self
.OnSelectColor
, item
)
281 self
._visualMenu
.AppendItem(item
)
283 item
= wx
.MenuItem(self
._visualMenu
, MENU_SELECT_NONACTIVE_TEXT_COLOR
,
284 "Select NON-active tab text color", "Select NON-active tab text color")
285 self
.Bind(wx
.EVT_MENU
, self
.OnSelectColor
, item
)
286 self
._visualMenu
.AppendItem(item
)
288 item
= wx
.MenuItem(self
._visualMenu
, MENU_GRADIENT_BACKGROUND
, "Use Gradient Coloring for tab area",
289 "Use Gradient Coloring for tab area", wx
.ITEM_CHECK
)
290 self
.Bind(wx
.EVT_MENU
, self
.OnGradientBack
, item
)
291 self
._visualMenu
.AppendItem(item
)
294 item
= wx
.MenuItem(self
._visualMenu
, MENU_COLORFUL_TABS
, "Colorful tabs", "Colorful tabs", wx
.ITEM_CHECK
)
295 self
.Bind(wx
.EVT_MENU
, self
.OnColorfulTabs
, item
)
296 self
._visualMenu
.AppendItem(item
)
299 help_menu
= wx
.Menu()
300 item
= wx
.MenuItem(help_menu
, wx
.ID_ANY
, "About...", "Shows The About Dialog")
301 self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, item
)
302 help_menu
.AppendItem(item
)
304 self
._menuBar
.Append(self
._fileMenu
, "&File")
305 self
._menuBar
.Append(self
._editMenu
, "&Edit")
306 self
._menuBar
.Append(self
._visualMenu
, "&Tab Appearance")
308 self
._menuBar
.Append(help_menu
, "&Help")
310 self
.SetMenuBar(self
._menuBar
)
313 def CreateRightClickMenu(self
):
315 self
._rmenu
= wx
.Menu()
316 item
= wx
.MenuItem(self
._rmenu
, MENU_EDIT_DELETE_PAGE
, "Close Tab\tCtrl+F4", "Close Tab")
317 self
._rmenu
.AppendItem(item
)
320 def LayoutItems(self
):
322 mainSizer
= wx
.BoxSizer(wx
.VERTICAL
)
323 self
.SetSizer(mainSizer
)
325 bookStyle
= fnb
.FNB_NODRAG
327 self
.book
= fnb
.FlatNotebook(self
, wx
.ID_ANY
, style
=bookStyle
)
329 bookStyle
&= ~
(fnb
.FNB_NODRAG
)
330 bookStyle |
= fnb
.FNB_ALLOW_FOREIGN_DND
331 self
.secondBook
= fnb
.FlatNotebook(self
, wx
.ID_ANY
, style
=bookStyle
)
333 # Set right click menu to the notebook
334 self
.book
.SetRightClickMenu(self
._rmenu
)
337 self
.book
.SetImageList(self
._ImageList
)
338 mainSizer
.Add(self
.book
, 6, wx
.EXPAND
)
340 # Add spacer between the books
341 spacer
= wx
.Panel(self
, -1)
342 spacer
.SetBackgroundColour(wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_3DFACE
))
343 mainSizer
.Add(spacer
, 0, wx
.ALL | wx
.EXPAND
)
345 mainSizer
.Add(self
.secondBook
, 2, wx
.EXPAND
)
347 # Add some pages to the second notebook
350 text
= wx
.TextCtrl(self
.secondBook
, -1, "Second Book Page 1\n", style
=wx
.TE_MULTILINE|wx
.TE_READONLY
)
351 self
.secondBook
.AddPage(text
, "Second Book Page 1")
353 text
= wx
.TextCtrl(self
.secondBook
, -1, "Second Book Page 2\n", style
=wx
.TE_MULTILINE|wx
.TE_READONLY
)
354 self
.secondBook
.AddPage(text
, "Second Book Page 2")
362 def OnStyle(self
, event
):
364 style
= self
.book
.GetWindowStyleFlag()
365 eventid
= event
.GetId()
367 if eventid
== MENU_HIDE_NAV_BUTTONS
:
368 if event
.IsChecked():
369 # Hide the navigation buttons
370 style |
= fnb
.FNB_NO_NAV_BUTTONS
372 style
&= ~fnb
.FNB_NO_NAV_BUTTONS
373 style
&= ~fnb
.FNB_DROPDOWN_TABS_LIST
375 self
.book
.SetWindowStyleFlag(style
)
377 elif eventid
== MENU_HIDE_X
:
378 if event
.IsChecked():
380 style |
= fnb
.FNB_NO_X_BUTTON
382 if style
& fnb
.FNB_NO_X_BUTTON
:
383 style ^
= fnb
.FNB_NO_X_BUTTON
385 self
.book
.SetWindowStyleFlag(style
)
387 elif eventid
== MENU_DRAW_BORDER
:
388 if event
.IsChecked():
389 style |
= fnb
.FNB_TABS_BORDER_SIMPLE
391 if style
& fnb
.FNB_TABS_BORDER_SIMPLE
:
392 style ^
= fnb
.FNB_TABS_BORDER_SIMPLE
394 self
.book
.SetWindowStyleFlag(style
)
396 elif eventid
== MENU_USE_MOUSE_MIDDLE_BTN
:
397 if event
.IsChecked():
398 style |
= fnb
.FNB_MOUSE_MIDDLE_CLOSES_TABS
400 if style
& fnb
.FNB_MOUSE_MIDDLE_CLOSES_TABS
:
401 style ^
= fnb
.FNB_MOUSE_MIDDLE_CLOSES_TABS
403 self
.book
.SetWindowStyleFlag(style
)
405 elif eventid
== MENU_USE_BOTTOM_TABS
:
406 if event
.IsChecked():
407 style |
= fnb
.FNB_BOTTOM
409 if style
& fnb
.FNB_BOTTOM
:
410 style ^
= fnb
.FNB_BOTTOM
412 self
.book
.SetWindowStyleFlag(style
)
416 def OnQuit(self
, event
):
421 def OnDeleteAll(self
, event
):
423 self
.book
.DeleteAllPages()
426 def OnShowImages(self
, event
):
428 self
._bShowImages
= event
.IsChecked()
431 def OnVC71Style(self
, event
):
433 style
= self
.book
.GetWindowStyleFlag()
435 # remove old tabs style
436 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS
)
439 style |
= fnb
.FNB_VC71
441 self
.book
.SetWindowStyleFlag(style
)
444 def OnVC8Style(self
, event
):
446 style
= self
.book
.GetWindowStyleFlag()
448 # remove old tabs style
449 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS
)
455 self
.book
.SetWindowStyleFlag(style
)
458 def OnDefaultStyle(self
, event
):
460 style
= self
.book
.GetWindowStyleFlag()
462 # remove old tabs style
463 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS
)
466 self
.book
.SetWindowStyleFlag(style
)
469 def OnFancyStyle(self
, event
):
471 style
= self
.book
.GetWindowStyleFlag()
473 # remove old tabs style
474 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS
)
477 style |
= fnb
.FNB_FANCY_TABS
478 self
.book
.SetWindowStyleFlag(style
)
481 def OnSelectColor(self
, event
):
483 eventid
= event
.GetId()
485 # Open a color dialog
486 data
= wx
.ColourData()
488 dlg
= wx
.ColourDialog(self
, data
)
490 if dlg
.ShowModal() == wx
.ID_OK
:
492 if eventid
== MENU_SELECT_GRADIENT_COLOR_BORDER
:
493 self
.book
.SetGradientColourBorder(dlg
.GetColourData().GetColour())
494 elif eventid
== MENU_SELECT_GRADIENT_COLOR_FROM
:
495 self
.book
.SetGradientColourFrom(dlg
.GetColourData().GetColour())
496 elif eventid
== MENU_SELECT_GRADIENT_COLOR_TO
:
497 self
.book
.SetGradientColourTo(dlg
.GetColourData().GetColour())
498 elif eventid
== MENU_SET_ACTIVE_TEXT_COLOR
:
499 self
.book
.SetActiveTabTextColour(dlg
.GetColourData().GetColour())
500 elif eventid
== MENU_SELECT_NONACTIVE_TEXT_COLOR
:
501 self
.book
.SetNonActiveTabTextColour(dlg
.GetColourData().GetColour())
502 elif eventid
== MENU_SET_ACTIVE_TAB_COLOR
:
503 self
.book
.SetActiveTabColour(dlg
.GetColourData().GetColour())
504 elif eventid
== MENU_SET_TAB_AREA_COLOR
:
505 self
.book
.SetTabAreaColour(dlg
.GetColourData().GetColour())
510 def OnAddPage(self
, event
):
512 caption
= "New Page Added #" + str(self
._newPageCounter
)
517 if self
._bShowImages
:
518 image
= random
.randint(0, self
._ImageList
.GetImageCount()-1)
520 self
.book
.AddPage(self
.CreatePage(caption
), caption
, True, image
)
522 self
._newPageCounter
= self
._newPageCounter
+ 1
525 def CreatePage(self
, caption
):
527 p
= wx
.Panel(self
.book
)
528 wx
.StaticText(p
, -1, caption
, (20,20))
529 wx
.TextCtrl(p
, -1, "", (20,40), (150,-1))
533 def OnDeletePage(self
, event
):
535 self
.book
.DeletePage(self
.book
.GetSelection())
538 def OnSetSelection(self
, event
):
540 dlg
= wx
.TextEntryDialog(self
, "Enter Tab Number to select:", "Set Selection")
542 if dlg
.ShowModal() == wx
.ID_OK
:
545 self
.book
.SetSelection(int(val
))
548 def OnEnableTab(self
, event
):
550 dlg
= wx
.TextEntryDialog(self
, "Enter Tab Number to enable:", "Enable Tab")
552 if dlg
.ShowModal() == wx
.ID_OK
:
555 self
.book
.Enable(int(val
))
558 def OnDisableTab(self
, event
):
560 dlg
= wx
.TextEntryDialog(self
, "Enter Tab Number to disable:", "Disable Tab")
562 if dlg
.ShowModal() == wx
.ID_OK
:
565 self
.book
.Enable(int(val
), False)
568 def OnEnableDrag(self
, event
):
570 style
= self
.book
.GetWindowStyleFlag()
571 style2
= self
.secondBook
.GetWindowStyleFlag()
573 if event
.IsChecked():
574 if style
& fnb
.FNB_NODRAG
:
575 style ^
= fnb
.FNB_NODRAG
576 if style2
& fnb
.FNB_NODRAG
:
577 style2 ^
= fnb
.FNB_NODRAG
579 style |
= fnb
.FNB_NODRAG
580 style2 |
= fnb
.FNB_NODRAG
582 self
.book
.SetWindowStyleFlag(style
)
583 self
.secondBook
.SetWindowStyleFlag(style2
)
586 def OnAllowForeignDnd(self
, event
):
588 style
= self
.book
.GetWindowStyleFlag()
589 if event
.IsChecked():
590 style |
= fnb
.FNB_ALLOW_FOREIGN_DND
592 style
&= ~
(fnb
.FNB_ALLOW_FOREIGN_DND
)
594 self
.book
.SetWindowStyleFlag(style
)
598 def OnSetAllPagesShapeAngle(self
, event
):
601 dlg
= wx
.TextEntryDialog(self
, "Enter an inclination of header borders (0-15):", "Set Angle")
602 if dlg
.ShowModal() == wx
.ID_OK
:
605 self
.book
.SetAllPagesShapeAngle(int(val
))
608 def OnSetPageImage(self
, event
):
610 dlg
= wx
.TextEntryDialog(self
, "Enter an image index (0-%i):"%(self
.book
.GetImageList().GetImageCount()-1), "Set Image Index")
611 if dlg
.ShowModal() == wx
.ID_OK
:
613 self
.book
.SetPageImage(self
.book
.GetSelection(), int(val
))
616 def OnAdvanceSelectionFwd(self
, event
):
618 self
.book
.AdvanceSelection(True)
621 def OnAdvanceSelectionBack(self
, event
):
623 self
.book
.AdvanceSelection(False)
626 def OnPageChanging(self
, event
):
628 self
.log
.write("Page Changing From %d To %d" % (event
.GetOldSelection(), event
.GetSelection()))
632 def OnPageChanged(self
, event
):
634 self
.log
.write("Page Changed To %d" % event
.GetSelection())
638 def OnPageClosing(self
, event
):
640 self
.log
.write("Page Closing, Selection: %d" % event
.GetSelection())
644 def OnDrawTabX(self
, event
):
646 style
= self
.book
.GetWindowStyleFlag()
647 if event
.IsChecked():
648 style |
= fnb
.FNB_X_ON_TAB
650 if style
& fnb
.FNB_X_ON_TAB
:
651 style ^
= fnb
.FNB_X_ON_TAB
653 self
.book
.SetWindowStyleFlag(style
)
656 def OnDClickCloseTab(self
, event
):
658 style
= self
.book
.GetWindowStyleFlag()
659 if event
.IsChecked():
660 style |
= fnb
.FNB_DCLICK_CLOSES_TABS
662 style
&= ~
(fnb
.FNB_DCLICK_CLOSES_TABS
)
664 self
.book
.SetWindowStyleFlag(style
)
667 def OnGradientBack(self
, event
):
669 style
= self
.book
.GetWindowStyleFlag()
670 if event
.IsChecked():
671 style |
= fnb
.FNB_BACKGROUND_GRADIENT
673 style
&= ~
(fnb
.FNB_BACKGROUND_GRADIENT
)
675 self
.book
.SetWindowStyleFlag(style
)
679 def OnColorfulTabs(self
, event
):
681 style
= self
.book
.GetWindowStyleFlag()
682 if event
.IsChecked():
683 style |
= fnb
.FNB_COLORFUL_TABS
685 style
&= ~
(fnb
.FNB_COLORFUL_TABS
)
687 self
.book
.SetWindowStyleFlag(style
)
691 def OnSmartTabs(self
, event
):
693 style
= self
.book
.GetWindowStyleFlag()
694 if event
.IsChecked():
695 style |
= fnb
.FNB_SMART_TABS
697 style
&= ~fnb
.FNB_SMART_TABS
699 self
.book
.SetWindowStyleFlag(style
)
703 def OnDropDownArrow(self
, event
):
705 style
= self
.book
.GetWindowStyleFlag()
707 if event
.IsChecked():
709 style |
= fnb
.FNB_DROPDOWN_TABS_LIST
710 style |
= fnb
.FNB_NO_NAV_BUTTONS
714 style
&= ~fnb
.FNB_DROPDOWN_TABS_LIST
715 style
&= ~fnb
.FNB_NO_NAV_BUTTONS
717 self
.book
.SetWindowStyleFlag(style
)
721 def OnHideNavigationButtonsUI(self
, event
):
723 style
= self
.book
.GetWindowStyleFlag()
724 event
.Check((style
& fnb
.FNB_NO_NAV_BUTTONS
and [True] or [False])[0])
727 def OnDropDownArrowUI(self
, event
):
729 style
= self
.book
.GetWindowStyleFlag()
730 event
.Check((style
& fnb
.FNB_DROPDOWN_TABS_LIST
and [True] or [False])[0])
733 def OnAllowForeignDndUI(self
, event
):
735 style
= self
.book
.GetWindowStyleFlag()
736 event
.Enable((style
& fnb
.FNB_NODRAG
and [False] or [True])[0])
739 def OnAbout(self
, event
):
741 msg
= "This Is The About Dialog Of The FlatNotebook Demo.\n\n" + \
742 "Author: Andrea Gavana @ 02 Oct 2006\n\n" + \
743 "Please Report Any Bug/Requests Of Improvements\n" + \
744 "To Me At The Following Adresses:\n\n" + \
745 "andrea.gavana@gmail.com\n" + "gavana@kpo.kz\n\n" + \
746 "Based On Eran C++ Implementation (wxWidgets Forum).\n\n" + \
747 "Welcome To wxPython " + wx
.VERSION_STRING
+ "!!"
749 dlg
= wx
.MessageDialog(self
, msg
, "FlatNotebook wxPython Demo",
750 wx
.OK | wx
.ICON_INFORMATION
)
755 #---------------------------------------------------------------------------
758 class TestPanel(wx
.Panel
):
759 def __init__(self
, parent
, log
):
761 wx
.Panel
.__init
__(self
, parent
, -1)
763 b
= wx
.Button(self
, -1, " Test FlatNotebook ", (50,50))
764 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
)
767 def OnButton(self
, evt
):
768 self
.win
= FlatNotebookDemo(self
, self
.log
)
771 #----------------------------------------------------------------------
773 def runTest(frame
, nb
, log
):
774 win
= TestPanel(nb
, log
)
777 #----------------------------------------------------------------------
780 overview
= fnb
.__doc
__
784 if __name__
== '__main__':
787 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])