]>
Commit | Line | Data |
---|---|---|
1 | import wx | |
2 | import wx.lib.flatnotebook as fnb | |
3 | import random | |
4 | import images | |
5 | ||
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.NewId() | |
37 | MENU_EDIT_ADD_PAGE = wx.NewId() | |
38 | MENU_EDIT_DELETE_PAGE = wx.NewId() | |
39 | MENU_EDIT_SET_SELECTION = wx.NewId() | |
40 | MENU_EDIT_ADVANCE_SELECTION_FWD = wx.NewId() | |
41 | MENU_EDIT_ADVANCE_SELECTION_BACK = wx.NewId() | |
42 | MENU_SET_ALL_TABS_SHAPE_ANGLE = wx.NewId() | |
43 | MENU_SHOW_IMAGES = wx.NewId() | |
44 | MENU_USE_VC71_STYLE = wx.NewId() | |
45 | MENU_USE_DEFAULT_STYLE = wx.NewId() | |
46 | MENU_USE_FANCY_STYLE = wx.NewId() | |
47 | MENU_SELECT_GRADIENT_COLOR_FROM = wx.NewId() | |
48 | MENU_SELECT_GRADIENT_COLOR_TO = wx.NewId() | |
49 | MENU_SELECT_GRADIENT_COLOR_BORDER = wx.NewId() | |
50 | MENU_SET_PAGE_IMAGE_INDEX = wx.NewId() | |
51 | MENU_HIDE_X = wx.NewId() | |
52 | MENU_HIDE_NAV_BUTTONS = wx.NewId() | |
53 | MENU_USE_MOUSE_MIDDLE_BTN = wx.NewId() | |
54 | MENU_DRAW_BORDER = wx.NewId() | |
55 | MENU_USE_BOTTOM_TABS = wx.NewId() | |
56 | MENU_ENABLE_TAB = wx.NewId() | |
57 | MENU_DISABLE_TAB = wx.NewId() | |
58 | MENU_ENABLE_DRAG_N_DROP = wx.NewId() | |
59 | MENU_DCLICK_CLOSES_TAB = wx.NewId() | |
60 | MENU_USE_VC8_STYLE = wx.NewId() | |
61 | ||
62 | MENU_SET_ACTIVE_TEXT_COLOR = wx.NewId() | |
63 | MENU_DRAW_TAB_X = wx.NewId() | |
64 | MENU_SET_ACTIVE_TAB_COLOR = wx.NewId() | |
65 | MENU_SET_TAB_AREA_COLOR = wx.NewId() | |
66 | MENU_SELECT_NONACTIVE_TEXT_COLOR = wx.NewId() | |
67 | MENU_GRADIENT_BACKGROUND = wx.NewId() | |
68 | MENU_COLORFUL_TABS = wx.NewId() | |
69 | MENU_SMART_TABS = wx.NewId() | |
70 | MENU_USE_DROP_ARROW_BUTTON = wx.NewId() | |
71 | MENU_ALLOW_FOREIGN_DND = wx.NewId() | |
72 | ||
73 | ||
74 | class FlatNotebookDemo(wx.Frame): | |
75 | ||
76 | def __init__(self, parent, log): | |
77 | ||
78 | wx.Frame.__init__(self, parent, title="FlatNotebook Demo", size=(800,600)) | |
79 | self.log = log | |
80 | ||
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 | ||
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) | |
111 | ||
112 | ||
113 | def CreateMenuBar(self): | |
114 | ||
115 | self._menuBar = wx.MenuBar(wx.MB_DOCKABLE) | |
116 | self._fileMenu = wx.Menu() | |
117 | self._editMenu = wx.Menu() | |
118 | self._visualMenu = wx.Menu() | |
119 | ||
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) | |
123 | ||
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) | |
153 | self._visualMenu.AppendItem(item) | |
154 | ||
155 | item = wx.MenuItem(self._editMenu, MENU_SET_PAGE_IMAGE_INDEX, "Set image index of selected page", | |
156 | "Set image index") | |
157 | self.Bind(wx.EVT_MENU, self.OnSetPageImage, item) | |
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 | ||
181 | self._visualMenu.AppendMenu(wx.ID_ANY, "Tabs Style", styleMenu) | |
182 | ||
183 | item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_FROM, "Select fancy tab style 'from' color", | |
184 | "Select fancy tab style 'from' color") | |
185 | self._visualMenu.AppendItem(item) | |
186 | ||
187 | item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_TO, "Select fancy tab style 'to' color", | |
188 | "Select fancy tab style 'to' color") | |
189 | self._visualMenu.AppendItem(item) | |
190 | ||
191 | item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOR_BORDER, "Select fancy tab style 'border' color", | |
192 | "Select fancy tab style 'border' color") | |
193 | self._visualMenu.AppendItem(item) | |
194 | ||
195 | self._editMenu.AppendSeparator() | |
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 | ||
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 | ||
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 | ||
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 | ||
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) | |
249 | item.Check(False) | |
250 | ||
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", | |
258 | "Draw Border around tab area", wx.ITEM_CHECK) | |
259 | self.Bind(wx.EVT_MENU, self.OnStyle, item) | |
260 | self._visualMenu.AppendItem(item) | |
261 | item.Check(True) | |
262 | ||
263 | item = wx.MenuItem(self._visualMenu, MENU_DRAW_TAB_X, "Draw X button On Active Tab", | |
264 | "Draw X button On Active Tab", wx.ITEM_CHECK) | |
265 | self.Bind(wx.EVT_MENU, self.OnDrawTabX, item) | |
266 | self._visualMenu.AppendItem(item) | |
267 | ||
268 | item = wx.MenuItem(self._visualMenu, MENU_SET_ACTIVE_TAB_COLOR, "Select Active Tab Color", | |
269 | "Select Active Tab Color") | |
270 | self.Bind(wx.EVT_MENU, self.OnSelectColor, item) | |
271 | self._visualMenu.AppendItem(item) | |
272 | ||
273 | item = wx.MenuItem(self._visualMenu, MENU_SET_TAB_AREA_COLOR, "Select Tab Area Color", | |
274 | "Select Tab Area Color") | |
275 | self.Bind(wx.EVT_MENU, self.OnSelectColor, item) | |
276 | self._visualMenu.AppendItem(item) | |
277 | ||
278 | item = wx.MenuItem(self._visualMenu, MENU_SET_ACTIVE_TEXT_COLOR, "Select active tab text color", | |
279 | "Select active tab text color") | |
280 | self.Bind(wx.EVT_MENU, self.OnSelectColor, item) | |
281 | self._visualMenu.AppendItem(item) | |
282 | ||
283 | item = wx.MenuItem(self._visualMenu, MENU_SELECT_NONACTIVE_TEXT_COLOR, | |
284 | "Select NON-active tab text color", "Select NON-active tab text color") | |
285 | self.Bind(wx.EVT_MENU, self.OnSelectColor, item) | |
286 | self._visualMenu.AppendItem(item) | |
287 | ||
288 | item = wx.MenuItem(self._visualMenu, MENU_GRADIENT_BACKGROUND, "Use Gradient Coloring for tab area", | |
289 | "Use Gradient Coloring for tab area", wx.ITEM_CHECK) | |
290 | self.Bind(wx.EVT_MENU, self.OnGradientBack, item) | |
291 | self._visualMenu.AppendItem(item) | |
292 | item.Check(False) | |
293 | ||
294 | item = wx.MenuItem(self._visualMenu, MENU_COLORFUL_TABS, "Colorful tabs", "Colorful tabs", wx.ITEM_CHECK) | |
295 | self.Bind(wx.EVT_MENU, self.OnColorfulTabs, item) | |
296 | self._visualMenu.AppendItem(item) | |
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") | |
306 | self._menuBar.Append(self._visualMenu, "&Tab Appearance") | |
307 | ||
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 | ||
325 | bookStyle = fnb.FNB_NODRAG | |
326 | ||
327 | self.book = fnb.FlatNotebook(self, wx.ID_ANY, style=bookStyle) | |
328 | ||
329 | bookStyle &= ~(fnb.FNB_NODRAG) | |
330 | bookStyle |= fnb.FNB_ALLOW_FOREIGN_DND | |
331 | self.secondBook = fnb.FlatNotebook(self, wx.ID_ANY, style=bookStyle) | |
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 | ||
350 | text = wx.TextCtrl(self.secondBook, -1, "Second Book Page 1\n", style=wx.TE_MULTILINE|wx.TE_READONLY) | |
351 | self.secondBook.AddPage(text, "Second Book Page 1") | |
352 | ||
353 | text = wx.TextCtrl(self.secondBook, -1, "Second Book Page 2\n", style=wx.TE_MULTILINE|wx.TE_READONLY) | |
354 | self.secondBook.AddPage(text, "Second Book Page 2") | |
355 | ||
356 | self.Thaw() | |
357 | ||
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: | |
372 | style &= ~fnb.FNB_NO_NAV_BUTTONS | |
373 | style &= ~fnb.FNB_DROPDOWN_TABS_LIST | |
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: | |
493 | self.book.SetGradientColourBorder(dlg.GetColourData().GetColour()) | |
494 | elif eventid == MENU_SELECT_GRADIENT_COLOR_FROM: | |
495 | self.book.SetGradientColourFrom(dlg.GetColourData().GetColour()) | |
496 | elif eventid == MENU_SELECT_GRADIENT_COLOR_TO: | |
497 | self.book.SetGradientColourTo(dlg.GetColourData().GetColour()) | |
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) | |
521 | self.Thaw() | |
522 | self._newPageCounter = self._newPageCounter + 1 | |
523 | ||
524 | ||
525 | def CreatePage(self, caption): | |
526 | ||
527 | p = wx.Panel(self.book) | |
528 | wx.StaticText(p, -1, caption, (20,20)) | |
529 | wx.TextCtrl(p, -1, "", (20,40), (150,-1)) | |
530 | return p | |
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() | |
571 | style2 = self.secondBook.GetWindowStyleFlag() | |
572 | ||
573 | if event.IsChecked(): | |
574 | if style & fnb.FNB_NODRAG: | |
575 | style ^= fnb.FNB_NODRAG | |
576 | if style2 & fnb.FNB_NODRAG: | |
577 | style2 ^= fnb.FNB_NODRAG | |
578 | else: | |
579 | style |= fnb.FNB_NODRAG | |
580 | style2 |= fnb.FNB_NODRAG | |
581 | ||
582 | self.book.SetWindowStyleFlag(style) | |
583 | self.secondBook.SetWindowStyleFlag(style2) | |
584 | ||
585 | ||
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 | ||
598 | def OnSetAllPagesShapeAngle(self, event): | |
599 | ||
600 | ||
601 | dlg = wx.TextEntryDialog(self, "Enter an inclination of header borders (0-15):", "Set Angle") | |
602 | if dlg.ShowModal() == wx.ID_OK: | |
603 | ||
604 | val = dlg.GetValue() | |
605 | self.book.SetAllPagesShapeAngle(int(val)) | |
606 | ||
607 | ||
608 | def OnSetPageImage(self, event): | |
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() | |
613 | self.book.SetPageImage(self.book.GetSelection(), int(val)) | |
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): | |
627 | ||
628 | self.log.write("Page Changing From %d To %d" % (event.GetOldSelection(), event.GetSelection())) | |
629 | event.Skip() | |
630 | ||
631 | ||
632 | def OnPageChanged(self, event): | |
633 | ||
634 | self.log.write("Page Changed To %d" % event.GetSelection()) | |
635 | event.Skip() | |
636 | ||
637 | ||
638 | def OnPageClosing(self, event): | |
639 | ||
640 | self.log.write("Page Closing, Selection: %d" % event.GetSelection()) | |
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 | ||
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 | ||
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 | ||
758 | class TestPanel(wx.Panel): | |
759 | def __init__(self, parent, log): | |
760 | self.log = log | |
761 | wx.Panel.__init__(self, parent, -1) | |
762 | ||
763 | b = wx.Button(self, -1, " Test FlatNotebook ", (50,50)) | |
764 | self.Bind(wx.EVT_BUTTON, self.OnButton, b) | |
765 | ||
766 | ||
767 | def OnButton(self, evt): | |
768 | self.win = FlatNotebookDemo(self, self.log) | |
769 | self.win.Show(True) | |
770 | ||
771 | #---------------------------------------------------------------------- | |
772 | ||
773 | def runTest(frame, nb, log): | |
774 | win = TestPanel(nb, log) | |
775 | return win | |
776 | ||
777 | #---------------------------------------------------------------------- | |
778 | ||
779 | ||
780 | overview = fnb.__doc__ | |
781 | ||
782 | ||
783 | ||
784 | if __name__ == '__main__': | |
785 | import sys,os | |
786 | import run | |
787 | run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) | |
788 |