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_USE_FF2_STYLE
= wx
.NewId()
62 MENU_HIDE_ON_SINGLE_TAB
= wx
.NewId()
64 MENU_SET_ACTIVE_TEXT_COLOR
= wx
.NewId()
65 MENU_DRAW_TAB_X
= wx
.NewId()
66 MENU_SET_ACTIVE_TAB_COLOR
= wx
.NewId()
67 MENU_SET_TAB_AREA_COLOR
= wx
.NewId()
68 MENU_SELECT_NONACTIVE_TEXT_COLOR
= wx
.NewId()
69 MENU_GRADIENT_BACKGROUND
= wx
.NewId()
70 MENU_COLORFUL_TABS
= wx
.NewId()
71 MENU_SMART_TABS
= wx
.NewId()
72 MENU_USE_DROP_ARROW_BUTTON
= wx
.NewId()
73 MENU_ALLOW_FOREIGN_DND
= wx
.NewId()
76 class FlatNotebookDemo(wx
.Frame
):
78 def __init__(self
, parent
, log
):
80 wx
.Frame
.__init
__(self
, parent
, title
="FlatNotebook Demo", size
=(800,600))
83 self
._bShowImages
= False
84 self
._bVCStyle
= False
85 self
._newPageCounter
= 0
87 self
._ImageList
= wx
.ImageList(16, 16)
88 self
._ImageList
.Add(images
.get_book_redBitmap())
89 self
._ImageList
.Add(images
.get_book_greenBitmap())
90 self
._ImageList
.Add(images
.get_book_blueBitmap())
92 self
.statusbar
= self
.CreateStatusBar(2, wx
.ST_SIZEGRIP
)
93 self
.statusbar
.SetStatusWidths([-2, -1])
95 statusbar_fields
= [("FlatNotebook wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
96 ("Welcome To wxPython!")]
98 for i
in range(len(statusbar_fields
)):
99 self
.statusbar
.SetStatusText(statusbar_fields
[i
], i
)
101 self
.SetIcon(GetMondrianIcon())
103 self
.CreateRightClickMenu()
106 self
.Bind(fnb
.EVT_FLATNOTEBOOK_PAGE_CHANGING
, self
.OnPageChanging
)
107 self
.Bind(fnb
.EVT_FLATNOTEBOOK_PAGE_CHANGED
, self
.OnPageChanged
)
108 self
.Bind(fnb
.EVT_FLATNOTEBOOK_PAGE_CLOSING
, self
.OnPageClosing
)
110 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnDropDownArrowUI
, id=MENU_USE_DROP_ARROW_BUTTON
)
111 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnHideNavigationButtonsUI
, id=MENU_HIDE_NAV_BUTTONS
)
112 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnAllowForeignDndUI
, id=MENU_ALLOW_FOREIGN_DND
)
115 def CreateMenuBar(self
):
117 self
._menuBar
= wx
.MenuBar(wx
.MB_DOCKABLE
)
118 self
._fileMenu
= wx
.Menu()
119 self
._editMenu
= wx
.Menu()
120 self
._visualMenu
= wx
.Menu()
122 item
= wx
.MenuItem(self
._fileMenu
, wx
.ID_ANY
, "&Close\tCtrl-Q", "Close demo window")
123 self
.Bind(wx
.EVT_MENU
, self
.OnQuit
, item
)
124 self
._fileMenu
.AppendItem(item
)
126 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_ADD_PAGE
, "New Page\tCtrl+N", "Add New Page")
127 self
.Bind(wx
.EVT_MENU
, self
.OnAddPage
, item
)
128 self
._editMenu
.AppendItem(item
)
130 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_DELETE_PAGE
, "Delete Page\tCtrl+F4", "Delete Page")
131 self
.Bind(wx
.EVT_MENU
, self
.OnDeletePage
, item
)
132 self
._editMenu
.AppendItem(item
)
134 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_DELETE_ALL
, "Delete All Pages", "Delete All Pages")
135 self
.Bind(wx
.EVT_MENU
, self
.OnDeleteAll
, item
)
136 self
._editMenu
.AppendItem(item
)
138 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_SET_SELECTION
, "Set Selection", "Set Selection")
139 self
.Bind(wx
.EVT_MENU
, self
.OnSetSelection
, item
)
140 self
._editMenu
.AppendItem(item
)
142 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_ADVANCE_SELECTION_FWD
, "Advance Selection Forward",
143 "Advance Selection Forward")
144 self
.Bind(wx
.EVT_MENU
, self
.OnAdvanceSelectionFwd
, item
)
145 self
._editMenu
.AppendItem(item
)
147 item
= wx
.MenuItem(self
._editMenu
, MENU_EDIT_ADVANCE_SELECTION_BACK
, "Advance Selection Backward",
148 "Advance Selection Backward")
149 self
.Bind(wx
.EVT_MENU
, self
.OnAdvanceSelectionBack
, item
)
150 self
._editMenu
.AppendItem(item
)
152 item
= wx
.MenuItem(self
._editMenu
, MENU_SET_ALL_TABS_SHAPE_ANGLE
, "Set an inclination of tab header borders",
153 "Set the shape of tab header")
154 self
.Bind(wx
.EVT_MENU
, self
.OnSetAllPagesShapeAngle
, item
)
155 self
._visualMenu
.AppendItem(item
)
157 item
= wx
.MenuItem(self
._editMenu
, MENU_SET_PAGE_IMAGE_INDEX
, "Set image index of selected page",
159 self
.Bind(wx
.EVT_MENU
, self
.OnSetPageImage
, item
)
160 self
._editMenu
.AppendItem(item
)
162 item
= wx
.MenuItem(self
._editMenu
, MENU_SHOW_IMAGES
, "Show Images", "Show Images", wx
.ITEM_CHECK
)
163 self
.Bind(wx
.EVT_MENU
, self
.OnShowImages
, item
)
164 self
._editMenu
.AppendItem(item
)
166 styleMenu
= wx
.Menu()
167 item
= wx
.MenuItem(styleMenu
, MENU_USE_DEFAULT_STYLE
, "Use Default Style", "Use VC71 Style", wx
.ITEM_RADIO
)
168 self
.Bind(wx
.EVT_MENU
, self
.OnDefaultStyle
, item
)
169 styleMenu
.AppendItem(item
)
171 item
= wx
.MenuItem(styleMenu
, MENU_USE_VC71_STYLE
, "Use VC71 Style", "Use VC71 Style", wx
.ITEM_RADIO
)
172 self
.Bind(wx
.EVT_MENU
, self
.OnVC71Style
, item
)
173 styleMenu
.AppendItem(item
)
175 item
= wx
.MenuItem(styleMenu
, MENU_USE_VC8_STYLE
, "Use VC8 Style", "Use VC8 Style", wx
.ITEM_RADIO
)
176 self
.Bind(wx
.EVT_MENU
, self
.OnVC8Style
, item
)
177 styleMenu
.AppendItem(item
)
179 item
= wx
.MenuItem(styleMenu
, MENU_USE_FANCY_STYLE
, "Use Fancy Style", "Use Fancy Style", wx
.ITEM_RADIO
)
180 self
.Bind(wx
.EVT_MENU
, self
.OnFancyStyle
, item
)
181 styleMenu
.AppendItem(item
)
183 item
= wx
.MenuItem(styleMenu
, MENU_USE_FF2_STYLE
, "Use Firefox 2 Style", "Use Firefox 2 Style", wx
.ITEM_RADIO
)
184 self
.Bind(wx
.EVT_MENU
, self
.OnFF2Style
, item
)
185 styleMenu
.AppendItem(item
)
187 self
._visualMenu
.AppendMenu(wx
.ID_ANY
, "Tabs Style", styleMenu
)
189 item
= wx
.MenuItem(self
._visualMenu
, MENU_SELECT_GRADIENT_COLOR_FROM
, "Select fancy tab style 'from' color",
190 "Select fancy tab style 'from' color")
191 self
._visualMenu
.AppendItem(item
)
193 item
= wx
.MenuItem(self
._visualMenu
, MENU_SELECT_GRADIENT_COLOR_TO
, "Select fancy tab style 'to' color",
194 "Select fancy tab style 'to' color")
195 self
._visualMenu
.AppendItem(item
)
197 item
= wx
.MenuItem(self
._visualMenu
, MENU_SELECT_GRADIENT_COLOR_BORDER
, "Select fancy tab style 'border' color",
198 "Select fancy tab style 'border' color")
199 self
._visualMenu
.AppendItem(item
)
201 self
._editMenu
.AppendSeparator()
203 self
.Bind(wx
.EVT_MENU_RANGE
, self
.OnSelectColor
, id=MENU_SELECT_GRADIENT_COLOR_FROM
,
204 id2
=MENU_SELECT_GRADIENT_COLOR_BORDER
)
206 item
= wx
.MenuItem(self
._editMenu
, MENU_HIDE_ON_SINGLE_TAB
, "Hide Page Container when only one Tab",
207 "Hide Page Container when only one Tab", wx
.ITEM_CHECK
)
208 self
.Bind(wx
.EVT_MENU
, self
.OnStyle
, item
)
209 self
._editMenu
.AppendItem(item
)
211 item
= wx
.MenuItem(self
._editMenu
, MENU_HIDE_NAV_BUTTONS
, "Hide Navigation Buttons",
212 "Hide Navigation Buttons", wx
.ITEM_CHECK
)
213 self
._editMenu
.AppendItem(item
)
215 item
= wx
.MenuItem(self
._editMenu
, MENU_HIDE_X
, "Hide X Button", "Hide X Button", wx
.ITEM_CHECK
)
216 self
._editMenu
.AppendItem(item
)
218 item
= wx
.MenuItem(self
._editMenu
, MENU_SMART_TABS
, "Smart tabbing", "Smart tabbing", wx
.ITEM_CHECK
)
219 self
._editMenu
.AppendItem(item
)
220 self
.Bind(wx
.EVT_MENU
, self
.OnSmartTabs
, item
)
223 item
= wx
.MenuItem(self
._editMenu
, MENU_USE_DROP_ARROW_BUTTON
, "Use drop down button for tab navigation",
224 "Use drop down arrow for quick tab navigation", wx
.ITEM_CHECK
)
225 self
._editMenu
.AppendItem(item
)
226 self
.Bind(wx
.EVT_MENU
, self
.OnDropDownArrow
, item
)
228 self
._editMenu
.AppendSeparator()
230 item
= wx
.MenuItem(self
._editMenu
, MENU_USE_MOUSE_MIDDLE_BTN
, "Use Mouse Middle Button as 'X' button",
231 "Use Mouse Middle Button as 'X' button", wx
.ITEM_CHECK
)
232 self
._editMenu
.AppendItem(item
)
234 item
= wx
.MenuItem(self
._editMenu
, MENU_DCLICK_CLOSES_TAB
, "Mouse double click closes tab",
235 "Mouse double click closes tab", wx
.ITEM_CHECK
)
236 self
.Bind(wx
.EVT_MENU
, self
.OnDClickCloseTab
, item
)
237 self
._editMenu
.AppendItem(item
)
240 self
._editMenu
.AppendSeparator()
242 item
= wx
.MenuItem(self
._editMenu
, MENU_USE_BOTTOM_TABS
, "Use Bottoms Tabs", "Use Bottoms Tabs",
244 self
._editMenu
.AppendItem(item
)
246 self
.Bind(wx
.EVT_MENU_RANGE
, self
.OnStyle
, id=MENU_HIDE_X
, id2
=MENU_USE_BOTTOM_TABS
)
248 item
= wx
.MenuItem(self
._editMenu
, MENU_ENABLE_TAB
, "Enable Tab", "Enable Tab")
249 self
.Bind(wx
.EVT_MENU
, self
.OnEnableTab
, item
)
250 self
._editMenu
.AppendItem(item
)
252 item
= wx
.MenuItem(self
._editMenu
, MENU_DISABLE_TAB
, "Disable Tab", "Disable Tab")
253 self
.Bind(wx
.EVT_MENU
, self
.OnDisableTab
, item
)
254 self
._editMenu
.AppendItem(item
)
256 item
= wx
.MenuItem(self
._editMenu
, MENU_ENABLE_DRAG_N_DROP
, "Enable Drag And Drop of Tabs",
257 "Enable Drag And Drop of Tabs", wx
.ITEM_CHECK
)
258 self
.Bind(wx
.EVT_MENU
, self
.OnEnableDrag
, item
)
259 self
._editMenu
.AppendItem(item
)
262 item
= wx
.MenuItem(self
._editMenu
, MENU_ALLOW_FOREIGN_DND
, "Enable Drag And Drop of Tabs from foreign notebooks",
263 "Enable Drag And Drop of Tabs from foreign notebooks", wx
.ITEM_CHECK
)
264 self
.Bind(wx
.EVT_MENU
, self
.OnAllowForeignDnd
, item
)
265 self
._editMenu
.AppendItem(item
)
268 item
= wx
.MenuItem(self
._visualMenu
, MENU_DRAW_BORDER
, "Draw Border around tab area",
269 "Draw Border around tab area", wx
.ITEM_CHECK
)
270 self
.Bind(wx
.EVT_MENU
, self
.OnStyle
, item
)
271 self
._visualMenu
.AppendItem(item
)
274 item
= wx
.MenuItem(self
._visualMenu
, MENU_DRAW_TAB_X
, "Draw X button On Active Tab",
275 "Draw X button On Active Tab", wx
.ITEM_CHECK
)
276 self
.Bind(wx
.EVT_MENU
, self
.OnDrawTabX
, item
)
277 self
._visualMenu
.AppendItem(item
)
279 item
= wx
.MenuItem(self
._visualMenu
, MENU_SET_ACTIVE_TAB_COLOR
, "Select Active Tab Color",
280 "Select Active Tab Color")
281 self
.Bind(wx
.EVT_MENU
, self
.OnSelectColor
, item
)
282 self
._visualMenu
.AppendItem(item
)
284 item
= wx
.MenuItem(self
._visualMenu
, MENU_SET_TAB_AREA_COLOR
, "Select Tab Area Color",
285 "Select Tab Area Color")
286 self
.Bind(wx
.EVT_MENU
, self
.OnSelectColor
, item
)
287 self
._visualMenu
.AppendItem(item
)
289 item
= wx
.MenuItem(self
._visualMenu
, MENU_SET_ACTIVE_TEXT_COLOR
, "Select active tab text color",
290 "Select 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_SELECT_NONACTIVE_TEXT_COLOR
,
295 "Select NON-active tab text color", "Select NON-active tab text color")
296 self
.Bind(wx
.EVT_MENU
, self
.OnSelectColor
, item
)
297 self
._visualMenu
.AppendItem(item
)
299 item
= wx
.MenuItem(self
._visualMenu
, MENU_GRADIENT_BACKGROUND
, "Use Gradient Coloring for tab area",
300 "Use Gradient Coloring for tab area", wx
.ITEM_CHECK
)
301 self
.Bind(wx
.EVT_MENU
, self
.OnGradientBack
, item
)
302 self
._visualMenu
.AppendItem(item
)
305 item
= wx
.MenuItem(self
._visualMenu
, MENU_COLORFUL_TABS
, "Colorful tabs", "Colorful tabs", wx
.ITEM_CHECK
)
306 self
.Bind(wx
.EVT_MENU
, self
.OnColorfulTabs
, item
)
307 self
._visualMenu
.AppendItem(item
)
310 help_menu
= wx
.Menu()
311 item
= wx
.MenuItem(help_menu
, wx
.ID_ANY
, "About...", "Shows The About Dialog")
312 self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, item
)
313 help_menu
.AppendItem(item
)
315 self
._menuBar
.Append(self
._fileMenu
, "&File")
316 self
._menuBar
.Append(self
._editMenu
, "&Edit")
317 self
._menuBar
.Append(self
._visualMenu
, "&Tab Appearance")
319 self
._menuBar
.Append(help_menu
, "&Help")
321 self
.SetMenuBar(self
._menuBar
)
324 def CreateRightClickMenu(self
):
326 self
._rmenu
= wx
.Menu()
327 item
= wx
.MenuItem(self
._rmenu
, MENU_EDIT_DELETE_PAGE
, "Close Tab\tCtrl+F4", "Close Tab")
328 self
._rmenu
.AppendItem(item
)
331 def LayoutItems(self
):
333 mainSizer
= wx
.BoxSizer(wx
.VERTICAL
)
334 self
.SetSizer(mainSizer
)
336 bookStyle
= fnb
.FNB_NODRAG
338 self
.book
= fnb
.FlatNotebook(self
, wx
.ID_ANY
, style
=bookStyle
)
340 bookStyle
&= ~
(fnb
.FNB_NODRAG
)
341 bookStyle |
= fnb
.FNB_ALLOW_FOREIGN_DND
342 self
.secondBook
= fnb
.FlatNotebook(self
, wx
.ID_ANY
, style
=bookStyle
)
344 # Set right click menu to the notebook
345 self
.book
.SetRightClickMenu(self
._rmenu
)
348 self
.book
.SetImageList(self
._ImageList
)
349 mainSizer
.Add(self
.book
, 6, wx
.EXPAND
)
351 # Add spacer between the books
352 spacer
= wx
.Panel(self
, -1)
353 spacer
.SetBackgroundColour(wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_3DFACE
))
354 mainSizer
.Add(spacer
, 0, wx
.ALL | wx
.EXPAND
)
356 mainSizer
.Add(self
.secondBook
, 2, wx
.EXPAND
)
358 # Add some pages to the second notebook
361 text
= wx
.TextCtrl(self
.secondBook
, -1, "Second Book Page 1\n", style
=wx
.TE_MULTILINE|wx
.TE_READONLY
)
362 self
.secondBook
.AddPage(text
, "Second Book Page 1")
364 text
= wx
.TextCtrl(self
.secondBook
, -1, "Second Book Page 2\n", style
=wx
.TE_MULTILINE|wx
.TE_READONLY
)
365 self
.secondBook
.AddPage(text
, "Second Book Page 2")
373 def OnStyle(self
, event
):
375 style
= self
.book
.GetWindowStyleFlag()
376 eventid
= event
.GetId()
378 if eventid
== MENU_HIDE_NAV_BUTTONS
:
379 if event
.IsChecked():
380 # Hide the navigation buttons
381 style |
= fnb
.FNB_NO_NAV_BUTTONS
383 style
&= ~fnb
.FNB_NO_NAV_BUTTONS
384 style
&= ~fnb
.FNB_DROPDOWN_TABS_LIST
386 self
.book
.SetWindowStyleFlag(style
)
388 elif eventid
== MENU_HIDE_ON_SINGLE_TAB
:
389 if event
.IsChecked():
390 # Hide the navigation buttons
391 style |
= fnb
.FNB_HIDE_ON_SINGLE_TAB
393 style
&= ~
(fnb
.FNB_HIDE_ON_SINGLE_TAB
)
395 self
.book
.SetWindowStyleFlag(style
)
397 elif eventid
== MENU_HIDE_X
:
398 if event
.IsChecked():
400 style |
= fnb
.FNB_NO_X_BUTTON
402 if style
& fnb
.FNB_NO_X_BUTTON
:
403 style ^
= fnb
.FNB_NO_X_BUTTON
405 self
.book
.SetWindowStyleFlag(style
)
407 elif eventid
== MENU_DRAW_BORDER
:
408 if event
.IsChecked():
409 style |
= fnb
.FNB_TABS_BORDER_SIMPLE
411 if style
& fnb
.FNB_TABS_BORDER_SIMPLE
:
412 style ^
= fnb
.FNB_TABS_BORDER_SIMPLE
414 self
.book
.SetWindowStyleFlag(style
)
416 elif eventid
== MENU_USE_MOUSE_MIDDLE_BTN
:
417 if event
.IsChecked():
418 style |
= fnb
.FNB_MOUSE_MIDDLE_CLOSES_TABS
420 if style
& fnb
.FNB_MOUSE_MIDDLE_CLOSES_TABS
:
421 style ^
= fnb
.FNB_MOUSE_MIDDLE_CLOSES_TABS
423 self
.book
.SetWindowStyleFlag(style
)
425 elif eventid
== MENU_USE_BOTTOM_TABS
:
426 if event
.IsChecked():
427 style |
= fnb
.FNB_BOTTOM
429 if style
& fnb
.FNB_BOTTOM
:
430 style ^
= fnb
.FNB_BOTTOM
432 self
.book
.SetWindowStyleFlag(style
)
436 def OnQuit(self
, event
):
441 def OnDeleteAll(self
, event
):
443 self
.book
.DeleteAllPages()
446 def OnShowImages(self
, event
):
448 self
._bShowImages
= event
.IsChecked()
451 def OnFF2Style(self
, event
):
453 style
= self
.book
.GetWindowStyleFlag()
455 # remove old tabs style
456 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS | fnb
.FNB_FF2
)
461 self
.book
.SetWindowStyleFlag(style
)
464 def OnVC71Style(self
, event
):
466 style
= self
.book
.GetWindowStyleFlag()
468 # remove old tabs style
469 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS | fnb
.FNB_FF2
)
472 style |
= fnb
.FNB_VC71
474 self
.book
.SetWindowStyleFlag(style
)
477 def OnVC8Style(self
, event
):
479 style
= self
.book
.GetWindowStyleFlag()
481 # remove old tabs style
482 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS | fnb
.FNB_FF2
)
488 self
.book
.SetWindowStyleFlag(style
)
491 def OnDefaultStyle(self
, event
):
493 style
= self
.book
.GetWindowStyleFlag()
495 # remove old tabs style
496 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS | fnb
.FNB_FF2
)
499 self
.book
.SetWindowStyleFlag(style
)
502 def OnFancyStyle(self
, event
):
504 style
= self
.book
.GetWindowStyleFlag()
506 # remove old tabs style
507 mirror
= ~
(fnb
.FNB_VC71 | fnb
.FNB_VC8 | fnb
.FNB_FANCY_TABS | fnb
.FNB_FF2
)
510 style |
= fnb
.FNB_FANCY_TABS
511 self
.book
.SetWindowStyleFlag(style
)
514 def OnSelectColor(self
, event
):
516 eventid
= event
.GetId()
518 # Open a color dialog
519 data
= wx
.ColourData()
521 dlg
= wx
.ColourDialog(self
, data
)
523 if dlg
.ShowModal() == wx
.ID_OK
:
525 if eventid
== MENU_SELECT_GRADIENT_COLOR_BORDER
:
526 self
.book
.SetGradientColourBorder(dlg
.GetColourData().GetColour())
527 elif eventid
== MENU_SELECT_GRADIENT_COLOR_FROM
:
528 self
.book
.SetGradientColourFrom(dlg
.GetColourData().GetColour())
529 elif eventid
== MENU_SELECT_GRADIENT_COLOR_TO
:
530 self
.book
.SetGradientColourTo(dlg
.GetColourData().GetColour())
531 elif eventid
== MENU_SET_ACTIVE_TEXT_COLOR
:
532 self
.book
.SetActiveTabTextColour(dlg
.GetColourData().GetColour())
533 elif eventid
== MENU_SELECT_NONACTIVE_TEXT_COLOR
:
534 self
.book
.SetNonActiveTabTextColour(dlg
.GetColourData().GetColour())
535 elif eventid
== MENU_SET_ACTIVE_TAB_COLOR
:
536 self
.book
.SetActiveTabColour(dlg
.GetColourData().GetColour())
537 elif eventid
== MENU_SET_TAB_AREA_COLOR
:
538 self
.book
.SetTabAreaColour(dlg
.GetColourData().GetColour())
543 def OnAddPage(self
, event
):
545 caption
= "New Page Added #" + str(self
._newPageCounter
)
550 if self
._bShowImages
:
551 image
= random
.randint(0, self
._ImageList
.GetImageCount()-1)
553 self
.book
.AddPage(self
.CreatePage(caption
), caption
, True, image
)
555 self
._newPageCounter
= self
._newPageCounter
+ 1
558 def CreatePage(self
, caption
):
560 p
= wx
.Panel(self
.book
)
561 wx
.StaticText(p
, -1, caption
, (20,20))
562 wx
.TextCtrl(p
, -1, "", (20,40), (150,-1))
566 def OnDeletePage(self
, event
):
568 self
.book
.DeletePage(self
.book
.GetSelection())
571 def OnSetSelection(self
, event
):
573 dlg
= wx
.TextEntryDialog(self
, "Enter Tab Number to select:", "Set Selection")
575 if dlg
.ShowModal() == wx
.ID_OK
:
578 self
.book
.SetSelection(int(val
))
581 def OnEnableTab(self
, event
):
583 dlg
= wx
.TextEntryDialog(self
, "Enter Tab Number to enable:", "Enable Tab")
585 if dlg
.ShowModal() == wx
.ID_OK
:
588 self
.book
.Enable(int(val
))
591 def OnDisableTab(self
, event
):
593 dlg
= wx
.TextEntryDialog(self
, "Enter Tab Number to disable:", "Disable Tab")
595 if dlg
.ShowModal() == wx
.ID_OK
:
598 self
.book
.Enable(int(val
), False)
601 def OnEnableDrag(self
, event
):
603 style
= self
.book
.GetWindowStyleFlag()
604 style2
= self
.secondBook
.GetWindowStyleFlag()
606 if event
.IsChecked():
607 if style
& fnb
.FNB_NODRAG
:
608 style ^
= fnb
.FNB_NODRAG
609 if style2
& fnb
.FNB_NODRAG
:
610 style2 ^
= fnb
.FNB_NODRAG
612 style |
= fnb
.FNB_NODRAG
613 style2 |
= fnb
.FNB_NODRAG
615 self
.book
.SetWindowStyleFlag(style
)
616 self
.secondBook
.SetWindowStyleFlag(style2
)
619 def OnAllowForeignDnd(self
, event
):
621 style
= self
.book
.GetWindowStyleFlag()
622 if event
.IsChecked():
623 style |
= fnb
.FNB_ALLOW_FOREIGN_DND
625 style
&= ~
(fnb
.FNB_ALLOW_FOREIGN_DND
)
627 self
.book
.SetWindowStyleFlag(style
)
631 def OnSetAllPagesShapeAngle(self
, event
):
634 dlg
= wx
.TextEntryDialog(self
, "Enter an inclination of header borders (0-15):", "Set Angle")
635 if dlg
.ShowModal() == wx
.ID_OK
:
638 self
.book
.SetAllPagesShapeAngle(int(val
))
641 def OnSetPageImage(self
, event
):
643 dlg
= wx
.TextEntryDialog(self
, "Enter an image index (0-%i):"%(self
.book
.GetImageList().GetImageCount()-1), "Set Image Index")
644 if dlg
.ShowModal() == wx
.ID_OK
:
646 self
.book
.SetPageImage(self
.book
.GetSelection(), int(val
))
649 def OnAdvanceSelectionFwd(self
, event
):
651 self
.book
.AdvanceSelection(True)
654 def OnAdvanceSelectionBack(self
, event
):
656 self
.book
.AdvanceSelection(False)
659 def OnPageChanging(self
, event
):
661 self
.log
.write("Page Changing From %d To %d" % (event
.GetOldSelection(), event
.GetSelection()))
665 def OnPageChanged(self
, event
):
667 self
.log
.write("Page Changed To %d" % event
.GetSelection())
671 def OnPageClosing(self
, event
):
673 self
.log
.write("Page Closing, Selection: %d" % event
.GetSelection())
677 def OnDrawTabX(self
, event
):
679 style
= self
.book
.GetWindowStyleFlag()
680 if event
.IsChecked():
681 style |
= fnb
.FNB_X_ON_TAB
683 if style
& fnb
.FNB_X_ON_TAB
:
684 style ^
= fnb
.FNB_X_ON_TAB
686 self
.book
.SetWindowStyleFlag(style
)
689 def OnDClickCloseTab(self
, event
):
691 style
= self
.book
.GetWindowStyleFlag()
692 if event
.IsChecked():
693 style |
= fnb
.FNB_DCLICK_CLOSES_TABS
695 style
&= ~
(fnb
.FNB_DCLICK_CLOSES_TABS
)
697 self
.book
.SetWindowStyleFlag(style
)
700 def OnGradientBack(self
, event
):
702 style
= self
.book
.GetWindowStyleFlag()
703 if event
.IsChecked():
704 style |
= fnb
.FNB_BACKGROUND_GRADIENT
706 style
&= ~
(fnb
.FNB_BACKGROUND_GRADIENT
)
708 self
.book
.SetWindowStyleFlag(style
)
712 def OnColorfulTabs(self
, event
):
714 style
= self
.book
.GetWindowStyleFlag()
715 if event
.IsChecked():
716 style |
= fnb
.FNB_COLORFUL_TABS
718 style
&= ~
(fnb
.FNB_COLORFUL_TABS
)
720 self
.book
.SetWindowStyleFlag(style
)
724 def OnSmartTabs(self
, event
):
726 style
= self
.book
.GetWindowStyleFlag()
727 if event
.IsChecked():
728 style |
= fnb
.FNB_SMART_TABS
730 style
&= ~fnb
.FNB_SMART_TABS
732 self
.book
.SetWindowStyleFlag(style
)
736 def OnDropDownArrow(self
, event
):
738 style
= self
.book
.GetWindowStyleFlag()
740 if event
.IsChecked():
742 style |
= fnb
.FNB_DROPDOWN_TABS_LIST
743 style |
= fnb
.FNB_NO_NAV_BUTTONS
747 style
&= ~fnb
.FNB_DROPDOWN_TABS_LIST
748 style
&= ~fnb
.FNB_NO_NAV_BUTTONS
750 self
.book
.SetWindowStyleFlag(style
)
754 def OnHideNavigationButtonsUI(self
, event
):
756 style
= self
.book
.GetWindowStyleFlag()
757 event
.Check((style
& fnb
.FNB_NO_NAV_BUTTONS
and [True] or [False])[0])
760 def OnDropDownArrowUI(self
, event
):
762 style
= self
.book
.GetWindowStyleFlag()
763 event
.Check((style
& fnb
.FNB_DROPDOWN_TABS_LIST
and [True] or [False])[0])
766 def OnAllowForeignDndUI(self
, event
):
768 style
= self
.book
.GetWindowStyleFlag()
769 event
.Enable((style
& fnb
.FNB_NODRAG
and [False] or [True])[0])
772 def OnAbout(self
, event
):
774 msg
= "This Is The About Dialog Of The FlatNotebook Demo.\n\n" + \
775 "Author: Andrea Gavana @ 02 Oct 2006\n\n" + \
776 "Please Report Any Bug/Requests Of Improvements\n" + \
777 "To Me At The Following Adresses:\n\n" + \
778 "andrea.gavana@gmail.com\n" + "gavana@kpo.kz\n\n" + \
779 "Based On Eran C++ Implementation (wxWidgets Forum).\n\n" + \
780 "Welcome To wxPython " + wx
.VERSION_STRING
+ "!!"
782 dlg
= wx
.MessageDialog(self
, msg
, "FlatNotebook wxPython Demo",
783 wx
.OK | wx
.ICON_INFORMATION
)
788 #---------------------------------------------------------------------------
791 class TestPanel(wx
.Panel
):
792 def __init__(self
, parent
, log
):
794 wx
.Panel
.__init
__(self
, parent
, -1)
796 b
= wx
.Button(self
, -1, " Test FlatNotebook ", (50,50))
797 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
)
800 def OnButton(self
, evt
):
801 self
.win
= FlatNotebookDemo(self
, self
.log
)
804 #----------------------------------------------------------------------
806 def runTest(frame
, nb
, log
):
807 win
= TestPanel(nb
, log
)
810 #----------------------------------------------------------------------
813 overview
= fnb
.__doc
__
817 if __name__
== '__main__':
820 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])