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