]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/FlatNotebook.py
Tinderbox build fix.
[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()
61
62MENU_SET_ACTIVE_TEXT_COLOR = wx.NewId()
63MENU_DRAW_TAB_X = wx.NewId()
64MENU_SET_ACTIVE_TAB_COLOR = wx.NewId()
65MENU_SET_TAB_AREA_COLOR = wx.NewId()
66MENU_SELECT_NONACTIVE_TEXT_COLOR = wx.NewId()
67MENU_GRADIENT_BACKGROUND = wx.NewId()
68MENU_COLORFUL_TABS = wx.NewId()
69MENU_SMART_TABS = wx.NewId()
70MENU_USE_DROP_ARROW_BUTTON = wx.NewId()
71MENU_ALLOW_FOREIGN_DND = wx.NewId()
6cb4f153
RD
72
73
74class FlatNotebookDemo(wx.Frame):
75
75c39820 76 def __init__(self, parent, log):
6cb4f153 77
75c39820
RD
78 wx.Frame.__init__(self, parent, title="FlatNotebook Demo", size=(800,600))
79 self.log = log
6a64d551 80
6cb4f153
RD
81 self._bShowImages = False
82 self._bVCStyle = False
83 self._newPageCounter = 0
84
85 self._ImageList = wx.ImageList(16, 16)
86 self._ImageList.Add(images.get_book_redBitmap())
87 self._ImageList.Add(images.get_book_greenBitmap())
88 self._ImageList.Add(images.get_book_blueBitmap())
89
90 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
91 self.statusbar.SetStatusWidths([-2, -1])
92 # statusbar fields
93 statusbar_fields = [("FlatNotebook wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
94 ("Welcome To wxPython!")]
95
96 for i in range(len(statusbar_fields)):
97 self.statusbar.SetStatusText(statusbar_fields[i], i)
98
99 self.SetIcon(GetMondrianIcon())
100 self.CreateMenuBar()
101 self.CreateRightClickMenu()
102 self.LayoutItems()
103
104 self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
105 self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
106 self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CLOSING, self.OnPageClosing)
107
6a64d551
RD
108 self.Bind(wx.EVT_UPDATE_UI, self.OnDropDownArrowUI, id=MENU_USE_DROP_ARROW_BUTTON)
109 self.Bind(wx.EVT_UPDATE_UI, self.OnHideNavigationButtonsUI, id=MENU_HIDE_NAV_BUTTONS)
110 self.Bind(wx.EVT_UPDATE_UI, self.OnAllowForeignDndUI, id=MENU_ALLOW_FOREIGN_DND)
6cb4f153
RD
111
112
113 def CreateMenuBar(self):
114
115 self._menuBar = wx.MenuBar(wx.MB_DOCKABLE)
116 self._fileMenu = wx.Menu()
6a64d551
RD
117 self._editMenu = wx.Menu()
118 self._visualMenu = wx.Menu()
119
6cb4f153
RD
120 item = wx.MenuItem(self._fileMenu, wx.ID_ANY, "&Close\tCtrl-Q", "Close demo window")
121 self.Bind(wx.EVT_MENU, self.OnQuit, item)
122 self._fileMenu.AppendItem(item)
6a64d551 123
6cb4f153
RD
124 item = wx.MenuItem(self._editMenu, MENU_EDIT_ADD_PAGE, "New Page\tCtrl+N", "Add New Page")
125 self.Bind(wx.EVT_MENU, self.OnAddPage, item)
126 self._editMenu.AppendItem(item)
127
128 item = wx.MenuItem(self._editMenu, MENU_EDIT_DELETE_PAGE, "Delete Page\tCtrl+F4", "Delete Page")
129 self.Bind(wx.EVT_MENU, self.OnDeletePage, item)
130 self._editMenu.AppendItem(item)
131
132 item = wx.MenuItem(self._editMenu, MENU_EDIT_DELETE_ALL, "Delete All Pages", "Delete All Pages")
133 self.Bind(wx.EVT_MENU, self.OnDeleteAll, item)
134 self._editMenu.AppendItem(item)
135
136 item = wx.MenuItem(self._editMenu, MENU_EDIT_SET_SELECTION, "Set Selection", "Set Selection")
137 self.Bind(wx.EVT_MENU, self.OnSetSelection, item)
138 self._editMenu.AppendItem(item)
139
140 item = wx.MenuItem(self._editMenu, MENU_EDIT_ADVANCE_SELECTION_FWD, "Advance Selection Forward",
141 "Advance Selection Forward")
142 self.Bind(wx.EVT_MENU, self.OnAdvanceSelectionFwd, item)
143 self._editMenu.AppendItem(item)
144
145 item = wx.MenuItem(self._editMenu, MENU_EDIT_ADVANCE_SELECTION_BACK, "Advance Selection Backward",
146 "Advance Selection Backward")
147 self.Bind(wx.EVT_MENU, self.OnAdvanceSelectionBack, item)
148 self._editMenu.AppendItem(item)
149
150 item = wx.MenuItem(self._editMenu, MENU_SET_ALL_TABS_SHAPE_ANGLE, "Set an inclination of tab header borders",
151 "Set the shape of tab header")
152 self.Bind(wx.EVT_MENU, self.OnSetAllPagesShapeAngle, item)
6a64d551 153 self._visualMenu.AppendItem(item)
6cb4f153
RD
154
155 item = wx.MenuItem(self._editMenu, MENU_SET_PAGE_IMAGE_INDEX, "Set image index of selected page",
156 "Set image index")
6a64d551 157 self.Bind(wx.EVT_MENU, self.OnSetPageImage, item)
6cb4f153
RD
158 self._editMenu.AppendItem(item)
159
160 item = wx.MenuItem(self._editMenu, MENU_SHOW_IMAGES, "Show Images", "Show Images", wx.ITEM_CHECK)
161 self.Bind(wx.EVT_MENU, self.OnShowImages, item)
162 self._editMenu.AppendItem(item)
163
164 styleMenu = wx.Menu()
165 item = wx.MenuItem(styleMenu, MENU_USE_DEFAULT_STYLE, "Use Default Style", "Use VC71 Style", wx.ITEM_RADIO)
166 self.Bind(wx.EVT_MENU, self.OnDefaultStyle, item)
167 styleMenu.AppendItem(item)
168
169 item = wx.MenuItem(styleMenu, MENU_USE_VC71_STYLE, "Use VC71 Style", "Use VC71 Style", wx.ITEM_RADIO)
170 self.Bind(wx.EVT_MENU, self.OnVC71Style, item)
171 styleMenu.AppendItem(item)
172
173 item = wx.MenuItem(styleMenu, MENU_USE_VC8_STYLE, "Use VC8 Style", "Use VC8 Style", wx.ITEM_RADIO)
174 self.Bind(wx.EVT_MENU, self.OnVC8Style, item)
175 styleMenu.AppendItem(item)
176
177 item = wx.MenuItem(styleMenu, MENU_USE_FANCY_STYLE, "Use Fancy Style", "Use Fancy Style", wx.ITEM_RADIO)
178 self.Bind(wx.EVT_MENU, self.OnFancyStyle, item)
179 styleMenu.AppendItem(item)
180
6a64d551 181 self._visualMenu.AppendMenu(wx.ID_ANY, "Tabs Style", styleMenu)
6cb4f153 182
6a64d551 183 item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_FROM, "Select fancy tab style 'from' color",
6cb4f153 184 "Select fancy tab style 'from' color")
6a64d551 185 self._visualMenu.AppendItem(item)
6cb4f153 186
6a64d551 187 item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_TO, "Select fancy tab style 'to' color",
6cb4f153 188 "Select fancy tab style 'to' color")
6a64d551 189 self._visualMenu.AppendItem(item)
6cb4f153 190
6a64d551 191 item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_BORDER, "Select fancy tab style 'border' color",
6cb4f153 192 "Select fancy tab style 'border' color")
6a64d551
RD
193 self._visualMenu.AppendItem(item)
194
195 self._editMenu.AppendSeparator()
6cb4f153
RD
196
197 self.Bind(wx.EVT_MENU_RANGE, self.OnSelectColor, id=MENU_SELECT_GRADIENT_COLOR_FROM,
198 id2=MENU_SELECT_GRADIENT_COLOR_BORDER)
199
200 item = wx.MenuItem(self._editMenu, MENU_HIDE_NAV_BUTTONS, "Hide Navigation Buttons",
201 "Hide Navigation Buttons", wx.ITEM_CHECK)
202 self._editMenu.AppendItem(item)
203
204 item = wx.MenuItem(self._editMenu, MENU_HIDE_X, "Hide X Button", "Hide X Button", wx.ITEM_CHECK)
205 self._editMenu.AppendItem(item)
206
6a64d551
RD
207 item = wx.MenuItem(self._editMenu, MENU_SMART_TABS, "Smart tabbing", "Smart tabbing", wx.ITEM_CHECK)
208 self._editMenu.AppendItem(item)
209 self.Bind(wx.EVT_MENU, self.OnSmartTabs, item)
210 item.Check(False)
211
212 item = wx.MenuItem(self._editMenu, MENU_USE_DROP_ARROW_BUTTON, "Use drop down button for tab navigation",
213 "Use drop down arrow for quick tab navigation", wx.ITEM_CHECK)
214 self._editMenu.AppendItem(item)
215 self.Bind(wx.EVT_MENU, self.OnDropDownArrow, item)
216 item.Check(False);
217 self._editMenu.AppendSeparator()
218
6cb4f153
RD
219 item = wx.MenuItem(self._editMenu, MENU_USE_MOUSE_MIDDLE_BTN, "Use Mouse Middle Button as 'X' button",
220 "Use Mouse Middle Button as 'X' button", wx.ITEM_CHECK)
221 self._editMenu.AppendItem(item)
222
6a64d551
RD
223 item = wx.MenuItem(self._editMenu, MENU_DCLICK_CLOSES_TAB, "Mouse double click closes tab",
224 "Mouse double click closes tab", wx.ITEM_CHECK)
225 self.Bind(wx.EVT_MENU, self.OnDClickCloseTab, item)
226 self._editMenu.AppendItem(item)
227 item.Check(False)
228
229 self._editMenu.AppendSeparator()
230
6cb4f153
RD
231 item = wx.MenuItem(self._editMenu, MENU_USE_BOTTOM_TABS, "Use Bottoms Tabs", "Use Bottoms Tabs",
232 wx.ITEM_CHECK)
233 self._editMenu.AppendItem(item)
234
235 self.Bind(wx.EVT_MENU_RANGE, self.OnStyle, id=MENU_HIDE_X, id2=MENU_USE_BOTTOM_TABS)
236
237 item = wx.MenuItem(self._editMenu, MENU_ENABLE_TAB, "Enable Tab", "Enable Tab")
238 self.Bind(wx.EVT_MENU, self.OnEnableTab, item)
239 self._editMenu.AppendItem(item)
240
241 item = wx.MenuItem(self._editMenu, MENU_DISABLE_TAB, "Disable Tab", "Disable Tab")
242 self.Bind(wx.EVT_MENU, self.OnDisableTab, item)
243 self._editMenu.AppendItem(item)
244
245 item = wx.MenuItem(self._editMenu, MENU_ENABLE_DRAG_N_DROP, "Enable Drag And Drop of Tabs",
246 "Enable Drag And Drop of Tabs", wx.ITEM_CHECK)
247 self.Bind(wx.EVT_MENU, self.OnEnableDrag, item)
248 self._editMenu.AppendItem(item)
6a64d551 249 item.Check(False)
6cb4f153 250
6a64d551
RD
251 item = wx.MenuItem(self._editMenu, MENU_ALLOW_FOREIGN_DND, "Enable Drag And Drop of Tabs from foreign notebooks",
252 "Enable Drag And Drop of Tabs from foreign notebooks", wx.ITEM_CHECK)
253 self.Bind(wx.EVT_MENU, self.OnAllowForeignDnd, item)
254 self._editMenu.AppendItem(item)
255 item.Check(False);
256
257 item = wx.MenuItem(self._visualMenu, MENU_DRAW_BORDER, "Draw Border around tab area",
6cb4f153
RD
258 "Draw Border around tab area", wx.ITEM_CHECK)
259 self.Bind(wx.EVT_MENU, self.OnStyle, item)
6a64d551 260 self._visualMenu.AppendItem(item)
6cb4f153
RD
261 item.Check(True)
262
6a64d551 263 item = wx.MenuItem(self._visualMenu, MENU_DRAW_TAB_X, "Draw X button On Active Tab",
6cb4f153
RD
264 "Draw X button On Active Tab", wx.ITEM_CHECK)
265 self.Bind(wx.EVT_MENU, self.OnDrawTabX, item)
6a64d551 266 self._visualMenu.AppendItem(item)
6cb4f153 267
6a64d551 268 item = wx.MenuItem(self._visualMenu, MENU_SET_ACTIVE_TAB_COLOR, "Select Active Tab Color",
6cb4f153
RD
269 "Select Active Tab Color")
270 self.Bind(wx.EVT_MENU, self.OnSelectColor, item)
6a64d551 271 self._visualMenu.AppendItem(item)
6cb4f153 272
6a64d551 273 item = wx.MenuItem(self._visualMenu, MENU_SET_TAB_AREA_COLOR, "Select Tab Area Color",
6cb4f153
RD
274 "Select Tab Area Color")
275 self.Bind(wx.EVT_MENU, self.OnSelectColor, item)
6a64d551 276 self._visualMenu.AppendItem(item)
6cb4f153 277
6a64d551 278 item = wx.MenuItem(self._visualMenu, MENU_SET_ACTIVE_TEXT_COLOR, "Select active tab text color",
6cb4f153
RD
279 "Select active tab text color")
280 self.Bind(wx.EVT_MENU, self.OnSelectColor, item)
6a64d551 281 self._visualMenu.AppendItem(item)
6cb4f153 282
6a64d551 283 item = wx.MenuItem(self._visualMenu, MENU_SELECT_NONACTIVE_TEXT_COLOR,
6cb4f153
RD
284 "Select NON-active tab text color", "Select NON-active tab text color")
285 self.Bind(wx.EVT_MENU, self.OnSelectColor, item)
6a64d551 286 self._visualMenu.AppendItem(item)
6cb4f153 287
6a64d551 288 item = wx.MenuItem(self._visualMenu, MENU_GRADIENT_BACKGROUND, "Use Gradient Coloring for tab area",
6cb4f153
RD
289 "Use Gradient Coloring for tab area", wx.ITEM_CHECK)
290 self.Bind(wx.EVT_MENU, self.OnGradientBack, item)
6a64d551 291 self._visualMenu.AppendItem(item)
6cb4f153
RD
292 item.Check(False)
293
6a64d551 294 item = wx.MenuItem(self._visualMenu, MENU_COLORFUL_TABS, "Colorful tabs", "Colorful tabs", wx.ITEM_CHECK)
6cb4f153 295 self.Bind(wx.EVT_MENU, self.OnColorfulTabs, item)
6a64d551 296 self._visualMenu.AppendItem(item)
6cb4f153
RD
297 item.Check(False)
298
299 help_menu = wx.Menu()
300 item = wx.MenuItem(help_menu, wx.ID_ANY, "About...", "Shows The About Dialog")
301 self.Bind(wx.EVT_MENU, self.OnAbout, item)
302 help_menu.AppendItem(item)
303
304 self._menuBar.Append(self._fileMenu, "&File")
305 self._menuBar.Append(self._editMenu, "&Edit")
6a64d551
RD
306 self._menuBar.Append(self._visualMenu, "&Tab Appearance")
307
6cb4f153
RD
308 self._menuBar.Append(help_menu, "&Help")
309
310 self.SetMenuBar(self._menuBar)
311
312
313 def CreateRightClickMenu(self):
314
315 self._rmenu = wx.Menu()
316 item = wx.MenuItem(self._rmenu, MENU_EDIT_DELETE_PAGE, "Close Tab\tCtrl+F4", "Close Tab")
317 self._rmenu.AppendItem(item)
318
319
320 def LayoutItems(self):
321
322 mainSizer = wx.BoxSizer(wx.VERTICAL)
323 self.SetSizer(mainSizer)
324
6a64d551
RD
325 bookStyle = fnb.FNB_NODRAG
326
327 self.book = fnb.FlatNotebook(self, wx.ID_ANY, style=bookStyle)
6cb4f153 328
6a64d551
RD
329 bookStyle &= ~(fnb.FNB_NODRAG)
330 bookStyle |= fnb.FNB_ALLOW_FOREIGN_DND
331 self.secondBook = fnb.FlatNotebook(self, wx.ID_ANY, style=bookStyle)
6cb4f153
RD
332
333 # Set right click menu to the notebook
334 self.book.SetRightClickMenu(self._rmenu)
335
336 # Set the image list
337 self.book.SetImageList(self._ImageList)
338 mainSizer.Add(self.book, 6, wx.EXPAND)
339
340 # Add spacer between the books
341 spacer = wx.Panel(self, -1)
342 spacer.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE))
343 mainSizer.Add(spacer, 0, wx.ALL | wx.EXPAND)
344
345 mainSizer.Add(self.secondBook, 2, wx.EXPAND)
346
347 # Add some pages to the second notebook
348 self.Freeze()
349
6a64d551 350 text = wx.TextCtrl(self.secondBook, -1, "Second Book Page 1\n", style=wx.TE_MULTILINE|wx.TE_READONLY)
6cb4f153
RD
351 self.secondBook.AddPage(text, "Second Book Page 1")
352
6a64d551 353 text = wx.TextCtrl(self.secondBook, -1, "Second Book Page 2\n", style=wx.TE_MULTILINE|wx.TE_READONLY)
6cb4f153
RD
354 self.secondBook.AddPage(text, "Second Book Page 2")
355
356 self.Thaw()
357
6cb4f153
RD
358 mainSizer.Layout()
359 self.SendSizeEvent()
360
361
362 def OnStyle(self, event):
363
364 style = self.book.GetWindowStyleFlag()
365 eventid = event.GetId()
366
367 if eventid == MENU_HIDE_NAV_BUTTONS:
368 if event.IsChecked():
369 # Hide the navigation buttons
370 style |= fnb.FNB_NO_NAV_BUTTONS
371 else:
6a64d551
RD
372 style &= ~fnb.FNB_NO_NAV_BUTTONS
373 style &= ~fnb.FNB_DROPDOWN_TABS_LIST
6cb4f153
RD
374
375 self.book.SetWindowStyleFlag(style)
376
377 elif eventid == MENU_HIDE_X:
378 if event.IsChecked():
379 # Hide the X button
380 style |= fnb.FNB_NO_X_BUTTON
381 else:
382 if style & fnb.FNB_NO_X_BUTTON:
383 style ^= fnb.FNB_NO_X_BUTTON
384
385 self.book.SetWindowStyleFlag(style)
386
387 elif eventid == MENU_DRAW_BORDER:
388 if event.IsChecked():
389 style |= fnb.FNB_TABS_BORDER_SIMPLE
390 else:
391 if style & fnb.FNB_TABS_BORDER_SIMPLE:
392 style ^= fnb.FNB_TABS_BORDER_SIMPLE
393
394 self.book.SetWindowStyleFlag(style)
395
396 elif eventid == MENU_USE_MOUSE_MIDDLE_BTN:
397 if event.IsChecked():
398 style |= fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS
399 else:
400 if style & fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS:
401 style ^= fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS
402
403 self.book.SetWindowStyleFlag(style)
404
405 elif eventid == MENU_USE_BOTTOM_TABS:
406 if event.IsChecked():
407 style |= fnb.FNB_BOTTOM
408 else:
409 if style & fnb.FNB_BOTTOM:
410 style ^= fnb.FNB_BOTTOM
411
412 self.book.SetWindowStyleFlag(style)
413 self.book.Refresh()
414
415
416 def OnQuit(self, event):
417
418 self.Destroy()
419
420
421 def OnDeleteAll(self, event):
422
423 self.book.DeleteAllPages()
424
425
426 def OnShowImages(self, event):
427
428 self._bShowImages = event.IsChecked()
429
430
431 def OnVC71Style(self, event):
432
433 style = self.book.GetWindowStyleFlag()
434
435 # remove old tabs style
436 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS)
437 style &= mirror
438
439 style |= fnb.FNB_VC71
440
441 self.book.SetWindowStyleFlag(style)
442
443
444 def OnVC8Style(self, event):
445
446 style = self.book.GetWindowStyleFlag()
447
448 # remove old tabs style
449 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS)
450 style &= mirror
451
452 # set new style
453 style |= fnb.FNB_VC8
454
455 self.book.SetWindowStyleFlag(style)
456
457
458 def OnDefaultStyle(self, event):
459
460 style = self.book.GetWindowStyleFlag()
461
462 # remove old tabs style
463 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS)
464 style &= mirror
465
466 self.book.SetWindowStyleFlag(style)
467
468
469 def OnFancyStyle(self, event):
470
471 style = self.book.GetWindowStyleFlag()
472
473 # remove old tabs style
474 mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS)
475 style &= mirror
476
477 style |= fnb.FNB_FANCY_TABS
478 self.book.SetWindowStyleFlag(style)
479
480
481 def OnSelectColor(self, event):
482
483 eventid = event.GetId()
484
485 # Open a color dialog
486 data = wx.ColourData()
487
488 dlg = wx.ColourDialog(self, data)
489
490 if dlg.ShowModal() == wx.ID_OK:
491
492 if eventid == MENU_SELECT_GRADIENT_COLOR_BORDER:
6a64d551 493 self.book.SetGradientColourBorder(dlg.GetColourData().GetColour())
6cb4f153 494 elif eventid == MENU_SELECT_GRADIENT_COLOR_FROM:
6a64d551 495 self.book.SetGradientColourFrom(dlg.GetColourData().GetColour())
6cb4f153 496 elif eventid == MENU_SELECT_GRADIENT_COLOR_TO:
6a64d551 497 self.book.SetGradientColourTo(dlg.GetColourData().GetColour())
6cb4f153
RD
498 elif eventid == MENU_SET_ACTIVE_TEXT_COLOR:
499 self.book.SetActiveTabTextColour(dlg.GetColourData().GetColour())
500 elif eventid == MENU_SELECT_NONACTIVE_TEXT_COLOR:
501 self.book.SetNonActiveTabTextColour(dlg.GetColourData().GetColour())
502 elif eventid == MENU_SET_ACTIVE_TAB_COLOR:
503 self.book.SetActiveTabColour(dlg.GetColourData().GetColour())
504 elif eventid == MENU_SET_TAB_AREA_COLOR:
505 self.book.SetTabAreaColour(dlg.GetColourData().GetColour())
506
507 self.book.Refresh()
508
509
510 def OnAddPage(self, event):
511
512 caption = "New Page Added #" + str(self._newPageCounter)
513
514 self.Freeze()
515
516 image = -1
517 if self._bShowImages:
518 image = random.randint(0, self._ImageList.GetImageCount()-1)
519
520 self.book.AddPage(self.CreatePage(caption), caption, True, image)
6cb4f153
RD
521 self.Thaw()
522 self._newPageCounter = self._newPageCounter + 1
523
524
525 def CreatePage(self, caption):
526
75c39820
RD
527 p = wx.Panel(self.book)
528 wx.StaticText(p, -1, caption, (20,20))
529 wx.TextCtrl(p, -1, "", (20,40), (150,-1))
75c39820 530 return p
6cb4f153
RD
531
532
533 def OnDeletePage(self, event):
534
535 self.book.DeletePage(self.book.GetSelection())
536
537
538 def OnSetSelection(self, event):
539
540 dlg = wx.TextEntryDialog(self, "Enter Tab Number to select:", "Set Selection")
541
542 if dlg.ShowModal() == wx.ID_OK:
543
544 val = dlg.GetValue()
545 self.book.SetSelection(int(val))
546
547
548 def OnEnableTab(self, event):
549
550 dlg = wx.TextEntryDialog(self, "Enter Tab Number to enable:", "Enable Tab")
551
552 if dlg.ShowModal() == wx.ID_OK:
553
554 val = dlg.GetValue()
555 self.book.Enable(int(val))
556
557
558 def OnDisableTab(self, event):
559
560 dlg = wx.TextEntryDialog(self, "Enter Tab Number to disable:", "Disable Tab")
561
562 if dlg.ShowModal() == wx.ID_OK:
563
564 val = dlg.GetValue()
565 self.book.Enable(int(val), False)
566
567
568 def OnEnableDrag(self, event):
569
570 style = self.book.GetWindowStyleFlag()
6a64d551 571 style2 = self.secondBook.GetWindowStyleFlag()
6cb4f153
RD
572
573 if event.IsChecked():
574 if style & fnb.FNB_NODRAG:
575 style ^= fnb.FNB_NODRAG
6a64d551
RD
576 if style2 & fnb.FNB_NODRAG:
577 style2 ^= fnb.FNB_NODRAG
6cb4f153
RD
578 else:
579 style |= fnb.FNB_NODRAG
6a64d551 580 style2 |= fnb.FNB_NODRAG
6cb4f153
RD
581
582 self.book.SetWindowStyleFlag(style)
6a64d551 583 self.secondBook.SetWindowStyleFlag(style2)
6cb4f153
RD
584
585
6a64d551
RD
586 def OnAllowForeignDnd(self, event):
587
588 style = self.book.GetWindowStyleFlag()
589 if event.IsChecked():
590 style |= fnb.FNB_ALLOW_FOREIGN_DND
591 else:
592 style &= ~(fnb.FNB_ALLOW_FOREIGN_DND)
593
594 self.book.SetWindowStyleFlag(style)
595 self.book.Refresh()
596
597
6cb4f153
RD
598 def OnSetAllPagesShapeAngle(self, event):
599
600
6a64d551 601 dlg = wx.TextEntryDialog(self, "Enter an inclination of header borders (0-15):", "Set Angle")
6cb4f153
RD
602 if dlg.ShowModal() == wx.ID_OK:
603
604 val = dlg.GetValue()
605 self.book.SetAllPagesShapeAngle(int(val))
606
607
6a64d551 608 def OnSetPageImage(self, event):
6cb4f153
RD
609
610 dlg = wx.TextEntryDialog(self, "Enter an image index (0-%i):"%(self.book.GetImageList().GetImageCount()-1), "Set Image Index")
611 if dlg.ShowModal() == wx.ID_OK:
612 val = dlg.GetValue()
6a64d551 613 self.book.SetPageImage(self.book.GetSelection(), int(val))
6cb4f153
RD
614
615
616 def OnAdvanceSelectionFwd(self, event):
617
618 self.book.AdvanceSelection(True)
619
620
621 def OnAdvanceSelectionBack(self, event):
622
623 self.book.AdvanceSelection(False)
624
625
626 def OnPageChanging(self, event):
6a64d551 627
75c39820 628 self.log.write("Page Changing From %d To %d" % (event.GetOldSelection(), event.GetSelection()))
6cb4f153
RD
629 event.Skip()
630
631
632 def OnPageChanged(self, event):
6a64d551 633
75c39820 634 self.log.write("Page Changed To %d" % event.GetSelection())
6cb4f153
RD
635 event.Skip()
636
637
638 def OnPageClosing(self, event):
6a64d551 639
75c39820 640 self.log.write("Page Closing, Selection: %d" % event.GetSelection())
6cb4f153
RD
641 event.Skip()
642
643
644 def OnDrawTabX(self, event):
645
646 style = self.book.GetWindowStyleFlag()
647 if event.IsChecked():
648 style |= fnb.FNB_X_ON_TAB
649 else:
650 if style & fnb.FNB_X_ON_TAB:
651 style ^= fnb.FNB_X_ON_TAB
652
653 self.book.SetWindowStyleFlag(style)
654
655
656 def OnDClickCloseTab(self, event):
657
658 style = self.book.GetWindowStyleFlag()
659 if event.IsChecked():
660 style |= fnb.FNB_DCLICK_CLOSES_TABS
661 else:
662 style &= ~(fnb.FNB_DCLICK_CLOSES_TABS)
663
664 self.book.SetWindowStyleFlag(style)
665
666
667 def OnGradientBack(self, event):
668
669 style = self.book.GetWindowStyleFlag()
670 if event.IsChecked():
671 style |= fnb.FNB_BACKGROUND_GRADIENT
672 else:
673 style &= ~(fnb.FNB_BACKGROUND_GRADIENT)
674
675 self.book.SetWindowStyleFlag(style)
676 self.book.Refresh()
677
678
679 def OnColorfulTabs(self, event):
680
681 style = self.book.GetWindowStyleFlag()
682 if event.IsChecked():
683 style |= fnb.FNB_COLORFUL_TABS
684 else:
685 style &= ~(fnb.FNB_COLORFUL_TABS)
686
687 self.book.SetWindowStyleFlag(style)
688 self.book.Refresh()
689
690
6a64d551
RD
691 def OnSmartTabs(self, event):
692
693 style = self.book.GetWindowStyleFlag()
694 if event.IsChecked():
695 style |= fnb.FNB_SMART_TABS
696 else:
697 style &= ~fnb.FNB_SMART_TABS
698
699 self.book.SetWindowStyleFlag(style)
700 self.book.Refresh()
701
702
703 def OnDropDownArrow(self, event):
704
705 style = self.book.GetWindowStyleFlag()
706
707 if event.IsChecked():
708
709 style |= fnb.FNB_DROPDOWN_TABS_LIST
710 style |= fnb.FNB_NO_NAV_BUTTONS
711
712 else:
713
714 style &= ~fnb.FNB_DROPDOWN_TABS_LIST
715 style &= ~fnb.FNB_NO_NAV_BUTTONS
716
717 self.book.SetWindowStyleFlag(style)
718 self.book.Refresh()
719
720
721 def OnHideNavigationButtonsUI(self, event):
722
723 style = self.book.GetWindowStyleFlag()
724 event.Check((style & fnb.FNB_NO_NAV_BUTTONS and [True] or [False])[0])
725
726
727 def OnDropDownArrowUI(self, event):
728
729 style = self.book.GetWindowStyleFlag()
730 event.Check((style & fnb.FNB_DROPDOWN_TABS_LIST and [True] or [False])[0])
731
732
733 def OnAllowForeignDndUI(self, event):
734
735 style = self.book.GetWindowStyleFlag()
736 event.Enable((style & fnb.FNB_NODRAG and [False] or [True])[0])
737
738
6cb4f153
RD
739 def OnAbout(self, event):
740
741 msg = "This Is The About Dialog Of The FlatNotebook Demo.\n\n" + \
742 "Author: Andrea Gavana @ 02 Oct 2006\n\n" + \
743 "Please Report Any Bug/Requests Of Improvements\n" + \
744 "To Me At The Following Adresses:\n\n" + \
745 "andrea.gavana@gmail.com\n" + "gavana@kpo.kz\n\n" + \
746 "Based On Eran C++ Implementation (wxWidgets Forum).\n\n" + \
747 "Welcome To wxPython " + wx.VERSION_STRING + "!!"
748
749 dlg = wx.MessageDialog(self, msg, "FlatNotebook wxPython Demo",
750 wx.OK | wx.ICON_INFORMATION)
751 dlg.ShowModal()
752 dlg.Destroy()
753
754
755#---------------------------------------------------------------------------
756
757
758class TestPanel(wx.Panel):
759 def __init__(self, parent, log):
760 self.log = log
761 wx.Panel.__init__(self, parent, -1)
762
75c39820 763 b = wx.Button(self, -1, " Test FlatNotebook ", (50,50))
6cb4f153
RD
764 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
765
766
767 def OnButton(self, evt):
75c39820 768 self.win = FlatNotebookDemo(self, self.log)
6cb4f153
RD
769 self.win.Show(True)
770
771#----------------------------------------------------------------------
772
773def runTest(frame, nb, log):
774 win = TestPanel(nb, log)
775 return win
776
777#----------------------------------------------------------------------
778
779
979f2f9c 780overview = fnb.__doc__
6cb4f153
RD
781
782
783
784if __name__ == '__main__':
785 import sys,os
786 import run
787 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
788