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()
61 MENU_HIDE_ON_SINGLE_TAB
= wx
.NewId()
63 MENU_SET_ACTIVE_TEXT_COLOR
= wx
.NewId()
64 MENU_DRAW_TAB_X
= wx
.NewId()
65 MENU_SET_ACTIVE_TAB_COLOR
= wx
.NewId()
66 MENU_SET_TAB_AREA_COLOR
= wx
.NewId()
67 MENU_SELECT_NONACTIVE_TEXT_COLOR
= wx
.NewId()
68 MENU_GRADIENT_BACKGROUND
= wx
.NewId()
69 MENU_COLORFUL_TABS
= wx
.NewId()
70 MENU_SMART_TABS
= wx
.NewId()
71 MENU_USE_DROP_ARROW_BUTTON
= wx
.NewId()
72 MENU_ALLOW_FOREIGN_DND
= wx
.NewId()
75 class FlatNotebookDemo(wx
.Frame
):
77 def __init__(self
, parent
, log
):
79 wx
.Frame
.__init
__(self
, parent
, title
="FlatNotebook Demo", size
=(800,600))
82 self
._bShowImages
= False
83 self
._bVCStyle
= False
84 self
._newPageCounter
= 0
86 self
._ImageList
= wx
.ImageList(16, 16)
87 self
._ImageList
.Add(images
.get_book_redBitmap())
88 self
._ImageList
.Add(images
.get_book_greenBitmap())
89 self
._ImageList
.Add(images
.get_book_blueBitmap())
91 self
.statusbar
= self
.CreateStatusBar(2, wx
.ST_SIZEGRIP
)
92 self
.statusbar
.SetStatusWidths([-2, -1])
94 statusbar_fields
= [("FlatNotebook wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
95 ("Welcome To wxPython!")]
97 for i
in range(len(statusbar_fields
)):
98 self
.statusbar
.SetStatusText(statusbar_fields
[i
], i
)
100 self
.SetIcon(GetMondrianIcon())
102 self
.CreateRightClickMenu()
105 self
.Bind(fnb
.EVT_FLATNOTEBOOK_PAGE_CHANGING
, self
.OnPageChanging
)
106 self
.Bind(fnb
.EVT_FLATNOTEBOOK_PAGE_CHANGED
, self
.OnPageChanged
)
107 self
.Bind(fnb
.EVT_FLATNOTEBOOK_PAGE_CLOSING
, self
.OnPageClosing
)
109 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnDropDownArrowUI
, id=MENU_USE_DROP_ARROW_BUTTON
)
110 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnHideNavigationButtonsUI
, id=MENU_HIDE_NAV_BUTTONS
)
111 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnAllowForeignDndUI
, id=MENU_ALLOW_FOREIGN_DND
)
114 def CreateMenuBar(self
):
116 self
._menuBar
= wx
.MenuBar(wx
.MB_DOCKABLE
)
117 self
._fileMenu
= wx
.Menu()
118 self
._editMenu
= wx
.Menu()
119 self
._visualMenu
= wx
.Menu()
121 item
= wx
.MenuItem(self
._fileMenu
, wx
.ID_ANY
, "&Close\tCtrl-Q", "Close demo window")
122 self
.Bind(wx
.EVT_MENU
, self
.OnQuit
, item
)
123 self
._fileMenu
.AppendItem(item
)
125 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_ADD_PAGE
, "New Page\tCtrl+N", "Add New Page")
126 self
.Bind(wx
.EVT_MENU
, self
.OnAddPage
, item
)
127 self
._editMenu
.AppendItem(item
)
129 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_DELETE_PAGE
, "Delete Page\tCtrl+F4", "Delete Page")
130 self
.Bind(wx
.EVT_MENU
, self
.OnDeletePage
, item
)
131 self
._editMenu
.AppendItem(item
)
133 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_DELETE_ALL
, "Delete All Pages", "Delete All Pages")
134 self
.Bind(wx
.EVT_MENU
, self
.OnDeleteAll
, item
)
135 self
._editMenu
.AppendItem(item
)
137 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_SET_SELECTION
, "Set Selection", "Set Selection")
138 self
.Bind(wx
.EVT_MENU
, self
.OnSetSelection
, item
)
139 self
._editMenu
.AppendItem(item
)
141 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_ADVANCE_SELECTION_FWD
, "Advance Selection Forward",
142 "Advance Selection Forward")
143 self
.Bind(wx
.EVT_MENU
, self
.OnAdvanceSelectionFwd
, item
)
144 self
._editMenu
.AppendItem(item
)
146 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_ADVANCE_SELECTION_BACK
, "Advance Selection Backward",
147 "Advance Selection Backward")
148 self
.Bind(wx
.EVT_MENU
, self
.OnAdvanceSelectionBack
, item
)
149 self
._editMenu
.AppendItem(item
)
151 item
= wx
.MenuItem(self
._editMenu
, MENU_SET_ALL_TABS_SHAPE_ANGLE
, "Set an inclination of tab header borders",
152 "Set the shape of tab header")
153 self
.Bind(wx
.EVT_MENU
, self
.OnSetAllPagesShapeAngle
, item
)
154 self
._visualMenu
.AppendItem(item
)
156 item
= wx
.MenuItem(self
._editMenu
, MENU_SET_PAGE_IMAGE_INDEX
, "Set image index of selected page",
158 self
.Bind(wx
.EVT_MENU
, self
.OnSetPageImage
, item
)
159 self
._editMenu
.AppendItem(item
)
161 item
= wx
.MenuItem(self
._editMenu
, MENU_SHOW_IMAGES
, "Show Images", "Show Images", wx
.ITEM_CHECK
)
162 self
.Bind(wx
.EVT_MENU
, self
.OnShowImages
, item
)
163 self
._editMenu
.AppendItem(item
)
165 styleMenu
= wx
.Menu()
166 item
= wx
.MenuItem(styleMenu
, MENU_USE_DEFAULT_STYLE
, "Use Default Style", "Use VC71 Style", wx
.ITEM_RADIO
)
167 self
.Bind(wx
.EVT_MENU
, self
.OnDefaultStyle
, item
)
168 styleMenu
.AppendItem(item
)
170 item
= wx
.MenuItem(styleMenu
, MENU_USE_VC71_STYLE
, "Use VC71 Style", "Use VC71 Style", wx
.ITEM_RADIO
)
171 self
.Bind(wx
.EVT_MENU
, self
.OnVC71Style
, item
)
172 styleMenu
.AppendItem(item
)
174 item
= wx
.MenuItem(styleMenu
, MENU_USE_VC8_STYLE
, "Use VC8 Style", "Use VC8 Style", wx
.ITEM_RADIO
)
175 self
.Bind(wx
.EVT_MENU
, self
.OnVC8Style
, item
)
176 styleMenu
.AppendItem(item
)
178 item
= wx
.MenuItem(styleMenu
, MENU_USE_FANCY_STYLE
, "Use Fancy Style", "Use Fancy Style", wx
.ITEM_RADIO
)
179 self
.Bind(wx
.EVT_MENU
, self
.OnFancyStyle
, item
)
180 styleMenu
.AppendItem(item
)
182 self
._visualMenu
.AppendMenu(wx
.ID_ANY
, "Tabs Style", styleMenu
)
184 item
= wx
.MenuItem(self
._visualMenu
, MENU_SELECT_GRADIENT_COLOR_FROM
, "Select fancy tab style 'from' color",
185 "Select fancy tab style 'from' color")
186 self
._visualMenu
.AppendItem(item
)
188 item
= wx
.MenuItem(self
._visualMenu
, MENU_SELECT_GRADIENT_COLOR_TO
, "Select fancy tab style 'to' color",
189 "Select fancy tab style 'to' color")
190 self
._visualMenu
.AppendItem(item
)
192 item
= wx
.MenuItem(self
._visualMenu
, MENU_SELECT_GRADIENT_COLOR_BORDER
, "Select fancy tab style 'border' color",
193 "Select fancy tab style 'border' color")
194 self
._visualMenu
.AppendItem(item
)
196 self
._editMenu
.AppendSeparator()
198 self
.Bind(wx
.EVT_MENU_RANGE
, self
.OnSelectColor
, id=MENU_SELECT_GRADIENT_COLOR_FROM
,
199 id2
=MENU_SELECT_GRADIENT_COLOR_BORDER
)
201 item
= wx
.MenuItem(self
._editMenu
, MENU_HIDE_ON_SINGLE_TAB
, "Hide Page Container when only one Tab",
202 "Hide Page Container when only one Tab", wx
.ITEM_CHECK
)
203 self
.Bind(wx
.EVT_MENU
, self
.OnStyle
, item
)
204 self
._editMenu
.AppendItem(item
)
206 item
= wx
.MenuItem(self
._editMenu
, MENU_HIDE_NAV_BUTTONS
, "Hide Navigation Buttons",
207 "Hide Navigation Buttons", wx
.ITEM_CHECK
)
208 self
._editMenu
.AppendItem(item
)
210 item
= wx
.MenuItem(self
._editMenu
, MENU_HIDE_X
, "Hide X Button", "Hide X Button", wx
.ITEM_CHECK
)
211 self
._editMenu
.AppendItem(item
)
213 item
= wx
.MenuItem(self
._editMenu
, MENU_SMART_TABS
, "Smart tabbing", "Smart tabbing", wx
.ITEM_CHECK
)
214 self
._editMenu
.AppendItem(item
)
215 self
.Bind(wx
.EVT_MENU
, self
.OnSmartTabs
, item
)
218 item
= wx
.MenuItem(self
._editMenu
, MENU_USE_DROP_ARROW_BUTTON
, "Use drop down button for tab navigation",
219 "Use drop down arrow for quick tab navigation", wx
.ITEM_CHECK
)
220 self
._editMenu
.AppendItem(item
)
221 self
.Bind(wx
.EVT_MENU
, self
.OnDropDownArrow
, item
)
223 self
._editMenu
.AppendSeparator()
225 item
= wx
.MenuItem(self
._editMenu
, MENU_USE_MOUSE_MIDDLE_BTN
, "Use Mouse Middle Button as 'X' button",
226 "Use Mouse Middle Button as 'X' button", wx
.ITEM_CHECK
)
227 self
._editMenu
.AppendItem(item
)
229 item
= wx
.MenuItem(self
._editMenu
, MENU_DCLICK_CLOSES_TAB
, "Mouse double click closes tab",
230 "Mouse double click closes tab", wx
.ITEM_CHECK
)
231 self
.Bind(wx
.EVT_MENU
, self
.OnDClickCloseTab
, item
)
232 self
._editMenu
.AppendItem(item
)
235 self
._editMenu
.AppendSeparator()
237 item
= wx
.MenuItem(self
._editMenu
, MENU_USE_BOTTOM_TABS
, "Use Bottoms Tabs", "Use Bottoms Tabs",
239 self
._editMenu
.AppendItem(item
)
241 self
.Bind(wx
.EVT_MENU_RANGE
, self
.OnStyle
, id=MENU_HIDE_X
, id2
=MENU_USE_BOTTOM_TABS
)
243 item
= wx
.MenuItem(self
._editMenu
, MENU_ENABLE_TAB
, "Enable Tab", "Enable Tab")
244 self
.Bind(wx
.EVT_MENU
, self
.OnEnableTab
, item
)
245 self
._editMenu
.AppendItem(item
)
247 item
= wx
.MenuItem(self
._editMenu
, MENU_DISABLE_TAB
, "Disable Tab", "Disable Tab")
248 self
.Bind(wx
.EVT_MENU
, self
.OnDisableTab
, item
)
249 self
._editMenu
.AppendItem(item
)
251 item
= wx
.MenuItem(self
._editMenu
, MENU_ENABLE_DRAG_N_DROP
, "Enable Drag And Drop of Tabs",
252 "Enable Drag And Drop of Tabs", wx
.ITEM_CHECK
)
253 self
.Bind(wx
.EVT_MENU
, self
.OnEnableDrag
, item
)
254 self
._editMenu
.AppendItem(item
)
257 item
= wx
.MenuItem(self
._editMenu
, MENU_ALLOW_FOREIGN_DND
, "Enable Drag And Drop of Tabs from foreign notebooks",
258 "Enable Drag And Drop of Tabs from foreign notebooks", wx
.ITEM_CHECK
)
259 self
.Bind(wx
.EVT_MENU
, self
.OnAllowForeignDnd
, item
)
260 self
._editMenu
.AppendItem(item
)
263 item
= wx
.MenuItem(self
._visualMenu
, MENU_DRAW_BORDER
, "Draw Border around tab area",
264 "Draw Border around tab area", wx
.ITEM_CHECK
)
265 self
.Bind(wx
.EVT_MENU
, self
.OnStyle
, item
)
266 self
._visualMenu
.AppendItem(item
)
269 item
= wx
.MenuItem(self
._visualMenu
, MENU_DRAW_TAB_X
, "Draw X button On Active Tab",
270 "Draw X button On Active Tab", wx
.ITEM_CHECK
)
271 self
.Bind(wx
.EVT_MENU
, self
.OnDrawTabX
, item
)
272 self
._visualMenu
.AppendItem(item
)
274 item
= wx
.MenuItem(self
._visualMenu
, MENU_SET_ACTIVE_TAB_COLOR
, "Select Active Tab Color",
275 "Select Active Tab Color")
276 self
.Bind(wx
.EVT_MENU
, self
.OnSelectColor
, item
)
277 self
._visualMenu
.AppendItem(item
)
279 item
= wx
.MenuItem(self
._visualMenu
, MENU_SET_TAB_AREA_COLOR
, "Select Tab Area Color",
280 "Select Tab Area Color")
281 self
.Bind(wx
.EVT_MENU
, self
.OnSelectColor
, item
)
282 self
._visualMenu
.AppendItem(item
)
284 item
= wx
.MenuItem(self
._visualMenu
, MENU_SET_ACTIVE_TEXT_COLOR
, "Select active tab text color",
285 "Select active tab text color")
286 self
.Bind(wx
.EVT_MENU
, self
.OnSelectColor
, item
)
287 self
._visualMenu
.AppendItem(item
)
289 item
= wx
.MenuItem(self
._visualMenu
, MENU_SELECT_NONACTIVE_TEXT_COLOR
,
290 "Select NON-active tab text color", "Select NON-active tab text color")
291 self
.Bind(wx
.EVT_MENU
, self
.OnSelectColor
, item
)
292 self
._visualMenu
.AppendItem(item
)
294 item
= wx
.MenuItem(self
._visualMenu
, MENU_GRADIENT_BACKGROUND
, "Use Gradient Coloring for tab area",
295 "Use Gradient Coloring for tab area", wx
.ITEM_CHECK
)
296 self
.Bind(wx
.EVT_MENU
, self
.OnGradientBack
, item
)
297 self
._visualMenu
.AppendItem(item
)
300 item
= wx
.MenuItem(self
._visualMenu
, MENU_COLORFUL_TABS
, "Colorful tabs", "Colorful tabs", wx
.ITEM_CHECK
)
301 self
.Bind(wx
.EVT_MENU
, self
.OnColorfulTabs
, item
)
302 self
._visualMenu
.AppendItem(item
)
305 help_menu
= wx
.Menu()
306 item
= wx
.MenuItem(help_menu
, wx
.ID_ANY
, "About...", "Shows The About Dialog")
307 self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, item
)
308 help_menu
.AppendItem(item
)
310 self
._menuBar
.Append(self
._fileMenu
, "&File")
311 self
._menuBar
.Append(self
._editMenu
, "&Edit")
312 self
._menuBar
.Append(self
._visualMenu
, "&Tab Appearance")
314 self
._menuBar
.Append(help_menu
, "&Help")
316 self
.SetMenuBar(self
._menuBar
)
319 def CreateRightClickMenu(self
):
321 self
._rmenu
= wx
.Menu()
322 item
= wx
.MenuItem(self
._rmenu
, MENU_EDIT_DELETE_PAGE
, "Close Tab\tCtrl+F4", "Close Tab")
323 self
._rmenu
.AppendItem(item
)
326 def LayoutItems(self
):
328 mainSizer
= wx
.BoxSizer(wx
.VERTICAL
)
329 self
.SetSizer(mainSizer
)
331 bookStyle
= fnb
.FNB_NODRAG
333 self
.book
= fnb
.FlatNotebook(self
, wx
.ID_ANY
, style
=bookStyle
)
335 bookStyle
&= ~
(fnb
.FNB_NODRAG
)
336 bookStyle |
= fnb
.FNB_ALLOW_FOREIGN_DND
337 self
.secondBook
= fnb
.FlatNotebook(self
, wx
.ID_ANY
, style
=bookStyle
)
339 # Set right click menu to the notebook
340 self
.book
.SetRightClickMenu(self
._rmenu
)
343 self
.book
.SetImageList(self
._ImageList
)
344 mainSizer
.Add(self
.book
, 6, wx
.EXPAND
)
346 # Add spacer between the books
347 spacer
= wx
.Panel(self
, -1)
348 spacer
.SetBackgroundColour(wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_3DFACE
))
349 mainSizer
.Add(spacer
, 0, wx
.ALL | wx
.EXPAND
)
351 mainSizer
.Add(self
.secondBook
, 2, wx
.EXPAND
)
353 # Add some pages to the second notebook
356 text
= wx
.TextCtrl(self
.secondBook
, -1, "Second Book Page 1\n", style
=wx
.TE_MULTILINE|wx
.TE_READONLY
)
357 self
.secondBook
.AddPage(text
, "Second Book Page 1")
359 text
= wx
.TextCtrl(self
.secondBook
, -1, "Second Book Page 2\n", style
=wx
.TE_MULTILINE|wx
.TE_READONLY
)
360 self
.secondBook
.AddPage(text
, "Second Book Page 2")
368 def OnStyle(self
, event
):
370 style
= self
.book
.GetWindowStyleFlag()
371 eventid
= event
.GetId()
373 if eventid
== MENU_HIDE_NAV_BUTTONS
:
374 if event
.IsChecked():
375 # Hide the navigation buttons
376 style |
= fnb
.FNB_NO_NAV_BUTTONS
378 style
&= ~fnb
.FNB_NO_NAV_BUTTONS
379 style
&= ~fnb
.FNB_DROPDOWN_TABS_LIST
381 self
.book
.SetWindowStyleFlag(style
)
383 elif eventid
== MENU_HIDE_ON_SINGLE_TAB
:
384 if event
.IsChecked():
385 # Hide the navigation buttons
386 style |
= fnb
.FNB_HIDE_ON_SINGLE_TAB
388 style
&= ~
(fnb
.FNB_HIDE_ON_SINGLE_TAB
)
390 self
.book
.SetWindowStyleFlag(style
)
392 elif eventid
== MENU_HIDE_X
:
393 if event
.IsChecked():
395 style |
= fnb
.FNB_NO_X_BUTTON
397 if style
& fnb
.FNB_NO_X_BUTTON
:
398 style ^
= fnb
.FNB_NO_X_BUTTON
400 self
.book
.SetWindowStyleFlag(style
)
402 elif eventid
== MENU_DRAW_BORDER
:
403 if event
.IsChecked():
404 style |
= fnb
.FNB_TABS_BORDER_SIMPLE
406 if style
& fnb
.FNB_TABS_BORDER_SIMPLE
:
407 style ^
= fnb
.FNB_TABS_BORDER_SIMPLE
409 self
.book
.SetWindowStyleFlag(style
)
411 elif eventid
== MENU_USE_MOUSE_MIDDLE_BTN
:
412 if event
.IsChecked():
413 style |
= fnb
.FNB_MOUSE_MIDDLE_CLOSES_TABS
415 if style
& fnb
.FNB_MOUSE_MIDDLE_CLOSES_TABS
:
416 style ^
= fnb
.FNB_MOUSE_MIDDLE_CLOSES_TABS
418 self
.book
.SetWindowStyleFlag(style
)
420 elif eventid
== MENU_USE_BOTTOM_TABS
:
421 if event
.IsChecked():
422 style |
= fnb
.FNB_BOTTOM
424 if style
& fnb
.FNB_BOTTOM
:
425 style ^
= fnb
.FNB_BOTTOM
427 self
.book
.SetWindowStyleFlag(style
)
431 def OnQuit(self
, event
):
436 def OnDeleteAll(self
, event
):
438 self
.book
.DeleteAllPages()
441 def OnShowImages(self
, event
):
443 self
._bShowImages
= event
.IsChecked()
446 def OnVC71Style(self
, event
):
448 style
= self
.book
.GetWindowStyleFlag()
450 # remove old tabs style
451 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS
)
454 style |
= fnb
.FNB_VC71
456 self
.book
.SetWindowStyleFlag(style
)
459 def OnVC8Style(self
, event
):
461 style
= self
.book
.GetWindowStyleFlag()
463 # remove old tabs style
464 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS
)
470 self
.book
.SetWindowStyleFlag(style
)
473 def OnDefaultStyle(self
, event
):
475 style
= self
.book
.GetWindowStyleFlag()
477 # remove old tabs style
478 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS
)
481 self
.book
.SetWindowStyleFlag(style
)
484 def OnFancyStyle(self
, event
):
486 style
= self
.book
.GetWindowStyleFlag()
488 # remove old tabs style
489 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS
)
492 style |
= fnb
.FNB_FANCY_TABS
493 self
.book
.SetWindowStyleFlag(style
)
496 def OnSelectColor(self
, event
):
498 eventid
= event
.GetId()
500 # Open a color dialog
501 data
= wx
.ColourData()
503 dlg
= wx
.ColourDialog(self
, data
)
505 if dlg
.ShowModal() == wx
.ID_OK
:
507 if eventid
== MENU_SELECT_GRADIENT_COLOR_BORDER
:
508 self
.book
.SetGradientColourBorder(dlg
.GetColourData().GetColour())
509 elif eventid
== MENU_SELECT_GRADIENT_COLOR_FROM
:
510 self
.book
.SetGradientColourFrom(dlg
.GetColourData().GetColour())
511 elif eventid
== MENU_SELECT_GRADIENT_COLOR_TO
:
512 self
.book
.SetGradientColourTo(dlg
.GetColourData().GetColour())
513 elif eventid
== MENU_SET_ACTIVE_TEXT_COLOR
:
514 self
.book
.SetActiveTabTextColour(dlg
.GetColourData().GetColour())
515 elif eventid
== MENU_SELECT_NONACTIVE_TEXT_COLOR
:
516 self
.book
.SetNonActiveTabTextColour(dlg
.GetColourData().GetColour())
517 elif eventid
== MENU_SET_ACTIVE_TAB_COLOR
:
518 self
.book
.SetActiveTabColour(dlg
.GetColourData().GetColour())
519 elif eventid
== MENU_SET_TAB_AREA_COLOR
:
520 self
.book
.SetTabAreaColour(dlg
.GetColourData().GetColour())
525 def OnAddPage(self
, event
):
527 caption
= "New Page Added #" + str(self
._newPageCounter
)
532 if self
._bShowImages
:
533 image
= random
.randint(0, self
._ImageList
.GetImageCount()-1)
535 self
.book
.AddPage(self
.CreatePage(caption
), caption
, True, image
)
537 self
._newPageCounter
= self
._newPageCounter
+ 1
540 def CreatePage(self
, caption
):
542 p
= wx
.Panel(self
.book
)
543 wx
.StaticText(p
, -1, caption
, (20,20))
544 wx
.TextCtrl(p
, -1, "", (20,40), (150,-1))
548 def OnDeletePage(self
, event
):
550 self
.book
.DeletePage(self
.book
.GetSelection())
553 def OnSetSelection(self
, event
):
555 dlg
= wx
.TextEntryDialog(self
, "Enter Tab Number to select:", "Set Selection")
557 if dlg
.ShowModal() == wx
.ID_OK
:
560 self
.book
.SetSelection(int(val
))
563 def OnEnableTab(self
, event
):
565 dlg
= wx
.TextEntryDialog(self
, "Enter Tab Number to enable:", "Enable Tab")
567 if dlg
.ShowModal() == wx
.ID_OK
:
570 self
.book
.Enable(int(val
))
573 def OnDisableTab(self
, event
):
575 dlg
= wx
.TextEntryDialog(self
, "Enter Tab Number to disable:", "Disable Tab")
577 if dlg
.ShowModal() == wx
.ID_OK
:
580 self
.book
.Enable(int(val
), False)
583 def OnEnableDrag(self
, event
):
585 style
= self
.book
.GetWindowStyleFlag()
586 style2
= self
.secondBook
.GetWindowStyleFlag()
588 if event
.IsChecked():
589 if style
& fnb
.FNB_NODRAG
:
590 style ^
= fnb
.FNB_NODRAG
591 if style2
& fnb
.FNB_NODRAG
:
592 style2 ^
= fnb
.FNB_NODRAG
594 style |
= fnb
.FNB_NODRAG
595 style2 |
= fnb
.FNB_NODRAG
597 self
.book
.SetWindowStyleFlag(style
)
598 self
.secondBook
.SetWindowStyleFlag(style2
)
601 def OnAllowForeignDnd(self
, event
):
603 style
= self
.book
.GetWindowStyleFlag()
604 if event
.IsChecked():
605 style |
= fnb
.FNB_ALLOW_FOREIGN_DND
607 style
&= ~
(fnb
.FNB_ALLOW_FOREIGN_DND
)
609 self
.book
.SetWindowStyleFlag(style
)
613 def OnSetAllPagesShapeAngle(self
, event
):
616 dlg
= wx
.TextEntryDialog(self
, "Enter an inclination of header borders (0-15):", "Set Angle")
617 if dlg
.ShowModal() == wx
.ID_OK
:
620 self
.book
.SetAllPagesShapeAngle(int(val
))
623 def OnSetPageImage(self
, event
):
625 dlg
= wx
.TextEntryDialog(self
, "Enter an image index (0-%i):"%(self
.book
.GetImageList().GetImageCount()-1), "Set Image Index")
626 if dlg
.ShowModal() == wx
.ID_OK
:
628 self
.book
.SetPageImage(self
.book
.GetSelection(), int(val
))
631 def OnAdvanceSelectionFwd(self
, event
):
633 self
.book
.AdvanceSelection(True)
636 def OnAdvanceSelectionBack(self
, event
):
638 self
.book
.AdvanceSelection(False)
641 def OnPageChanging(self
, event
):
643 self
.log
.write("Page Changing From %d To %d" % (event
.GetOldSelection(), event
.GetSelection()))
647 def OnPageChanged(self
, event
):
649 self
.log
.write("Page Changed To %d" % event
.GetSelection())
653 def OnPageClosing(self
, event
):
655 self
.log
.write("Page Closing, Selection: %d" % event
.GetSelection())
659 def OnDrawTabX(self
, event
):
661 style
= self
.book
.GetWindowStyleFlag()
662 if event
.IsChecked():
663 style |
= fnb
.FNB_X_ON_TAB
665 if style
& fnb
.FNB_X_ON_TAB
:
666 style ^
= fnb
.FNB_X_ON_TAB
668 self
.book
.SetWindowStyleFlag(style
)
671 def OnDClickCloseTab(self
, event
):
673 style
= self
.book
.GetWindowStyleFlag()
674 if event
.IsChecked():
675 style |
= fnb
.FNB_DCLICK_CLOSES_TABS
677 style
&= ~
(fnb
.FNB_DCLICK_CLOSES_TABS
)
679 self
.book
.SetWindowStyleFlag(style
)
682 def OnGradientBack(self
, event
):
684 style
= self
.book
.GetWindowStyleFlag()
685 if event
.IsChecked():
686 style |
= fnb
.FNB_BACKGROUND_GRADIENT
688 style
&= ~
(fnb
.FNB_BACKGROUND_GRADIENT
)
690 self
.book
.SetWindowStyleFlag(style
)
694 def OnColorfulTabs(self
, event
):
696 style
= self
.book
.GetWindowStyleFlag()
697 if event
.IsChecked():
698 style |
= fnb
.FNB_COLORFUL_TABS
700 style
&= ~
(fnb
.FNB_COLORFUL_TABS
)
702 self
.book
.SetWindowStyleFlag(style
)
706 def OnSmartTabs(self
, event
):
708 style
= self
.book
.GetWindowStyleFlag()
709 if event
.IsChecked():
710 style |
= fnb
.FNB_SMART_TABS
712 style
&= ~fnb
.FNB_SMART_TABS
714 self
.book
.SetWindowStyleFlag(style
)
718 def OnDropDownArrow(self
, event
):
720 style
= self
.book
.GetWindowStyleFlag()
722 if event
.IsChecked():
724 style |
= fnb
.FNB_DROPDOWN_TABS_LIST
725 style |
= fnb
.FNB_NO_NAV_BUTTONS
729 style
&= ~fnb
.FNB_DROPDOWN_TABS_LIST
730 style
&= ~fnb
.FNB_NO_NAV_BUTTONS
732 self
.book
.SetWindowStyleFlag(style
)
736 def OnHideNavigationButtonsUI(self
, event
):
738 style
= self
.book
.GetWindowStyleFlag()
739 event
.Check((style
& fnb
.FNB_NO_NAV_BUTTONS
and [True] or [False])[0])
742 def OnDropDownArrowUI(self
, event
):
744 style
= self
.book
.GetWindowStyleFlag()
745 event
.Check((style
& fnb
.FNB_DROPDOWN_TABS_LIST
and [True] or [False])[0])
748 def OnAllowForeignDndUI(self
, event
):
750 style
= self
.book
.GetWindowStyleFlag()
751 event
.Enable((style
& fnb
.FNB_NODRAG
and [False] or [True])[0])
754 def OnAbout(self
, event
):
756 msg
= "This Is The About Dialog Of The FlatNotebook Demo.\n\n" + \
757 "Author: Andrea Gavana @ 02 Oct 2006\n\n" + \
758 "Please Report Any Bug/Requests Of Improvements\n" + \
759 "To Me At The Following Adresses:\n\n" + \
760 "andrea.gavana@gmail.com\n" + "gavana@kpo.kz\n\n" + \
761 "Based On Eran C++ Implementation (wxWidgets Forum).\n\n" + \
762 "Welcome To wxPython " + wx
.VERSION_STRING
+ "!!"
764 dlg
= wx
.MessageDialog(self
, msg
, "FlatNotebook wxPython Demo",
765 wx
.OK | wx
.ICON_INFORMATION
)
770 #---------------------------------------------------------------------------
773 class TestPanel(wx
.Panel
):
774 def __init__(self
, parent
, log
):
776 wx
.Panel
.__init
__(self
, parent
, -1)
778 b
= wx
.Button(self
, -1, " Test FlatNotebook ", (50,50))
779 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
)
782 def OnButton(self
, evt
):
783 self
.win
= FlatNotebookDemo(self
, self
.log
)
786 #----------------------------------------------------------------------
788 def runTest(frame
, nb
, log
):
789 win
= TestPanel(nb
, log
)
792 #----------------------------------------------------------------------
795 overview
= fnb
.__doc
__
799 if __name__
== '__main__':
802 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])