]>
Commit | Line | Data |
---|---|---|
6cb4f153 RD |
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, id=wx.ID_ANY, title="", pos=wx.DefaultPosition, size=(800, 600), | |
74 | style=wx.DEFAULT_FRAME_STYLE | wx.MAXIMIZE |wx.NO_FULL_REPAINT_ON_RESIZE): | |
75 | ||
76 | wx.Frame.__init__(self, parent, id, title, pos, size, style) | |
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 | self.Centre() | |
324 | mainSizer.Layout() | |
325 | self.SendSizeEvent() | |
326 | ||
327 | ||
328 | def OnStyle(self, event): | |
329 | ||
330 | style = self.book.GetWindowStyleFlag() | |
331 | eventid = event.GetId() | |
332 | ||
333 | if eventid == MENU_HIDE_NAV_BUTTONS: | |
334 | if event.IsChecked(): | |
335 | # Hide the navigation buttons | |
336 | style |= fnb.FNB_NO_NAV_BUTTONS | |
337 | else: | |
338 | if style & fnb.FNB_NO_NAV_BUTTONS: | |
339 | style ^= fnb.FNB_NO_NAV_BUTTONS | |
340 | ||
341 | self.book.SetWindowStyleFlag(style) | |
342 | ||
343 | elif eventid == MENU_HIDE_X: | |
344 | if event.IsChecked(): | |
345 | # Hide the X button | |
346 | style |= fnb.FNB_NO_X_BUTTON | |
347 | else: | |
348 | if style & fnb.FNB_NO_X_BUTTON: | |
349 | style ^= fnb.FNB_NO_X_BUTTON | |
350 | ||
351 | self.book.SetWindowStyleFlag(style) | |
352 | ||
353 | elif eventid == MENU_DRAW_BORDER: | |
354 | if event.IsChecked(): | |
355 | style |= fnb.FNB_TABS_BORDER_SIMPLE | |
356 | else: | |
357 | if style & fnb.FNB_TABS_BORDER_SIMPLE: | |
358 | style ^= fnb.FNB_TABS_BORDER_SIMPLE | |
359 | ||
360 | self.book.SetWindowStyleFlag(style) | |
361 | ||
362 | elif eventid == MENU_USE_MOUSE_MIDDLE_BTN: | |
363 | if event.IsChecked(): | |
364 | style |= fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS | |
365 | else: | |
366 | if style & fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS: | |
367 | style ^= fnb.FNB_MOUSE_MIDDLE_CLOSES_TABS | |
368 | ||
369 | self.book.SetWindowStyleFlag(style) | |
370 | ||
371 | elif eventid == MENU_USE_BOTTOM_TABS: | |
372 | if event.IsChecked(): | |
373 | style |= fnb.FNB_BOTTOM | |
374 | else: | |
375 | if style & fnb.FNB_BOTTOM: | |
376 | style ^= fnb.FNB_BOTTOM | |
377 | ||
378 | self.book.SetWindowStyleFlag(style) | |
379 | self.book.Refresh() | |
380 | ||
381 | ||
382 | def OnQuit(self, event): | |
383 | ||
384 | self.Destroy() | |
385 | ||
386 | ||
387 | def OnDeleteAll(self, event): | |
388 | ||
389 | self.book.DeleteAllPages() | |
390 | ||
391 | ||
392 | def OnShowImages(self, event): | |
393 | ||
394 | self._bShowImages = event.IsChecked() | |
395 | ||
396 | ||
397 | def OnVC71Style(self, event): | |
398 | ||
399 | style = self.book.GetWindowStyleFlag() | |
400 | ||
401 | # remove old tabs style | |
402 | mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS) | |
403 | style &= mirror | |
404 | ||
405 | style |= fnb.FNB_VC71 | |
406 | ||
407 | self.book.SetWindowStyleFlag(style) | |
408 | ||
409 | ||
410 | def OnVC8Style(self, event): | |
411 | ||
412 | style = self.book.GetWindowStyleFlag() | |
413 | ||
414 | # remove old tabs style | |
415 | mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS) | |
416 | style &= mirror | |
417 | ||
418 | # set new style | |
419 | style |= fnb.FNB_VC8 | |
420 | ||
421 | self.book.SetWindowStyleFlag(style) | |
422 | ||
423 | ||
424 | def OnDefaultStyle(self, event): | |
425 | ||
426 | style = self.book.GetWindowStyleFlag() | |
427 | ||
428 | # remove old tabs style | |
429 | mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS) | |
430 | style &= mirror | |
431 | ||
432 | self.book.SetWindowStyleFlag(style) | |
433 | ||
434 | ||
435 | def OnFancyStyle(self, event): | |
436 | ||
437 | style = self.book.GetWindowStyleFlag() | |
438 | ||
439 | # remove old tabs style | |
440 | mirror = ~(fnb.FNB_VC71 | fnb.FNB_VC8 | fnb.FNB_FANCY_TABS) | |
441 | style &= mirror | |
442 | ||
443 | style |= fnb.FNB_FANCY_TABS | |
444 | self.book.SetWindowStyleFlag(style) | |
445 | ||
446 | ||
447 | def OnSelectColor(self, event): | |
448 | ||
449 | eventid = event.GetId() | |
450 | ||
451 | # Open a color dialog | |
452 | data = wx.ColourData() | |
453 | ||
454 | dlg = wx.ColourDialog(self, data) | |
455 | ||
456 | if dlg.ShowModal() == wx.ID_OK: | |
457 | ||
458 | if eventid == MENU_SELECT_GRADIENT_COLOR_BORDER: | |
459 | self.book.SetGradientColorBorder(dlg.GetColourData().GetColour()) | |
460 | elif eventid == MENU_SELECT_GRADIENT_COLOR_FROM: | |
461 | self.book.SetGradientColorFrom(dlg.GetColourData().GetColour()) | |
462 | elif eventid == MENU_SELECT_GRADIENT_COLOR_TO: | |
463 | self.book.SetGradientColorTo(dlg.GetColourData().GetColour()) | |
464 | elif eventid == MENU_SET_ACTIVE_TEXT_COLOR: | |
465 | self.book.SetActiveTabTextColour(dlg.GetColourData().GetColour()) | |
466 | elif eventid == MENU_SELECT_NONACTIVE_TEXT_COLOR: | |
467 | self.book.SetNonActiveTabTextColour(dlg.GetColourData().GetColour()) | |
468 | elif eventid == MENU_SET_ACTIVE_TAB_COLOR: | |
469 | self.book.SetActiveTabColour(dlg.GetColourData().GetColour()) | |
470 | elif eventid == MENU_SET_TAB_AREA_COLOR: | |
471 | self.book.SetTabAreaColour(dlg.GetColourData().GetColour()) | |
472 | ||
473 | self.book.Refresh() | |
474 | ||
475 | ||
476 | def OnAddPage(self, event): | |
477 | ||
478 | caption = "New Page Added #" + str(self._newPageCounter) | |
479 | ||
480 | self.Freeze() | |
481 | ||
482 | image = -1 | |
483 | if self._bShowImages: | |
484 | image = random.randint(0, self._ImageList.GetImageCount()-1) | |
485 | ||
486 | self.book.AddPage(self.CreatePage(caption), caption, True, image) | |
487 | self.book.SetSelection(self.book.GetPageCount()-1) | |
488 | self.Thaw() | |
489 | self._newPageCounter = self._newPageCounter + 1 | |
490 | ||
491 | ||
492 | def CreatePage(self, caption): | |
493 | ||
494 | return wx.TextCtrl(self.book, -1, caption, wx.DefaultPosition, self.book.GetPageBestSize(), | |
495 | wx.TE_MULTILINE) | |
496 | ||
497 | ||
498 | def OnDeletePage(self, event): | |
499 | ||
500 | self.book.DeletePage(self.book.GetSelection()) | |
501 | ||
502 | ||
503 | def OnSetSelection(self, event): | |
504 | ||
505 | dlg = wx.TextEntryDialog(self, "Enter Tab Number to select:", "Set Selection") | |
506 | ||
507 | if dlg.ShowModal() == wx.ID_OK: | |
508 | ||
509 | val = dlg.GetValue() | |
510 | self.book.SetSelection(int(val)) | |
511 | ||
512 | ||
513 | def OnEnableTab(self, event): | |
514 | ||
515 | dlg = wx.TextEntryDialog(self, "Enter Tab Number to enable:", "Enable Tab") | |
516 | ||
517 | if dlg.ShowModal() == wx.ID_OK: | |
518 | ||
519 | val = dlg.GetValue() | |
520 | self.book.Enable(int(val)) | |
521 | ||
522 | ||
523 | def OnDisableTab(self, event): | |
524 | ||
525 | dlg = wx.TextEntryDialog(self, "Enter Tab Number to disable:", "Disable Tab") | |
526 | ||
527 | if dlg.ShowModal() == wx.ID_OK: | |
528 | ||
529 | val = dlg.GetValue() | |
530 | self.book.Enable(int(val), False) | |
531 | ||
532 | ||
533 | def OnEnableDrag(self, event): | |
534 | ||
535 | style = self.book.GetWindowStyleFlag() | |
536 | ||
537 | if event.IsChecked(): | |
538 | if style & fnb.FNB_NODRAG: | |
539 | style ^= fnb.FNB_NODRAG | |
540 | else: | |
541 | style |= fnb.FNB_NODRAG | |
542 | ||
543 | self.book.SetWindowStyleFlag(style) | |
544 | ||
545 | ||
546 | def OnSetAllPagesShapeAngle(self, event): | |
547 | ||
548 | ||
549 | dlg = wx.TextEntryDialog(self, "Enter an inclination of header borders (0-45):", "Set Angle") | |
550 | if dlg.ShowModal() == wx.ID_OK: | |
551 | ||
552 | val = dlg.GetValue() | |
553 | self.book.SetAllPagesShapeAngle(int(val)) | |
554 | ||
555 | ||
556 | def OnSetPageImageIndex(self, event): | |
557 | ||
558 | dlg = wx.TextEntryDialog(self, "Enter an image index (0-%i):"%(self.book.GetImageList().GetImageCount()-1), "Set Image Index") | |
559 | if dlg.ShowModal() == wx.ID_OK: | |
560 | val = dlg.GetValue() | |
561 | self.book.SetPageImageIndex(self.book.GetSelection(), int(val)) | |
562 | ||
563 | ||
564 | def OnAdvanceSelectionFwd(self, event): | |
565 | ||
566 | self.book.AdvanceSelection(True) | |
567 | ||
568 | ||
569 | def OnAdvanceSelectionBack(self, event): | |
570 | ||
571 | self.book.AdvanceSelection(False) | |
572 | ||
573 | ||
574 | def OnPageChanging(self, event): | |
575 | ||
576 | print "Page Changing From", event.GetOldSelection(), "To", event.GetSelection() | |
577 | event.Skip() | |
578 | ||
579 | ||
580 | def OnPageChanged(self, event): | |
581 | ||
582 | print "Page Changed To", event.GetSelection() | |
583 | event.Skip() | |
584 | ||
585 | ||
586 | def OnPageClosing(self, event): | |
587 | ||
588 | print "Page Closing, Selection:", 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 ButtonPanel ", (50,50)) | |
664 | self.Bind(wx.EVT_BUTTON, self.OnButton, b) | |
665 | ||
666 | ||
667 | def OnButton(self, evt): | |
668 | self.win = FlatNotebookDemo(self, title="FlatNotebook Demo") | |
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 | ||
979f2f9c | 680 | overview = fnb.__doc__ |
6cb4f153 RD |
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 |