]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/FlatNotebook.py
Register the test under the name displayed by "./test -l"
[wxWidgets.git] / wxPython / demo / FlatNotebook.py
CommitLineData
6cb4f153
RD
1import wx
2import wx.lib.flatnotebook as fnb
3import random
4import images
5
6a64d551 6
6cb4f153
RD
7#----------------------------------------------------------------------
8def GetMondrianData():
9 return \
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\
12ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\
13o\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'
17
18
19def GetMondrianBitmap():
20 return wx.BitmapFromImage(GetMondrianImage())
21
22
23def GetMondrianImage():
24 import cStringIO
25 stream = cStringIO.StringIO(GetMondrianData())
26 return wx.ImageFromStream(stream)
27
28
29def GetMondrianIcon():
30 icon = wx.EmptyIcon()
31 icon.CopyFromBitmap(GetMondrianBitmap())
32 return icon
33#----------------------------------------------------------------------
34
35
6a64d551
RD
36MENU_EDIT_DELETE_ALL = wx.NewId()
37MENU_EDIT_ADD_PAGE = wx.NewId()
38MENU_EDIT_DELETE_PAGE = wx.NewId()
39MENU_EDIT_SET_SELECTION = wx.NewId()
40MENU_EDIT_ADVANCE_SELECTION_FWD = wx.NewId()
41MENU_EDIT_ADVANCE_SELECTION_BACK = wx.NewId()
42MENU_SET_ALL_TABS_SHAPE_ANGLE = wx.NewId()
43MENU_SHOW_IMAGES = wx.NewId()
44MENU_USE_VC71_STYLE = wx.NewId()
45MENU_USE_DEFAULT_STYLE = wx.NewId()
46MENU_USE_FANCY_STYLE = wx.NewId()
47MENU_SELECT_GRADIENT_COLOR_FROM = wx.NewId()
48MENU_SELECT_GRADIENT_COLOR_TO = wx.NewId()
49MENU_SELECT_GRADIENT_COLOR_BORDER = wx.NewId()
50MENU_SET_PAGE_IMAGE_INDEX = wx.NewId()
51MENU_HIDE_X = wx.NewId()
52MENU_HIDE_NAV_BUTTONS = wx.NewId()
53MENU_USE_MOUSE_MIDDLE_BTN = wx.NewId()
54MENU_DRAW_BORDER = wx.NewId()
55MENU_USE_BOTTOM_TABS = wx.NewId()
56MENU_ENABLE_TAB = wx.NewId()
57MENU_DISABLE_TAB = wx.NewId()
58MENU_ENABLE_DRAG_N_DROP = wx.NewId()
59MENU_DCLICK_CLOSES_TAB = wx.NewId()
60MENU_USE_VC8_STYLE = wx.NewId()
5cc18d79 61MENU_USE_FF2_STYLE = wx.NewId()
37938059 62MENU_HIDE_ON_SINGLE_TAB = wx.NewId()
6a64d551
RD
63
64MENU_SET_ACTIVE_TEXT_COLOR = wx.NewId()
65MENU_DRAW_TAB_X = wx.NewId()
66MENU_SET_ACTIVE_TAB_COLOR = wx.NewId()
67MENU_SET_TAB_AREA_COLOR = wx.NewId()
68MENU_SELECT_NONACTIVE_TEXT_COLOR = wx.NewId()
69MENU_GRADIENT_BACKGROUND = wx.NewId()
70MENU_COLORFUL_TABS = wx.NewId()
71MENU_SMART_TABS = wx.NewId()
72MENU_USE_DROP_ARROW_BUTTON = wx.NewId()
73MENU_ALLOW_FOREIGN_DND = wx.NewId()
6cb4f153
RD
74
75
76class FlatNotebookDemo(wx.Frame):
77
75c39820 78 def __init__(self, parent, log):
6cb4f153 79
75c39820
RD
80 wx.Frame.__init__(self, parent, title="FlatNotebook Demo", size=(800,600))
81 self.log = log
6a64d551 82
6cb4f153
RD
83 self._bShowImages = False
84 self._bVCStyle = False
85 self._newPageCounter = 0
86
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())
91
92 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
93 self.statusbar.SetStatusWidths([-2, -1])
94 # statusbar fields
95 statusbar_fields = [("FlatNotebook wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
96 ("Welcome To wxPython!")]
97
98 for i in range(len(statusbar_fields)):
99 self.statusbar.SetStatusText(statusbar_fields[i], i)
100
101 self.SetIcon(GetMondrianIcon())
102 self.CreateMenuBar()
103 self.CreateRightClickMenu()
104 self.LayoutItems()
105
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)
109
6a64d551
RD
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)
6cb4f153
RD
113
114
115 def CreateMenuBar(self):
116
117 self._menuBar = wx.MenuBar(wx.MB_DOCKABLE)
118 self._fileMenu = wx.Menu()
6a64d551
RD
119 self._editMenu = wx.Menu()
120 self._visualMenu = wx.Menu()
121
6cb4f153
RD
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)
6a64d551 125
6cb4f153
RD
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)
129
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)
133
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)
137
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)
141
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)
146
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)
151
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)
6a64d551 155 self._visualMenu.AppendItem(item)
6cb4f153
RD
156
157 item = wx.MenuItem(self._editMenu, MENU_SET_PAGE_IMAGE_INDEX, "Set image index of selected page",
158 "Set image index")
6a64d551 159 self.Bind(wx.EVT_MENU, self.OnSetPageImage, item)
6cb4f153
RD
160 self._editMenu.AppendItem(item)
161
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)
165
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)
170
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)
174
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)
178
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)
182
5cc18d79
RD
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)
186
6a64d551 187 self._visualMenu.AppendMenu(wx.ID_ANY, "Tabs Style", styleMenu)
6cb4f153 188
6a64d551 189 item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_FROM, "Select fancy tab style 'from' color",
6cb4f153 190 "Select fancy tab style 'from' color")
6a64d551 191 self._visualMenu.AppendItem(item)
6cb4f153 192
6a64d551 193 item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_TO, "Select fancy tab style 'to' color",
6cb4f153 194 "Select fancy tab style 'to' color")
6a64d551 195 self._visualMenu.AppendItem(item)
6cb4f153 196
6a64d551 197 item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_BORDER, "Select fancy tab style 'border' color",
6cb4f153 198 "Select fancy tab style 'border' color")
6a64d551
RD
199 self._visualMenu.AppendItem(item)
200
201 self._editMenu.AppendSeparator()
6cb4f153
RD
202
203 self.Bind(wx.EVT_MENU_RANGE, self.OnSelectColor, id=MENU_SELECT_GRADIENT_COLOR_FROM,
204 id2=MENU_SELECT_GRADIENT_COLOR_BORDER)
205
37938059
RD
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)
210
6cb4f153
RD
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)
214
215 item = wx.MenuItem(self._editMenu, MENU_HIDE_X, "Hide X Button", "Hide X Button", wx.ITEM_CHECK)
216 self._editMenu.AppendItem(item)
217
6a64d551
RD
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)
221 item.Check(False)
222
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)
227 item.Check(False);
228 self._editMenu.AppendSeparator()
229
6cb4f153
RD
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)
233
6a64d551
RD
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)
238 item.Check(False)
239
240 self._editMenu.AppendSeparator()
241
6cb4f153
RD
242 item = wx.MenuItem(self._editMenu, MENU_USE_BOTTOM_TABS, "Use Bottoms Tabs", "Use Bottoms Tabs",
243 wx.ITEM_CHECK)
244 self._editMenu.AppendItem(item)
245
246 self.Bind(wx.EVT_MENU_RANGE, self.OnStyle, id=MENU_HIDE_X, id2=MENU_USE_BOTTOM_TABS)
247
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)
251
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)
255
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)
6a64d551 260 item.Check(False)
6cb4f153 261
6a64d551
RD
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)
266 item.Check(False);
267
268 item = wx.MenuItem(self._visualMenu, MENU_DRAW_BORDER, "Draw Border around tab area",
6cb4f153
RD
269 "Draw Border around tab area", wx.ITEM_CHECK)
270 self.Bind(wx.EVT_MENU, self.OnStyle, item)
6a64d551 271 self._visualMenu.AppendItem(item)
6cb4f153
RD
272 item.Check(True)
273
6a64d551 274 item = wx.MenuItem(self._visualMenu, MENU_DRAW_TAB_X, "Draw X button On Active Tab",
6cb4f153
RD
275 "Draw X button On Active Tab", wx.ITEM_CHECK)
276 self.Bind(wx.EVT_MENU, self.OnDrawTabX, item)
6a64d551 277 self._visualMenu.AppendItem(item)
6cb4f153 278
6a64d551 279 item = wx.MenuItem(self._visualMenu, MENU_SET_ACTIVE_TAB_COLOR, "Select Active Tab Color",
6cb4f153
RD
280 "Select Active Tab Color")
281 self.Bind(wx.EVT_MENU, self.OnSelectColor, item)
6a64d551 282 self._visualMenu.AppendItem(item)
6cb4f153 283
6a64d551 284 item = wx.MenuItem(self._visualMenu, MENU_SET_TAB_AREA_COLOR, "Select Tab Area Color",
6cb4f153
RD
285 "Select Tab Area Color")
286 self.Bind(wx.EVT_MENU, self.OnSelectColor, item)
6a64d551 287 self._visualMenu.AppendItem(item)
6cb4f153 288
6a64d551 289 item = wx.MenuItem(self._visualMenu, MENU_SET_ACTIVE_TEXT_COLOR, "Select active tab text color",
6cb4f153
RD
290 "Select active tab text color")
291 self.Bind(wx.EVT_MENU, self.OnSelectColor, item)
6a64d551 292 self._visualMenu.AppendItem(item)
6cb4f153 293
6a64d551 294 item = wx.MenuItem(self._visualMenu, MENU_SELECT_NONACTIVE_TEXT_COLOR,
6cb4f153
RD
295 "Select NON-active tab text color", "Select NON-active tab text color")
296 self.Bind(wx.EVT_MENU, self.OnSelectColor, item)
6a64d551 297 self._visualMenu.AppendItem(item)
6cb4f153 298
6a64d551 299 item = wx.MenuItem(self._visualMenu, MENU_GRADIENT_BACKGROUND, "Use Gradient Coloring for tab area",
6cb4f153
RD
300 "Use Gradient Coloring for tab area", wx.ITEM_CHECK)
301 self.Bind(wx.EVT_MENU, self.OnGradientBack, item)
6a64d551 302 self._visualMenu.AppendItem(item)
6cb4f153
RD
303 item.Check(False)
304
6a64d551 305 item = wx.MenuItem(self._visualMenu, MENU_COLORFUL_TABS, "Colorful tabs", "Colorful tabs", wx.ITEM_CHECK)
6cb4f153 306 self.Bind(wx.EVT_MENU, self.OnColorfulTabs, item)
6a64d551 307 self._visualMenu.AppendItem(item)
6cb4f153
RD
308 item.Check(False)
309
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)
314
315 self._menuBar.Append(self._fileMenu, "&File")
316 self._menuBar.Append(self._editMenu, "&Edit")
6a64d551
RD
317 self._menuBar.Append(self._visualMenu, "&Tab Appearance")
318
6cb4f153
RD
319 self._menuBar.Append(help_menu, "&Help")
320
321 self.SetMenuBar(self._menuBar)
322
323
324 def CreateRightClickMenu(self):
325
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)
329
330
331 def LayoutItems(self):
332
333 mainSizer = wx.BoxSizer(wx.VERTICAL)
334 self.SetSizer(mainSizer)
335
6a64d551
RD
336 bookStyle = fnb.FNB_NODRAG
337
338 self.book = fnb.FlatNotebook(self, wx.ID_ANY, style=bookStyle)
6cb4f153 339
6a64d551
RD
340 bookStyle &= ~(fnb.FNB_NODRAG)
341 bookStyle |= fnb.FNB_ALLOW_FOREIGN_DND
342 self.secondBook = fnb.FlatNotebook(self, wx.ID_ANY, style=bookStyle)
6cb4f153
RD
343
344 # Set right click menu to the notebook
345 self.book.SetRightClickMenu(self._rmenu)
346
347 # Set the image list
348 self.book.SetImageList(self._ImageList)
349 mainSizer.Add(self.book, 6, wx.EXPAND)
350
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)
355
356 mainSizer.Add(self.secondBook, 2, wx.EXPAND)
357
358 # Add some pages to the second notebook
359 self.Freeze()
360
6a64d551 361 text = wx.TextCtrl(self.secondBook, -1, "Second Book Page 1\n", style=wx.TE_MULTILINE|wx.TE_READONLY)
6cb4f153
RD
362 self.secondBook.AddPage(text, "Second Book Page 1")
363
6a64d551 364 text = wx.TextCtrl(self.secondBook, -1, "Second Book Page 2\n", style=wx.TE_MULTILINE|wx.TE_READONLY)
6cb4f153
RD
365 self.secondBook.AddPage(text, "Second Book Page 2")
366
367 self.Thaw()
368
6cb4f153
RD
369 mainSizer.Layout()
370 self.SendSizeEvent()
371
372
373 def OnStyle(self, event):
374
375 style = self.book.GetWindowStyleFlag()
376 eventid = event.GetId()
377
378 if eventid == MENU_HIDE_NAV_BUTTONS:
379 if event.IsChecked():
380 # Hide the navigation buttons
381 style |= fnb.FNB_NO_NAV_BUTTONS
382 else:
6a64d551
RD
383 style &= ~fnb.FNB_NO_NAV_BUTTONS
384 style &= ~fnb.FNB_DROPDOWN_TABS_LIST
6cb4f153
RD
385
386 self.book.SetWindowStyleFlag(style)
387
37938059
RD
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
392 else:
393 style &= ~(fnb.FNB_HIDE_ON_SINGLE_TAB)
394
395 self.book.SetWindowStyleFlag(style)
396
6cb4f153
RD
397 elif eventid == MENU_HIDE_X:
398 if event.IsChecked():
399 # Hide the X button
400 style |= fnb.FNB_NO_X_BUTTON
401 else:
402 if style & fnb.FNB_NO_X_BUTTON:
403 style ^= fnb.FNB_NO_X_BUTTON
404
405 self.book.SetWindowStyleFlag(style)
406
407 elif eventid == MENU_DRAW_BORDER:
408 if event.IsChecked():
409 style |= fnb.FNB_TABS_BORDER_SIMPLE
410 else:
411 if style & fnb.FNB_TABS_BORDER_SIMPLE:
412 style ^= fnb.FNB_TABS_BORDER_SIMPLE
413
414 self.book.SetWindowStyleFlag(style)
415
416 elif eventid == MENU_USE_MOUSE_MIDDLE_BTN:
417 if event.IsChecked():
418 style |= fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS
419 else:
420 if style & fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS:
421 style ^= fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS
422
423 self.book.SetWindowStyleFlag(style)
424
425 elif eventid == MENU_USE_BOTTOM_TABS:
426 if event.IsChecked():
427 style |= fnb.FNB_BOTTOM
428 else:
429 if style & fnb.FNB_BOTTOM:
430 style ^= fnb.FNB_BOTTOM
431
432 self.book.SetWindowStyleFlag(style)
433 self.book.Refresh()
434
435
436 def OnQuit(self, event):
437
438 self.Destroy()
439
440
441 def OnDeleteAll(self, event):
442
443 self.book.DeleteAllPages()
444
445
446 def OnShowImages(self, event):
447
448 self._bShowImages = event.IsChecked()
449
450
5cc18d79
RD
451 def OnFF2Style(self, event):
452
453 style = self.book.GetWindowStyleFlag()
454
455 # remove old tabs style
456 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS | fnb.FNB_FF2)
457 style &= mirror
458
459 style |= fnb.FNB_FF2
460
461 self.book.SetWindowStyleFlag(style)
462
463
6cb4f153
RD
464 def OnVC71Style(self, event):
465
466 style = self.book.GetWindowStyleFlag()
467
468 # remove old tabs style
5cc18d79 469 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS | fnb.FNB_FF2)
6cb4f153
RD
470 style &= mirror
471
472 style |= fnb.FNB_VC71
473
474 self.book.SetWindowStyleFlag(style)
475
476
477 def OnVC8Style(self, event):
478
479 style = self.book.GetWindowStyleFlag()
480
481 # remove old tabs style
5cc18d79 482 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS | fnb.FNB_FF2)
6cb4f153
RD
483 style &= mirror
484
485 # set new style
486 style |= fnb.FNB_VC8
487
488 self.book.SetWindowStyleFlag(style)
489
490
491 def OnDefaultStyle(self, event):
492
493 style = self.book.GetWindowStyleFlag()
494
495 # remove old tabs style
5cc18d79 496 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS | fnb.FNB_FF2)
6cb4f153
RD
497 style &= mirror
498
499 self.book.SetWindowStyleFlag(style)
500
501
502 def OnFancyStyle(self, event):
503
504 style = self.book.GetWindowStyleFlag()
505
506 # remove old tabs style
5cc18d79 507 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS | fnb.FNB_FF2)
6cb4f153
RD
508 style &= mirror
509
510 style |= fnb.FNB_FANCY_TABS
511 self.book.SetWindowStyleFlag(style)
512
513
514 def OnSelectColor(self, event):
515
516 eventid = event.GetId()
517
518 # Open a color dialog
519 data = wx.ColourData()
520
521 dlg = wx.ColourDialog(self, data)
522
523 if dlg.ShowModal() == wx.ID_OK:
524
525 if eventid == MENU_SELECT_GRADIENT_COLOR_BORDER:
6a64d551 526 self.book.SetGradientColourBorder(dlg.GetColourData().GetColour())
6cb4f153 527 elif eventid == MENU_SELECT_GRADIENT_COLOR_FROM:
6a64d551 528 self.book.SetGradientColourFrom(dlg.GetColourData().GetColour())
6cb4f153 529 elif eventid == MENU_SELECT_GRADIENT_COLOR_TO:
6a64d551 530 self.book.SetGradientColourTo(dlg.GetColourData().GetColour())
6cb4f153
RD
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())
539
540 self.book.Refresh()
541
542
543 def OnAddPage(self, event):
544
545 caption = "New Page Added #" + str(self._newPageCounter)
546
547 self.Freeze()
548
549 image = -1
550 if self._bShowImages:
551 image = random.randint(0, self._ImageList.GetImageCount()-1)
552
553 self.book.AddPage(self.CreatePage(caption), caption, True, image)
6cb4f153
RD
554 self.Thaw()
555 self._newPageCounter = self._newPageCounter + 1
556
557
558 def CreatePage(self, caption):
559
75c39820
RD
560 p = wx.Panel(self.book)
561 wx.StaticText(p, -1, caption, (20,20))
562 wx.TextCtrl(p, -1, "", (20,40), (150,-1))
75c39820 563 return p
6cb4f153
RD
564
565
566 def OnDeletePage(self, event):
567
568 self.book.DeletePage(self.book.GetSelection())
569
570
571 def OnSetSelection(self, event):
572
573 dlg = wx.TextEntryDialog(self, "Enter Tab Number to select:", "Set Selection")
574
575 if dlg.ShowModal() == wx.ID_OK:
576
577 val = dlg.GetValue()
578 self.book.SetSelection(int(val))
579
580
581 def OnEnableTab(self, event):
582
583 dlg = wx.TextEntryDialog(self, "Enter Tab Number to enable:", "Enable Tab")
584
585 if dlg.ShowModal() == wx.ID_OK:
586
587 val = dlg.GetValue()
588 self.book.Enable(int(val))
589
590
591 def OnDisableTab(self, event):
592
593 dlg = wx.TextEntryDialog(self, "Enter Tab Number to disable:", "Disable Tab")
594
595 if dlg.ShowModal() == wx.ID_OK:
596
597 val = dlg.GetValue()
598 self.book.Enable(int(val), False)
599
600
601 def OnEnableDrag(self, event):
602
603 style = self.book.GetWindowStyleFlag()
6a64d551 604 style2 = self.secondBook.GetWindowStyleFlag()
6cb4f153
RD
605
606 if event.IsChecked():
607 if style & fnb.FNB_NODRAG:
608 style ^= fnb.FNB_NODRAG
6a64d551
RD
609 if style2 & fnb.FNB_NODRAG:
610 style2 ^= fnb.FNB_NODRAG
6cb4f153
RD
611 else:
612 style |= fnb.FNB_NODRAG
6a64d551 613 style2 |= fnb.FNB_NODRAG
6cb4f153
RD
614
615 self.book.SetWindowStyleFlag(style)
6a64d551 616 self.secondBook.SetWindowStyleFlag(style2)
6cb4f153
RD
617
618
6a64d551
RD
619 def OnAllowForeignDnd(self, event):
620
621 style = self.book.GetWindowStyleFlag()
622 if event.IsChecked():
623 style |= fnb.FNB_ALLOW_FOREIGN_DND
624 else:
625 style &= ~(fnb.FNB_ALLOW_FOREIGN_DND)
626
627 self.book.SetWindowStyleFlag(style)
628 self.book.Refresh()
629
630
6cb4f153
RD
631 def OnSetAllPagesShapeAngle(self, event):
632
633
6a64d551 634 dlg = wx.TextEntryDialog(self, "Enter an inclination of header borders (0-15):", "Set Angle")
6cb4f153
RD
635 if dlg.ShowModal() == wx.ID_OK:
636
637 val = dlg.GetValue()
638 self.book.SetAllPagesShapeAngle(int(val))
639
640
6a64d551 641 def OnSetPageImage(self, event):
6cb4f153
RD
642
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:
645 val = dlg.GetValue()
6a64d551 646 self.book.SetPageImage(self.book.GetSelection(), int(val))
6cb4f153
RD
647
648
649 def OnAdvanceSelectionFwd(self, event):
650
651 self.book.AdvanceSelection(True)
652
653
654 def OnAdvanceSelectionBack(self, event):
655
656 self.book.AdvanceSelection(False)
657
658
659 def OnPageChanging(self, event):
6a64d551 660
75c39820 661 self.log.write("Page Changing From %d To %d" % (event.GetOldSelection(), event.GetSelection()))
6cb4f153
RD
662 event.Skip()
663
664
665 def OnPageChanged(self, event):
6a64d551 666
75c39820 667 self.log.write("Page Changed To %d" % event.GetSelection())
6cb4f153
RD
668 event.Skip()
669
670
671 def OnPageClosing(self, event):
6a64d551 672
75c39820 673 self.log.write("Page Closing, Selection: %d" % event.GetSelection())
6cb4f153
RD
674 event.Skip()
675
676
677 def OnDrawTabX(self, event):
678
679 style = self.book.GetWindowStyleFlag()
680 if event.IsChecked():
681 style |= fnb.FNB_X_ON_TAB
682 else:
683 if style & fnb.FNB_X_ON_TAB:
684 style ^= fnb.FNB_X_ON_TAB
685
686 self.book.SetWindowStyleFlag(style)
687
688
689 def OnDClickCloseTab(self, event):
690
691 style = self.book.GetWindowStyleFlag()
692 if event.IsChecked():
693 style |= fnb.FNB_DCLICK_CLOSES_TABS
694 else:
695 style &= ~(fnb.FNB_DCLICK_CLOSES_TABS)
696
697 self.book.SetWindowStyleFlag(style)
698
699
700 def OnGradientBack(self, event):
701
702 style = self.book.GetWindowStyleFlag()
703 if event.IsChecked():
704 style |= fnb.FNB_BACKGROUND_GRADIENT
705 else:
706 style &= ~(fnb.FNB_BACKGROUND_GRADIENT)
707
708 self.book.SetWindowStyleFlag(style)
709 self.book.Refresh()
710
711
712 def OnColorfulTabs(self, event):
713
714 style = self.book.GetWindowStyleFlag()
715 if event.IsChecked():
716 style |= fnb.FNB_COLORFUL_TABS
717 else:
718 style &= ~(fnb.FNB_COLORFUL_TABS)
719
720 self.book.SetWindowStyleFlag(style)
721 self.book.Refresh()
722
723
6a64d551
RD
724 def OnSmartTabs(self, event):
725
726 style = self.book.GetWindowStyleFlag()
727 if event.IsChecked():
728 style |= fnb.FNB_SMART_TABS
729 else:
730 style &= ~fnb.FNB_SMART_TABS
731
732 self.book.SetWindowStyleFlag(style)
733 self.book.Refresh()
734
735
736 def OnDropDownArrow(self, event):
737
738 style = self.book.GetWindowStyleFlag()
739
740 if event.IsChecked():
741
742 style |= fnb.FNB_DROPDOWN_TABS_LIST
743 style |= fnb.FNB_NO_NAV_BUTTONS
744
745 else:
746
747 style &= ~fnb.FNB_DROPDOWN_TABS_LIST
748 style &= ~fnb.FNB_NO_NAV_BUTTONS
749
750 self.book.SetWindowStyleFlag(style)
751 self.book.Refresh()
752
753
754 def OnHideNavigationButtonsUI(self, event):
755
756 style = self.book.GetWindowStyleFlag()
757 event.Check((style & fnb.FNB_NO_NAV_BUTTONS and [True] or [False])[0])
758
759
760 def OnDropDownArrowUI(self, event):
761
762 style = self.book.GetWindowStyleFlag()
763 event.Check((style & fnb.FNB_DROPDOWN_TABS_LIST and [True] or [False])[0])
764
765
766 def OnAllowForeignDndUI(self, event):
767
768 style = self.book.GetWindowStyleFlag()
769 event.Enable((style & fnb.FNB_NODRAG and [False] or [True])[0])
770
771
6cb4f153
RD
772 def OnAbout(self, event):
773
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 + "!!"
781
782 dlg = wx.MessageDialog(self, msg, "FlatNotebook wxPython Demo",
783 wx.OK | wx.ICON_INFORMATION)
784 dlg.ShowModal()
785 dlg.Destroy()
786
787
788#---------------------------------------------------------------------------
789
790
791class TestPanel(wx.Panel):
792 def __init__(self, parent, log):
793 self.log = log
794 wx.Panel.__init__(self, parent, -1)
795
75c39820 796 b = wx.Button(self, -1, " Test FlatNotebook ", (50,50))
6cb4f153
RD
797 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
798
799
800 def OnButton(self, evt):
75c39820 801 self.win = FlatNotebookDemo(self, self.log)
6cb4f153
RD
802 self.win.Show(True)
803
804#----------------------------------------------------------------------
805
806def runTest(frame, nb, log):
807 win = TestPanel(nb, log)
808 return win
809
810#----------------------------------------------------------------------
811
812
979f2f9c 813overview = fnb.__doc__
6cb4f153
RD
814
815
816
817if __name__ == '__main__':
818 import sys,os
819 import run
820 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
821