]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/FlatNotebook.py
comment out test code
[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()
37938059 61MENU_HIDE_ON_SINGLE_TAB = wx.NewId()
6a64d551
RD
62
63MENU_SET_ACTIVE_TEXT_COLOR = wx.NewId()
64MENU_DRAW_TAB_X = wx.NewId()
65MENU_SET_ACTIVE_TAB_COLOR = wx.NewId()
66MENU_SET_TAB_AREA_COLOR = wx.NewId()
67MENU_SELECT_NONACTIVE_TEXT_COLOR = wx.NewId()
68MENU_GRADIENT_BACKGROUND = wx.NewId()
69MENU_COLORFUL_TABS = wx.NewId()
70MENU_SMART_TABS = wx.NewId()
71MENU_USE_DROP_ARROW_BUTTON = wx.NewId()
72MENU_ALLOW_FOREIGN_DND = wx.NewId()
6cb4f153
RD
73
74
75class FlatNotebookDemo(wx.Frame):
76
75c39820 77 def __init__(self, parent, log):
6cb4f153 78
75c39820
RD
79 wx.Frame.__init__(self, parent, title="FlatNotebook Demo", size=(800,600))
80 self.log = log
6a64d551 81
6cb4f153
RD
82 self._bShowImages = False
83 self._bVCStyle = False
84 self._newPageCounter = 0
85
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())
90
91 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
92 self.statusbar.SetStatusWidths([-2, -1])
93 # statusbar fields
94 statusbar_fields = [("FlatNotebook wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
95 ("Welcome To wxPython!")]
96
97 for i in range(len(statusbar_fields)):
98 self.statusbar.SetStatusText(statusbar_fields[i], i)
99
100 self.SetIcon(GetMondrianIcon())
101 self.CreateMenuBar()
102 self.CreateRightClickMenu()
103 self.LayoutItems()
104
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)
108
6a64d551
RD
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)
6cb4f153
RD
112
113
114 def CreateMenuBar(self):
115
116 self._menuBar = wx.MenuBar(wx.MB_DOCKABLE)
117 self._fileMenu = wx.Menu()
6a64d551
RD
118 self._editMenu = wx.Menu()
119 self._visualMenu = wx.Menu()
120
6cb4f153
RD
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)
6a64d551 124
6cb4f153
RD
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)
128
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)
132
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)
136
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)
140
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)
145
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)
150
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)
6a64d551 154 self._visualMenu.AppendItem(item)
6cb4f153
RD
155
156 item = wx.MenuItem(self._editMenu, MENU_SET_PAGE_IMAGE_INDEX, "Set image index of selected page",
157 "Set image index")
6a64d551 158 self.Bind(wx.EVT_MENU, self.OnSetPageImage, item)
6cb4f153
RD
159 self._editMenu.AppendItem(item)
160
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)
164
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)
169
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)
173
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)
177
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)
181
6a64d551 182 self._visualMenu.AppendMenu(wx.ID_ANY, "Tabs Style", styleMenu)
6cb4f153 183
6a64d551 184 item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_FROM, "Select fancy tab style 'from' color",
6cb4f153 185 "Select fancy tab style 'from' color")
6a64d551 186 self._visualMenu.AppendItem(item)
6cb4f153 187
6a64d551 188 item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_TO, "Select fancy tab style 'to' color",
6cb4f153 189 "Select fancy tab style 'to' color")
6a64d551 190 self._visualMenu.AppendItem(item)
6cb4f153 191
6a64d551 192 item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_BORDER, "Select fancy tab style 'border' color",
6cb4f153 193 "Select fancy tab style 'border' color")
6a64d551
RD
194 self._visualMenu.AppendItem(item)
195
196 self._editMenu.AppendSeparator()
6cb4f153
RD
197
198 self.Bind(wx.EVT_MENU_RANGE, self.OnSelectColor, id=MENU_SELECT_GRADIENT_COLOR_FROM,
199 id2=MENU_SELECT_GRADIENT_COLOR_BORDER)
200
37938059
RD
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)
205
6cb4f153
RD
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)
209
210 item = wx.MenuItem(self._editMenu, MENU_HIDE_X, "Hide X Button", "Hide X Button", wx.ITEM_CHECK)
211 self._editMenu.AppendItem(item)
212
6a64d551
RD
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)
216 item.Check(False)
217
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)
222 item.Check(False);
223 self._editMenu.AppendSeparator()
224
6cb4f153
RD
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)
228
6a64d551
RD
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)
233 item.Check(False)
234
235 self._editMenu.AppendSeparator()
236
6cb4f153
RD
237 item = wx.MenuItem(self._editMenu, MENU_USE_BOTTOM_TABS, "Use Bottoms Tabs", "Use Bottoms Tabs",
238 wx.ITEM_CHECK)
239 self._editMenu.AppendItem(item)
240
241 self.Bind(wx.EVT_MENU_RANGE, self.OnStyle, id=MENU_HIDE_X, id2=MENU_USE_BOTTOM_TABS)
242
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)
246
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)
250
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)
6a64d551 255 item.Check(False)
6cb4f153 256
6a64d551
RD
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)
261 item.Check(False);
262
263 item = wx.MenuItem(self._visualMenu, MENU_DRAW_BORDER, "Draw Border around tab area",
6cb4f153
RD
264 "Draw Border around tab area", wx.ITEM_CHECK)
265 self.Bind(wx.EVT_MENU, self.OnStyle, item)
6a64d551 266 self._visualMenu.AppendItem(item)
6cb4f153
RD
267 item.Check(True)
268
6a64d551 269 item = wx.MenuItem(self._visualMenu, MENU_DRAW_TAB_X, "Draw X button On Active Tab",
6cb4f153
RD
270 "Draw X button On Active Tab", wx.ITEM_CHECK)
271 self.Bind(wx.EVT_MENU, self.OnDrawTabX, item)
6a64d551 272 self._visualMenu.AppendItem(item)
6cb4f153 273
6a64d551 274 item = wx.MenuItem(self._visualMenu, MENU_SET_ACTIVE_TAB_COLOR, "Select Active Tab Color",
6cb4f153
RD
275 "Select Active Tab Color")
276 self.Bind(wx.EVT_MENU, self.OnSelectColor, item)
6a64d551 277 self._visualMenu.AppendItem(item)
6cb4f153 278
6a64d551 279 item = wx.MenuItem(self._visualMenu, MENU_SET_TAB_AREA_COLOR, "Select Tab Area Color",
6cb4f153
RD
280 "Select Tab Area 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_ACTIVE_TEXT_COLOR, "Select active tab text color",
6cb4f153
RD
285 "Select active tab text 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_SELECT_NONACTIVE_TEXT_COLOR,
6cb4f153
RD
290 "Select NON-active tab text color", "Select NON-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_GRADIENT_BACKGROUND, "Use Gradient Coloring for tab area",
6cb4f153
RD
295 "Use Gradient Coloring for tab area", wx.ITEM_CHECK)
296 self.Bind(wx.EVT_MENU, self.OnGradientBack, item)
6a64d551 297 self._visualMenu.AppendItem(item)
6cb4f153
RD
298 item.Check(False)
299
6a64d551 300 item = wx.MenuItem(self._visualMenu, MENU_COLORFUL_TABS, "Colorful tabs", "Colorful tabs", wx.ITEM_CHECK)
6cb4f153 301 self.Bind(wx.EVT_MENU, self.OnColorfulTabs, item)
6a64d551 302 self._visualMenu.AppendItem(item)
6cb4f153
RD
303 item.Check(False)
304
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)
309
310 self._menuBar.Append(self._fileMenu, "&File")
311 self._menuBar.Append(self._editMenu, "&Edit")
6a64d551
RD
312 self._menuBar.Append(self._visualMenu, "&Tab Appearance")
313
6cb4f153
RD
314 self._menuBar.Append(help_menu, "&Help")
315
316 self.SetMenuBar(self._menuBar)
317
318
319 def CreateRightClickMenu(self):
320
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)
324
325
326 def LayoutItems(self):
327
328 mainSizer = wx.BoxSizer(wx.VERTICAL)
329 self.SetSizer(mainSizer)
330
6a64d551
RD
331 bookStyle = fnb.FNB_NODRAG
332
333 self.book = fnb.FlatNotebook(self, wx.ID_ANY, style=bookStyle)
6cb4f153 334
6a64d551
RD
335 bookStyle &= ~(fnb.FNB_NODRAG)
336 bookStyle |= fnb.FNB_ALLOW_FOREIGN_DND
337 self.secondBook = fnb.FlatNotebook(self, wx.ID_ANY, style=bookStyle)
6cb4f153
RD
338
339 # Set right click menu to the notebook
340 self.book.SetRightClickMenu(self._rmenu)
341
342 # Set the image list
343 self.book.SetImageList(self._ImageList)
344 mainSizer.Add(self.book, 6, wx.EXPAND)
345
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)
350
351 mainSizer.Add(self.secondBook, 2, wx.EXPAND)
352
353 # Add some pages to the second notebook
354 self.Freeze()
355
6a64d551 356 text = wx.TextCtrl(self.secondBook, -1, "Second Book Page 1\n", style=wx.TE_MULTILINE|wx.TE_READONLY)
6cb4f153
RD
357 self.secondBook.AddPage(text, "Second Book Page 1")
358
6a64d551 359 text = wx.TextCtrl(self.secondBook, -1, "Second Book Page 2\n", style=wx.TE_MULTILINE|wx.TE_READONLY)
6cb4f153
RD
360 self.secondBook.AddPage(text, "Second Book Page 2")
361
362 self.Thaw()
363
6cb4f153
RD
364 mainSizer.Layout()
365 self.SendSizeEvent()
366
367
368 def OnStyle(self, event):
369
370 style = self.book.GetWindowStyleFlag()
371 eventid = event.GetId()
372
373 if eventid == MENU_HIDE_NAV_BUTTONS:
374 if event.IsChecked():
375 # Hide the navigation buttons
376 style |= fnb.FNB_NO_NAV_BUTTONS
377 else:
6a64d551
RD
378 style &= ~fnb.FNB_NO_NAV_BUTTONS
379 style &= ~fnb.FNB_DROPDOWN_TABS_LIST
6cb4f153
RD
380
381 self.book.SetWindowStyleFlag(style)
382
37938059
RD
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
387 else:
388 style &= ~(fnb.FNB_HIDE_ON_SINGLE_TAB)
389
390 self.book.SetWindowStyleFlag(style)
391
6cb4f153
RD
392 elif eventid == MENU_HIDE_X:
393 if event.IsChecked():
394 # Hide the X button
395 style |= fnb.FNB_NO_X_BUTTON
396 else:
397 if style & fnb.FNB_NO_X_BUTTON:
398 style ^= fnb.FNB_NO_X_BUTTON
399
400 self.book.SetWindowStyleFlag(style)
401
402 elif eventid == MENU_DRAW_BORDER:
403 if event.IsChecked():
404 style |= fnb.FNB_TABS_BORDER_SIMPLE
405 else:
406 if style & fnb.FNB_TABS_BORDER_SIMPLE:
407 style ^= fnb.FNB_TABS_BORDER_SIMPLE
408
409 self.book.SetWindowStyleFlag(style)
410
411 elif eventid == MENU_USE_MOUSE_MIDDLE_BTN:
412 if event.IsChecked():
413 style |= fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS
414 else:
415 if style & fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS:
416 style ^= fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS
417
418 self.book.SetWindowStyleFlag(style)
419
420 elif eventid == MENU_USE_BOTTOM_TABS:
421 if event.IsChecked():
422 style |= fnb.FNB_BOTTOM
423 else:
424 if style & fnb.FNB_BOTTOM:
425 style ^= fnb.FNB_BOTTOM
426
427 self.book.SetWindowStyleFlag(style)
428 self.book.Refresh()
429
430
431 def OnQuit(self, event):
432
433 self.Destroy()
434
435
436 def OnDeleteAll(self, event):
437
438 self.book.DeleteAllPages()
439
440
441 def OnShowImages(self, event):
442
443 self._bShowImages = event.IsChecked()
444
445
446 def OnVC71Style(self, event):
447
448 style = self.book.GetWindowStyleFlag()
449
450 # remove old tabs style
451 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS)
452 style &= mirror
453
454 style |= fnb.FNB_VC71
455
456 self.book.SetWindowStyleFlag(style)
457
458
459 def OnVC8Style(self, event):
460
461 style = self.book.GetWindowStyleFlag()
462
463 # remove old tabs style
464 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS)
465 style &= mirror
466
467 # set new style
468 style |= fnb.FNB_VC8
469
470 self.book.SetWindowStyleFlag(style)
471
472
473 def OnDefaultStyle(self, event):
474
475 style = self.book.GetWindowStyleFlag()
476
477 # remove old tabs style
478 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS)
479 style &= mirror
480
481 self.book.SetWindowStyleFlag(style)
482
483
484 def OnFancyStyle(self, event):
485
486 style = self.book.GetWindowStyleFlag()
487
488 # remove old tabs style
489 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS)
490 style &= mirror
491
492 style |= fnb.FNB_FANCY_TABS
493 self.book.SetWindowStyleFlag(style)
494
495
496 def OnSelectColor(self, event):
497
498 eventid = event.GetId()
499
500 # Open a color dialog
501 data = wx.ColourData()
502
503 dlg = wx.ColourDialog(self, data)
504
505 if dlg.ShowModal() == wx.ID_OK:
506
507 if eventid == MENU_SELECT_GRADIENT_COLOR_BORDER:
6a64d551 508 self.book.SetGradientColourBorder(dlg.GetColourData().GetColour())
6cb4f153 509 elif eventid == MENU_SELECT_GRADIENT_COLOR_FROM:
6a64d551 510 self.book.SetGradientColourFrom(dlg.GetColourData().GetColour())
6cb4f153 511 elif eventid == MENU_SELECT_GRADIENT_COLOR_TO:
6a64d551 512 self.book.SetGradientColourTo(dlg.GetColourData().GetColour())
6cb4f153
RD
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())
521
522 self.book.Refresh()
523
524
525 def OnAddPage(self, event):
526
527 caption = "New Page Added #" + str(self._newPageCounter)
528
529 self.Freeze()
530
531 image = -1
532 if self._bShowImages:
533 image = random.randint(0, self._ImageList.GetImageCount()-1)
534
535 self.book.AddPage(self.CreatePage(caption), caption, True, image)
6cb4f153
RD
536 self.Thaw()
537 self._newPageCounter = self._newPageCounter + 1
538
539
540 def CreatePage(self, caption):
541
75c39820
RD
542 p = wx.Panel(self.book)
543 wx.StaticText(p, -1, caption, (20,20))
544 wx.TextCtrl(p, -1, "", (20,40), (150,-1))
75c39820 545 return p
6cb4f153
RD
546
547
548 def OnDeletePage(self, event):
549
550 self.book.DeletePage(self.book.GetSelection())
551
552
553 def OnSetSelection(self, event):
554
555 dlg = wx.TextEntryDialog(self, "Enter Tab Number to select:", "Set Selection")
556
557 if dlg.ShowModal() == wx.ID_OK:
558
559 val = dlg.GetValue()
560 self.book.SetSelection(int(val))
561
562
563 def OnEnableTab(self, event):
564
565 dlg = wx.TextEntryDialog(self, "Enter Tab Number to enable:", "Enable Tab")
566
567 if dlg.ShowModal() == wx.ID_OK:
568
569 val = dlg.GetValue()
570 self.book.Enable(int(val))
571
572
573 def OnDisableTab(self, event):
574
575 dlg = wx.TextEntryDialog(self, "Enter Tab Number to disable:", "Disable Tab")
576
577 if dlg.ShowModal() == wx.ID_OK:
578
579 val = dlg.GetValue()
580 self.book.Enable(int(val), False)
581
582
583 def OnEnableDrag(self, event):
584
585 style = self.book.GetWindowStyleFlag()
6a64d551 586 style2 = self.secondBook.GetWindowStyleFlag()
6cb4f153
RD
587
588 if event.IsChecked():
589 if style & fnb.FNB_NODRAG:
590 style ^= fnb.FNB_NODRAG
6a64d551
RD
591 if style2 & fnb.FNB_NODRAG:
592 style2 ^= fnb.FNB_NODRAG
6cb4f153
RD
593 else:
594 style |= fnb.FNB_NODRAG
6a64d551 595 style2 |= fnb.FNB_NODRAG
6cb4f153
RD
596
597 self.book.SetWindowStyleFlag(style)
6a64d551 598 self.secondBook.SetWindowStyleFlag(style2)
6cb4f153
RD
599
600
6a64d551
RD
601 def OnAllowForeignDnd(self, event):
602
603 style = self.book.GetWindowStyleFlag()
604 if event.IsChecked():
605 style |= fnb.FNB_ALLOW_FOREIGN_DND
606 else:
607 style &= ~(fnb.FNB_ALLOW_FOREIGN_DND)
608
609 self.book.SetWindowStyleFlag(style)
610 self.book.Refresh()
611
612
6cb4f153
RD
613 def OnSetAllPagesShapeAngle(self, event):
614
615
6a64d551 616 dlg = wx.TextEntryDialog(self, "Enter an inclination of header borders (0-15):", "Set Angle")
6cb4f153
RD
617 if dlg.ShowModal() == wx.ID_OK:
618
619 val = dlg.GetValue()
620 self.book.SetAllPagesShapeAngle(int(val))
621
622
6a64d551 623 def OnSetPageImage(self, event):
6cb4f153
RD
624
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:
627 val = dlg.GetValue()
6a64d551 628 self.book.SetPageImage(self.book.GetSelection(), int(val))
6cb4f153
RD
629
630
631 def OnAdvanceSelectionFwd(self, event):
632
633 self.book.AdvanceSelection(True)
634
635
636 def OnAdvanceSelectionBack(self, event):
637
638 self.book.AdvanceSelection(False)
639
640
641 def OnPageChanging(self, event):
6a64d551 642
75c39820 643 self.log.write("Page Changing From %d To %d" % (event.GetOldSelection(), event.GetSelection()))
6cb4f153
RD
644 event.Skip()
645
646
647 def OnPageChanged(self, event):
6a64d551 648
75c39820 649 self.log.write("Page Changed To %d" % event.GetSelection())
6cb4f153
RD
650 event.Skip()
651
652
653 def OnPageClosing(self, event):
6a64d551 654
75c39820 655 self.log.write("Page Closing, Selection: %d" % event.GetSelection())
6cb4f153
RD
656 event.Skip()
657
658
659 def OnDrawTabX(self, event):
660
661 style = self.book.GetWindowStyleFlag()
662 if event.IsChecked():
663 style |= fnb.FNB_X_ON_TAB
664 else:
665 if style & fnb.FNB_X_ON_TAB:
666 style ^= fnb.FNB_X_ON_TAB
667
668 self.book.SetWindowStyleFlag(style)
669
670
671 def OnDClickCloseTab(self, event):
672
673 style = self.book.GetWindowStyleFlag()
674 if event.IsChecked():
675 style |= fnb.FNB_DCLICK_CLOSES_TABS
676 else:
677 style &= ~(fnb.FNB_DCLICK_CLOSES_TABS)
678
679 self.book.SetWindowStyleFlag(style)
680
681
682 def OnGradientBack(self, event):
683
684 style = self.book.GetWindowStyleFlag()
685 if event.IsChecked():
686 style |= fnb.FNB_BACKGROUND_GRADIENT
687 else:
688 style &= ~(fnb.FNB_BACKGROUND_GRADIENT)
689
690 self.book.SetWindowStyleFlag(style)
691 self.book.Refresh()
692
693
694 def OnColorfulTabs(self, event):
695
696 style = self.book.GetWindowStyleFlag()
697 if event.IsChecked():
698 style |= fnb.FNB_COLORFUL_TABS
699 else:
700 style &= ~(fnb.FNB_COLORFUL_TABS)
701
702 self.book.SetWindowStyleFlag(style)
703 self.book.Refresh()
704
705
6a64d551
RD
706 def OnSmartTabs(self, event):
707
708 style = self.book.GetWindowStyleFlag()
709 if event.IsChecked():
710 style |= fnb.FNB_SMART_TABS
711 else:
712 style &= ~fnb.FNB_SMART_TABS
713
714 self.book.SetWindowStyleFlag(style)
715 self.book.Refresh()
716
717
718 def OnDropDownArrow(self, event):
719
720 style = self.book.GetWindowStyleFlag()
721
722 if event.IsChecked():
723
724 style |= fnb.FNB_DROPDOWN_TABS_LIST
725 style |= fnb.FNB_NO_NAV_BUTTONS
726
727 else:
728
729 style &= ~fnb.FNB_DROPDOWN_TABS_LIST
730 style &= ~fnb.FNB_NO_NAV_BUTTONS
731
732 self.book.SetWindowStyleFlag(style)
733 self.book.Refresh()
734
735
736 def OnHideNavigationButtonsUI(self, event):
737
738 style = self.book.GetWindowStyleFlag()
739 event.Check((style & fnb.FNB_NO_NAV_BUTTONS and [True] or [False])[0])
740
741
742 def OnDropDownArrowUI(self, event):
743
744 style = self.book.GetWindowStyleFlag()
745 event.Check((style & fnb.FNB_DROPDOWN_TABS_LIST and [True] or [False])[0])
746
747
748 def OnAllowForeignDndUI(self, event):
749
750 style = self.book.GetWindowStyleFlag()
751 event.Enable((style & fnb.FNB_NODRAG and [False] or [True])[0])
752
753
6cb4f153
RD
754 def OnAbout(self, event):
755
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 + "!!"
763
764 dlg = wx.MessageDialog(self, msg, "FlatNotebook wxPython Demo",
765 wx.OK | wx.ICON_INFORMATION)
766 dlg.ShowModal()
767 dlg.Destroy()
768
769
770#---------------------------------------------------------------------------
771
772
773class TestPanel(wx.Panel):
774 def __init__(self, parent, log):
775 self.log = log
776 wx.Panel.__init__(self, parent, -1)
777
75c39820 778 b = wx.Button(self, -1, " Test FlatNotebook ", (50,50))
6cb4f153
RD
779 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
780
781
782 def OnButton(self, evt):
75c39820 783 self.win = FlatNotebookDemo(self, self.log)
6cb4f153
RD
784 self.win.Show(True)
785
786#----------------------------------------------------------------------
787
788def runTest(frame, nb, log):
789 win = TestPanel(nb, log)
790 return win
791
792#----------------------------------------------------------------------
793
794
979f2f9c 795overview = fnb.__doc__
6cb4f153
RD
796
797
798
799if __name__ == '__main__':
800 import sys,os
801 import run
802 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
803