File: FlatNotebook.py

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (992 lines) | stat: -rw-r--r-- 33,933 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
import wx

import os
import sys

try:
    dirName = os.path.dirname(os.path.abspath(__file__))
except:
    dirName = os.path.dirname(os.path.abspath(sys.argv[0]))

sys.path.append(os.path.split(dirName)[0])

try:
    import agw.flatnotebook as FNB
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.flatnotebook as FNB

import random
import images


#----------------------------------------------------------------------


MENU_EDIT_DELETE_ALL = wx.NewId()
MENU_EDIT_ADD_PAGE = wx.NewId()
MENU_EDIT_DELETE_PAGE = wx.NewId()
MENU_EDIT_SET_SELECTION = wx.NewId()
MENU_EDIT_ADVANCE_SELECTION_FWD = wx.NewId()
MENU_EDIT_ADVANCE_SELECTION_BACK = wx.NewId()
MENU_SET_ALL_TABS_SHAPE_ANGLE = wx.NewId()
MENU_SHOW_IMAGES = wx.NewId()
MENU_USE_VC71_STYLE = wx.NewId()
MENU_USE_DEFAULT_STYLE = wx.NewId()
MENU_USE_FANCY_STYLE = wx.NewId()
MENU_USE_RIBBON_STYLE = wx.NewId()
MENU_SELECT_GRADIENT_COLOUR_FROM = wx.NewId()
MENU_SELECT_GRADIENT_COLOUR_TO = wx.NewId()
MENU_SELECT_GRADIENT_COLOUR_BORDER = wx.NewId()
MENU_SET_PAGE_IMAGE_INDEX = wx.NewId()
MENU_HIDE_X = wx.NewId()
MENU_HIDE_NAV_BUTTONS = wx.NewId()
MENU_USE_MOUSE_MIDDLE_BTN = wx.NewId()
MENU_DRAW_BORDER = wx.NewId()
MENU_USE_BOTTOM_TABS = wx.NewId()
MENU_ENABLE_TAB = wx.NewId()
MENU_DISABLE_TAB = wx.NewId()
MENU_ENABLE_DRAG_N_DROP = wx.NewId()
MENU_DCLICK_CLOSES_TAB = wx.NewId()
MENU_USE_VC8_STYLE = wx.NewId()
MENU_USE_FF2_STYLE = wx.NewId()
MENU_HIDE_ON_SINGLE_TAB = wx.NewId()
MENU_HIDE_TABS = wx.NewId()
MENU_NO_TABS_FOCUS = wx.NewId()

MENU_SET_ACTIVE_TEXT_COLOUR = wx.NewId()
MENU_DRAW_TAB_X = wx.NewId()
MENU_SET_ACTIVE_TAB_COLOUR = wx.NewId()
MENU_SET_TAB_AREA_COLOUR = wx.NewId()
MENU_SELECT_NONACTIVE_TEXT_COLOUR = wx.NewId()
MENU_GRADIENT_BACKGROUND = wx.NewId()
MENU_COLOURFUL_TABS = wx.NewId()
MENU_SMART_TABS = wx.NewId()
MENU_USE_DROP_ARROW_BUTTON = wx.NewId()
MENU_ALLOW_FOREIGN_DND = wx.NewId()

MENU_TILE_HORIZONTALLY = wx.NewId()
MENU_TILE_VERTICALLY = wx.NewId()
MENU_TILE_NONE = wx.NewId()


class FlatNotebookDemo(wx.Frame):

    def __init__(self, parent, log):

        wx.Frame.__init__(self, parent, title="FlatNotebook Demo", size=(800,600))
        self.log = log

        self._bShowImages = False
        self._bVCStyle = False
        self._newPageCounter = 0

        self._ImageList = wx.ImageList(16, 16)
        self._ImageList.Add(images._book_red.GetBitmap())
        self._ImageList.Add(images._book_green.GetBitmap())
        self._ImageList.Add(images._book_blue.GetBitmap())

        self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
        self.statusbar.SetStatusWidths([-2, -1])
        # statusbar fields
        statusbar_fields = [("FlatNotebook wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
                            ("Welcome To wxPython!")]

        for i in range(len(statusbar_fields)):
            self.statusbar.SetStatusText(statusbar_fields[i], i)

        self.SetIcon(images.Mondrian.GetIcon())
        self.CreateMenuBar()
        self.CreateRightClickMenu()
        self.LayoutItems()

        self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
        self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
        self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CLOSING, self.OnPageClosing)
        self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_DROPPED_FOREIGN, self.OnForeignDrop)
        self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_DROPPED, self.OnDrop)
        
        self.Bind(wx.EVT_UPDATE_UI, self.OnDropDownArrowUI, id=MENU_USE_DROP_ARROW_BUTTON)
        self.Bind(wx.EVT_UPDATE_UI, self.OnHideNavigationButtonsUI, id=MENU_HIDE_NAV_BUTTONS)
        self.Bind(wx.EVT_UPDATE_UI, self.OnAllowForeignDndUI, id=MENU_ALLOW_FOREIGN_DND)


    def CreateMenuBar(self):

        self._menuBar = wx.MenuBar(wx.MB_DOCKABLE)
        self._fileMenu = wx.Menu()
        self._editMenu = wx.Menu()
        self._visualMenu = wx.Menu()

        item = wx.MenuItem(self._fileMenu, wx.ID_ANY, "&Close\tCtrl-Q", "Close demo window")
        self.Bind(wx.EVT_MENU, self.OnQuit, item)
        self._fileMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_EDIT_ADD_PAGE, "New Page\tCtrl+N", "Add New Page")
        self.Bind(wx.EVT_MENU, self.OnAddPage, item)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_EDIT_DELETE_PAGE, "Delete Page\tCtrl+F4", "Delete Page")
        self.Bind(wx.EVT_MENU, self.OnDeletePage, item)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_EDIT_DELETE_ALL, "Delete All Pages", "Delete All Pages")
        self.Bind(wx.EVT_MENU, self.OnDeleteAll, item)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_EDIT_SET_SELECTION, "Set Selection", "Set Selection")
        self.Bind(wx.EVT_MENU, self.OnSetSelection, item)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_EDIT_ADVANCE_SELECTION_FWD, "Advance Selection Forward",
                           "Advance Selection Forward")
        self.Bind(wx.EVT_MENU, self.OnAdvanceSelectionFwd, item)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_EDIT_ADVANCE_SELECTION_BACK, "Advance Selection Backward",
                           "Advance Selection Backward")
        self.Bind(wx.EVT_MENU, self.OnAdvanceSelectionBack, item)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_SET_ALL_TABS_SHAPE_ANGLE, "Set an inclination of tab header borders",
                           "Set the shape of tab header")
        self.Bind(wx.EVT_MENU, self.OnSetAllPagesShapeAngle, item)
        self._visualMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_SET_PAGE_IMAGE_INDEX, "Set image index of selected page",
                           "Set image index")
        self.Bind(wx.EVT_MENU, self.OnSetPageImage, item)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_SHOW_IMAGES, "Show Images", "Show Images", wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnShowImages, item)
        self._editMenu.AppendItem(item)

        styleMenu = wx.Menu()
        item = wx.MenuItem(styleMenu, MENU_USE_DEFAULT_STYLE, "Use Default Style", "Use VC71 Style", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU, self.OnDefaultStyle, item)
        styleMenu.AppendItem(item)

        item = wx.MenuItem(styleMenu, MENU_USE_VC71_STYLE, "Use VC71 Style", "Use VC71 Style", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU, self.OnVC71Style, item)
        styleMenu.AppendItem(item)

        item = wx.MenuItem(styleMenu, MENU_USE_VC8_STYLE, "Use VC8 Style", "Use VC8 Style", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU, self.OnVC8Style, item)
        styleMenu.AppendItem(item)

        item = wx.MenuItem(styleMenu, MENU_USE_FANCY_STYLE, "Use Fancy Style", "Use Fancy Style", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU, self.OnFancyStyle, item)
        styleMenu.AppendItem(item)

        item = wx.MenuItem(styleMenu, MENU_USE_FF2_STYLE, "Use Firefox 2 Style", "Use Firefox 2 Style", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU, self.OnFF2Style, item)
        styleMenu.AppendItem(item)
        
        item = wx.MenuItem(styleMenu, MENU_USE_RIBBON_STYLE, "Use Ribbon Style", "Use Ribbon Style", wx.ITEM_RADIO)
        self.Bind(wx.EVT_MENU, self.OnRibbonStyle, item)
        styleMenu.AppendItem(item)

        self._visualMenu.AppendMenu(wx.ID_ANY, "Tabs Style", styleMenu)

        item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOUR_FROM, "Select fancy tab style 'from' colour",
                           "Select fancy tab style 'from' colour")
        self._visualMenu.AppendItem(item)

        item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOUR_TO, "Select fancy tab style 'to' colour",
                           "Select fancy tab style 'to' colour")
        self._visualMenu.AppendItem(item)

        item = wx.MenuItem(self._visualMenu, MENU_SELECT_GRADIENT_COLOUR_BORDER, "Select fancy tab style 'border' colour",
                           "Select fancy tab style 'border' colour")
        self._visualMenu.AppendItem(item)

        self._editMenu.AppendSeparator()        

        self.Bind(wx.EVT_MENU_RANGE, self.OnSelectColour, id=MENU_SELECT_GRADIENT_COLOUR_FROM,
                  id2=MENU_SELECT_GRADIENT_COLOUR_BORDER)        

        item = wx.MenuItem(self._editMenu, MENU_HIDE_ON_SINGLE_TAB, "Hide Page Container when only one Tab",
                           "Hide Page Container when only one Tab", wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnStyle, item)
        self._editMenu.AppendItem(item)
        
        item = wx.MenuItem(self._editMenu, MENU_HIDE_TABS, "Hide Tabs",
                           "Hide Page Container allowing only keyboard navigation", wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnStyle, item)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_NO_TABS_FOCUS, "No focus on notebook tabs",
                           "No focus on notebook tabs, only pages", wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnStyle, item)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_HIDE_NAV_BUTTONS, "Hide Navigation Buttons",
                           "Hide Navigation Buttons", wx.ITEM_CHECK)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_HIDE_X, "Hide X Button", "Hide X Button", wx.ITEM_CHECK)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_SMART_TABS, "Smart tabbing", "Smart tabbing", wx.ITEM_CHECK)
        self._editMenu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnSmartTabs, item)
        item.Check(False)

        item = wx.MenuItem(self._editMenu, MENU_USE_DROP_ARROW_BUTTON, "Use drop down button for tab navigation",
                           "Use drop down arrow for quick tab navigation", wx.ITEM_CHECK)
        self._editMenu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnDropDownArrow, item)
        item.Check(False)
        self._editMenu.AppendSeparator()

        item = wx.MenuItem(self._editMenu, MENU_TILE_HORIZONTALLY, "Tile pages horizontally",
                           "Tile all the panels in an horizontal sizer", wx.ITEM_RADIO)
        self._editMenu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnTile, item)
        
        item = wx.MenuItem(self._editMenu, MENU_TILE_VERTICALLY, "Tile pages vertically",
                           "Tile all the panels in a vertical sizer", wx.ITEM_RADIO)
        self._editMenu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnTile, item)

        item = wx.MenuItem(self._editMenu, MENU_TILE_NONE, "No tiling",
                           "No tiling, standard FlatNotebook behaviour", wx.ITEM_RADIO)
        self._editMenu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnTile, item)

        item.Check(True)

        self._editMenu.AppendSeparator()

        item = wx.MenuItem(self._editMenu, wx.ID_ANY, "Use custom page",
                           "Shows a custom page when the main notebook has no pages left", wx.ITEM_CHECK)
        self._editMenu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnCustomPanel, item)

        self._editMenu.AppendSeparator()
        
        item = wx.MenuItem(self._editMenu, MENU_USE_MOUSE_MIDDLE_BTN, "Use Mouse Middle Button as 'X' button",
                           "Use Mouse Middle Button as 'X' button", wx.ITEM_CHECK)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_DCLICK_CLOSES_TAB, "Mouse double click closes tab",
                           "Mouse double click closes tab", wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnDClickCloseTab, item)
        self._editMenu.AppendItem(item)
        item.Check(False)

        self._editMenu.AppendSeparator()

        item = wx.MenuItem(self._editMenu, MENU_USE_BOTTOM_TABS, "Use Bottoms Tabs", "Use Bottoms Tabs",
                           wx.ITEM_CHECK)
        self._editMenu.AppendItem(item)

        self.Bind(wx.EVT_MENU_RANGE, self.OnStyle, id=MENU_HIDE_X, id2=MENU_USE_BOTTOM_TABS)

        item = wx.MenuItem(self._editMenu, MENU_ENABLE_TAB, "Enable Tab", "Enable Tab")
        self.Bind(wx.EVT_MENU, self.OnEnableTab, item)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_DISABLE_TAB, "Disable Tab", "Disable Tab")
        self.Bind(wx.EVT_MENU, self.OnDisableTab, item)
        self._editMenu.AppendItem(item)

        item = wx.MenuItem(self._editMenu, MENU_ENABLE_DRAG_N_DROP, "Enable Drag And Drop of Tabs",
                           "Enable Drag And Drop of Tabs", wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnableDrag, item)        
        self._editMenu.AppendItem(item)
        item.Check(False)

        item = wx.MenuItem(self._editMenu, MENU_ALLOW_FOREIGN_DND, "Enable Drag And Drop of Tabs from foreign notebooks",
                           "Enable Drag And Drop of Tabs from foreign notebooks", wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnAllowForeignDnd, item)
        self._editMenu.AppendItem(item) 
        item.Check(False); 

        item = wx.MenuItem(self._visualMenu, MENU_DRAW_BORDER, "Draw Border around tab area",
                           "Draw Border around tab area", wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnStyle, item)
        self._visualMenu.AppendItem(item)
        item.Check(True)

        item = wx.MenuItem(self._visualMenu, MENU_DRAW_TAB_X, "Draw X button On Active Tab",
                           "Draw X button On Active Tab", wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnDrawTabX, item)
        self._visualMenu.AppendItem(item)

        item = wx.MenuItem(self._visualMenu, MENU_SET_ACTIVE_TAB_COLOUR, "Select Active Tab Colour",
                           "Select Active Tab Colour")
        self.Bind(wx.EVT_MENU, self.OnSelectColour, item)
        self._visualMenu.AppendItem(item)

        item = wx.MenuItem(self._visualMenu, MENU_SET_TAB_AREA_COLOUR, "Select Tab Area Colour",
                           "Select Tab Area Colour")
        self.Bind(wx.EVT_MENU, self.OnSelectColour, item)
        self._visualMenu.AppendItem(item)

        item = wx.MenuItem(self._visualMenu, MENU_SET_ACTIVE_TEXT_COLOUR, "Select active tab text colour",
                           "Select active tab text colour")
        self.Bind(wx.EVT_MENU, self.OnSelectColour, item)
        self._visualMenu.AppendItem(item)

        item = wx.MenuItem(self._visualMenu, MENU_SELECT_NONACTIVE_TEXT_COLOUR,
                           "Select NON-active tab text colour", "Select NON-active tab text colour")
        self.Bind(wx.EVT_MENU, self.OnSelectColour, item)
        self._visualMenu.AppendItem(item)

        item = wx.MenuItem(self._visualMenu, MENU_GRADIENT_BACKGROUND, "Use Gradient Colouring for tab area",
                           "Use Gradient Colouring for tab area", wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnGradientBack, item)
        self._visualMenu.AppendItem(item)
        item.Check(False)

        item = wx.MenuItem(self._visualMenu, MENU_COLOURFUL_TABS, "Colourful tabs", "Colourful tabs", wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnColourfulTabs, item)
        self._visualMenu.AppendItem(item)
        item.Check(False)

        help_menu = wx.Menu()
        item = wx.MenuItem(help_menu, wx.ID_ANY, "About...", "Shows The About Dialog")
        self.Bind(wx.EVT_MENU, self.OnAbout, item)
        help_menu.AppendItem(item)

        self._menuBar.Append(self._fileMenu, "&File")
        self._menuBar.Append(self._editMenu, "&Edit")
        self._menuBar.Append(self._visualMenu, "&Tab Appearance")

        self._menuBar.Append(help_menu, "&Help")

        self.SetMenuBar(self._menuBar)


    def CreateRightClickMenu(self):

        self._rmenu = wx.Menu()
        item = wx.MenuItem(self._rmenu, MENU_EDIT_DELETE_PAGE, "Close Tab\tCtrl+F4", "Close Tab")
        self._rmenu.AppendItem(item)


    def LayoutItems(self):

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(mainSizer)

        bookStyle = FNB.FNB_NODRAG

        self.book = FNB.FlatNotebook(self, wx.ID_ANY, agwStyle=bookStyle)

        bookStyle &= ~(FNB.FNB_NODRAG)
        bookStyle |= FNB.FNB_ALLOW_FOREIGN_DND 
        self.secondBook = FNB.FlatNotebook(self, wx.ID_ANY, agwStyle=bookStyle)

        # Set right click menu to the notebook
        self.book.SetRightClickMenu(self._rmenu)

        # Set the image list 
        self.book.SetImageList(self._ImageList)
        mainSizer.Add(self.book, 6, wx.EXPAND)

        # Add spacer between the books
        spacer = wx.Panel(self, -1)
        spacer.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE))
        mainSizer.Add(spacer, 0, wx.ALL | wx.EXPAND)

        mainSizer.Add(self.secondBook, 2, wx.EXPAND)

        # Add some pages to the second notebook
        self.Freeze()

        text = wx.TextCtrl(self.secondBook, -1, "Second Book Page 1\n", style=wx.TE_MULTILINE|wx.TE_READONLY)  
        self.secondBook.AddPage(text, "Second Book Page 1")

        text = wx.TextCtrl(self.secondBook, -1, "Second Book Page 2\n", style=wx.TE_MULTILINE|wx.TE_READONLY)
        self.secondBook.AddPage(text,  "Second Book Page 2")

        self.Thaw() 

        mainSizer.Layout()
        self.SendSizeEvent()


    def OnStyle(self, event):

        style = self.book.GetAGWWindowStyleFlag()
        eventid = event.GetId()

        if eventid == MENU_HIDE_NAV_BUTTONS:
            if event.IsChecked():            
                # Hide the navigation buttons
                style |= FNB.FNB_NO_NAV_BUTTONS
            else:
                style &= ~FNB.FNB_NO_NAV_BUTTONS
                style &= ~FNB.FNB_DROPDOWN_TABS_LIST

            self.book.SetAGWWindowStyleFlag(style)

        elif eventid == MENU_HIDE_ON_SINGLE_TAB:
            if event.IsChecked():
                # Hide the navigation buttons
                style |= FNB.FNB_HIDE_ON_SINGLE_TAB
            else:
                style &= ~(FNB.FNB_HIDE_ON_SINGLE_TAB)
                
            self.book.SetAGWWindowStyleFlag(style)
                
        elif eventid == MENU_HIDE_TABS:
            if event.IsChecked():
                # Hide the tabs
                style |= FNB.FNB_HIDE_TABS
            else:
                style &= ~(FNB.FNB_HIDE_TABS)

            self.book.SetAGWWindowStyleFlag(style)

        elif eventid == MENU_HIDE_X:
            if event.IsChecked():
                # Hide the X button
                style |= FNB.FNB_NO_X_BUTTON
            else:
                if style & FNB.FNB_NO_X_BUTTON:
                    style ^= FNB.FNB_NO_X_BUTTON

            self.book.SetAGWWindowStyleFlag(style)

        elif eventid == MENU_DRAW_BORDER:
            if event.IsChecked():
                style |= FNB.FNB_TABS_BORDER_SIMPLE
            else:
                if style & FNB.FNB_TABS_BORDER_SIMPLE:
                    style ^= FNB.FNB_TABS_BORDER_SIMPLE

            self.book.SetAGWWindowStyleFlag(style)

        elif eventid == MENU_USE_MOUSE_MIDDLE_BTN:
            if event.IsChecked():
                style |= FNB.FNB_MOUSE_MIDDLE_CLOSES_TABS            
            else:
                if style & FNB.FNB_MOUSE_MIDDLE_CLOSES_TABS:
                    style ^= FNB.FNB_MOUSE_MIDDLE_CLOSES_TABS

            self.book.SetAGWWindowStyleFlag(style)

        elif eventid == MENU_USE_BOTTOM_TABS:
            if event.IsChecked():
                style |= FNB.FNB_BOTTOM
            else:
                if style & FNB.FNB_BOTTOM:
                    style ^= FNB.FNB_BOTTOM

            self.book.SetAGWWindowStyleFlag(style)
            self.book.Refresh()

        elif eventid == MENU_NO_TABS_FOCUS:
            if event.IsChecked():
                # Hide the navigation buttons
                style |= FNB.FNB_NO_TAB_FOCUS
            else:
                style &= ~(FNB.FNB_NO_TAB_FOCUS)

            self.book.SetAGWWindowStyleFlag(style)


    def OnQuit(self, event):

        self.Destroy()


    def OnDeleteAll(self, event):

        self.book.DeleteAllPages()


    def OnShowImages(self, event):

        self._bShowImages = event.IsChecked()


    def OnForeignDrop(self, event):

        self.log.write('Foreign drop received\n')
        self.log.write('new NB: %s  ||  old NB: %s\n' % (event.GetNotebook(), event.GetOldNotebook()))
        self.log.write('new tab: %s  ||  old tab: %s\n' % (event.GetSelection(), event.GetOldSelection()))
        

    def OnDrop(self, event):

        self.log.write('Drop received - same notebook\n')
        self.log.write('new: %s old: %s\n' % (event.GetSelection(), event.GetOldSelection()))


    def OnFF2Style(self, event):

        style = self.book.GetAGWWindowStyleFlag()

        # remove old tabs style
        mirror = ~(FNB.FNB_VC71 | FNB.FNB_VC8 | FNB.FNB_FANCY_TABS | FNB.FNB_FF2 | FNB.FNB_RIBBON_TABS)
        style &= mirror

        style |= FNB.FNB_FF2

        self.book.SetAGWWindowStyleFlag(style)


    def OnVC71Style(self, event):

        style = self.book.GetAGWWindowStyleFlag()

        # remove old tabs style
        mirror = ~(FNB.FNB_VC71 | FNB.FNB_VC8 | FNB.FNB_FANCY_TABS | FNB.FNB_FF2 | FNB.FNB_RIBBON_TABS)
        style &= mirror

        style |= FNB.FNB_VC71

        self.book.SetAGWWindowStyleFlag(style)


    def OnVC8Style(self, event):

        style = self.book.GetAGWWindowStyleFlag()

        # remove old tabs style
        mirror = ~(FNB.FNB_VC71 | FNB.FNB_VC8 | FNB.FNB_FANCY_TABS | FNB.FNB_FF2 | FNB.FNB_RIBBON_TABS)
        style &= mirror

        # set new style
        style |= FNB.FNB_VC8

        self.book.SetAGWWindowStyleFlag(style)
        
    def OnRibbonStyle(self, event):

        style = self.book.GetAGWWindowStyleFlag()

        # remove old tabs style
        mirror = ~(FNB.FNB_VC71 | FNB.FNB_VC8 | FNB.FNB_FANCY_TABS | FNB.FNB_FF2 | FNB.FNB_RIBBON_TABS)
        style &= mirror

        # set new style
        style |= FNB.FNB_RIBBON_TABS

        self.book.SetAGWWindowStyleFlag(style)


    def OnDefaultStyle(self, event):

        style = self.book.GetAGWWindowStyleFlag()

        # remove old tabs style
        mirror = ~(FNB.FNB_VC71 | FNB.FNB_VC8 | FNB.FNB_FANCY_TABS | FNB.FNB_FF2 | FNB.FNB_RIBBON_TABS)
        style &= mirror

        self.book.SetAGWWindowStyleFlag(style)


    def OnFancyStyle(self, event):

        style = self.book.GetAGWWindowStyleFlag()

        # remove old tabs style
        mirror = ~(FNB.FNB_VC71 | FNB.FNB_VC8 | FNB.FNB_FANCY_TABS | FNB.FNB_FF2 | FNB.FNB_RIBBON_TABS)
        style &= mirror

        style |= FNB.FNB_FANCY_TABS
        self.book.SetAGWWindowStyleFlag(style)
        

    def OnSelectColour(self, event):

        eventid = event.GetId()

        # Open a colour dialog
        data = wx.ColourData()

        dlg = wx.ColourDialog(self, data)

        if dlg.ShowModal() == wx.ID_OK:

            if eventid == MENU_SELECT_GRADIENT_COLOUR_BORDER:
                self.book.SetGradientColourBorder(dlg.GetColourData().GetColour())
            elif eventid == MENU_SELECT_GRADIENT_COLOUR_FROM:
                self.book.SetGradientColourFrom(dlg.GetColourData().GetColour())
            elif eventid == MENU_SELECT_GRADIENT_COLOUR_TO:
                self.book.SetGradientColourTo(dlg.GetColourData().GetColour())
            elif eventid == MENU_SET_ACTIVE_TEXT_COLOUR:
                self.book.SetActiveTabTextColour(dlg.GetColourData().GetColour())
            elif eventid == MENU_SELECT_NONACTIVE_TEXT_COLOUR:
                self.book.SetNonActiveTabTextColour(dlg.GetColourData().GetColour())
            elif eventid == MENU_SET_ACTIVE_TAB_COLOUR:
                self.book.SetActiveTabColour(dlg.GetColourData().GetColour())
            elif eventid == MENU_SET_TAB_AREA_COLOUR:
                self.book.SetTabAreaColour(dlg.GetColourData().GetColour())

            self.book.Refresh()


    def OnAddPage(self, event):

        caption = "New Page Added #" + str(self._newPageCounter)

        self.Freeze()

        image = -1
        if self._bShowImages:
            image = random.randint(0, self._ImageList.GetImageCount()-1)

        self.book.AddPage(self.CreatePage(caption), caption, True, image)
        self.Thaw()
        self._newPageCounter = self._newPageCounter + 1


    def CreatePage(self, caption):

        p = wx.Panel(self.book, style=wx.SUNKEN_BORDER|wx.TAB_TRAVERSAL)
        wx.StaticText(p, -1, caption, (20,20))
        wx.TextCtrl(p, -1, "", (20,40), (150,-1))
        return p


    def OnDeletePage(self, event):

        self.book.DeletePage(self.book.GetSelection())


    def OnSetSelection(self, event):

        dlg = wx.TextEntryDialog(self, "Enter Tab Number to select:", "Set Selection")

        if dlg.ShowModal() == wx.ID_OK:

            val = dlg.GetValue()
            self.book.SetSelection(int(val))


    def OnEnableTab(self, event):

        dlg = wx.TextEntryDialog(self, "Enter Tab Number to enable:", "Enable Tab")

        if dlg.ShowModal() == wx.ID_OK:

            val = dlg.GetValue()
            self.book.EnableTab(int(val))   


    def OnDisableTab(self, event):

        dlg = wx.TextEntryDialog(self, "Enter Tab Number to disable:", "Disable Tab")

        if dlg.ShowModal() == wx.ID_OK:

            val = dlg.GetValue()
            self.book.EnableTab(int(val), False)    


    def OnEnableDrag(self, event):

        style = self.book.GetAGWWindowStyleFlag()
        style2 = self.secondBook.GetAGWWindowStyleFlag()

        if event.IsChecked():        
            if style & FNB.FNB_NODRAG:
                style ^= FNB.FNB_NODRAG
            if style2 & FNB.FNB_NODRAG:
                style2 ^= FNB.FNB_NODRAG
        else:
            style |= FNB.FNB_NODRAG
            style2 |= FNB.FNB_NODRAG

        self.book.SetAGWWindowStyleFlag(style)
        self.secondBook.SetAGWWindowStyleFlag(style2)


    def OnAllowForeignDnd(self, event): 

        style = self.book.GetAGWWindowStyleFlag()
        if event.IsChecked():
            style |= FNB.FNB_ALLOW_FOREIGN_DND 
        else:
            style &= ~(FNB.FNB_ALLOW_FOREIGN_DND)

        self.book.SetAGWWindowStyleFlag(style)
        self.book.Refresh() 


    def OnSetAllPagesShapeAngle(self, event):


        dlg = wx.TextEntryDialog(self, "Enter an inclination of header borders (0-15):", "Set Angle")
        if dlg.ShowModal() == wx.ID_OK:

            val = dlg.GetValue()
            self.book.SetAllPagesShapeAngle(int(val))


    def OnSetPageImage(self, event):

        dlg = wx.TextEntryDialog(self, "Enter an image index (0-%i):"%(self.book.GetImageList().GetImageCount()-1), "Set Image Index")
        if dlg.ShowModal() == wx.ID_OK:
            val = dlg.GetValue()
            self.book.SetPageImage(self.book.GetSelection(), int(val))


    def OnAdvanceSelectionFwd(self, event):

        self.book.AdvanceSelection(True)


    def OnAdvanceSelectionBack(self, event):

        self.book.AdvanceSelection(False)


    def OnPageChanging(self, event):

        self.log.write("Page Changing From %d To %d" % (event.GetOldSelection(), event.GetSelection()))
        event.Skip()


    def OnPageChanged(self, event):

        self.log.write("Page Changed To %d" % event.GetSelection())
        event.Skip()


    def OnPageClosing(self, event):

        self.log.write("Page Closing, Selection: %d" % event.GetSelection())
        event.Skip()


    def OnDrawTabX(self, event):

        style = self.book.GetAGWWindowStyleFlag()
        if event.IsChecked():
            style |= FNB.FNB_X_ON_TAB
        else:
            if style & FNB.FNB_X_ON_TAB:
                style ^= FNB.FNB_X_ON_TAB       

        self.book.SetAGWWindowStyleFlag(style)


    def OnDClickCloseTab(self, event):

        style = self.book.GetAGWWindowStyleFlag()
        if event.IsChecked():       
            style |= FNB.FNB_DCLICK_CLOSES_TABS
        else:
            style &= ~(FNB.FNB_DCLICK_CLOSES_TABS)      

        self.book.SetAGWWindowStyleFlag(style)


    def OnGradientBack(self, event):

        style = self.book.GetAGWWindowStyleFlag()
        if event.IsChecked():
            style |= FNB.FNB_BACKGROUND_GRADIENT
        else:
            style &= ~(FNB.FNB_BACKGROUND_GRADIENT)

        self.book.SetAGWWindowStyleFlag(style)
        self.book.Refresh()


    def OnColourfulTabs(self, event):

        style = self.book.GetAGWWindowStyleFlag()
        if event.IsChecked():
            style |= FNB.FNB_COLOURFUL_TABS
        else:
            style &= ~(FNB.FNB_COLOURFUL_TABS)

        self.book.SetAGWWindowStyleFlag(style)
        self.book.Refresh()


    def OnSmartTabs(self, event):

        style = self.book.GetAGWWindowStyleFlag()
        if event.IsChecked():
            style |= FNB.FNB_SMART_TABS
        else:
            style &= ~FNB.FNB_SMART_TABS

        self.book.SetAGWWindowStyleFlag(style)
        self.book.Refresh()


    def OnDropDownArrow(self, event):

        style = self.book.GetAGWWindowStyleFlag()

        if event.IsChecked():

            style |= FNB.FNB_DROPDOWN_TABS_LIST
            style |= FNB.FNB_NO_NAV_BUTTONS

        else:

            style &= ~FNB.FNB_DROPDOWN_TABS_LIST
            style &= ~FNB.FNB_NO_NAV_BUTTONS

        self.book.SetAGWWindowStyleFlag(style)
        self.book.Refresh()


    def OnTile(self, event):

        evId = event.GetId()
        if evId == MENU_TILE_HORIZONTALLY:
            self.book.Tile(wx.HORIZONTAL)
        elif evId == MENU_TILE_VERTICALLY:
            self.book.Tile(wx.VERTICAL)
        else:
            self.book.Tile(None)
        

    def OnCustomPanel(self, event):

        if event.IsChecked():
            custom = LogoPanel(self.book, -1)
            self.book.SetCustomPage(custom)
        else:
            self.book.SetCustomPage(None)


    def OnHideNavigationButtonsUI(self, event):

        style = self.book.GetAGWWindowStyleFlag()
        event.Check((style & FNB.FNB_NO_NAV_BUTTONS and [True] or [False])[0])


    def OnDropDownArrowUI(self, event):

        style = self.book.GetAGWWindowStyleFlag()
        event.Check((style & FNB.FNB_DROPDOWN_TABS_LIST and [True] or [False])[0])


    def OnAllowForeignDndUI(self, event): 

        style = self.book.GetAGWWindowStyleFlag()
        event.Enable((style & FNB.FNB_NODRAG and [False] or [True])[0])


    def OnAbout(self, event):

        msg = "This Is The About Dialog Of The FlatNotebook Demo.\n\n" + \
            "Author: Andrea Gavana @ 02 Oct 2006\n\n" + \
            "Please Report Any Bug/Requests Of Improvements\n" + \
            "To Me At The Following Adresses:\n\n" + \
            "andrea.gavana@gmail.com\n" + "andrea.gavana@maerskoil.com\n\n" + \
            "Based On Eran C++ Implementation (wxWidgets Forum).\n\n" + \
            "Welcome To wxPython " + wx.VERSION_STRING + "!!"

        dlg = wx.MessageDialog(self, msg, "FlatNotebook wxPython Demo",
                               wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()        


class LogoPanel(wx.Panel):

    def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize,
                 style=wx.CLIP_CHILDREN):

        wx.Panel.__init__(self, parent, id, pos, size, style)

        self.SetBackgroundColour(wx.WHITE)
        self.bmp = images.Vippi.GetBitmap()

        self.bigfont = wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD, False)
        self.normalfont = wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD, True)

        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
        
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_SIZE, self.OnSize)


    def OnSize(self, event):

        event.Skip()
        self.Refresh()
        

    def OnPaint(self, event):
        
        dc = wx.AutoBufferedPaintDC(self)
        self.DoDrawing(dc)    
        

    def DoDrawing(self, dc):

        dc.SetBackground(wx.WHITE_BRUSH)
        dc.Clear()
        
        w, h = self.GetClientSize()
        bmpW, bmpH = self.bmp.GetWidth(), self.bmp.GetHeight()

        xpos, ypos = int((w - bmpW)/2), int((h - bmpH)/2)
        
        dc.DrawBitmap(self.bmp, xpos, ypos, True)

        dc.SetFont(self.bigfont)
        dc.SetTextForeground(wx.BLUE)
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
        dc.SetPen(wx.Pen(wx.BLUE, 2))
        
        tw, th = dc.GetTextExtent("FlatNotebook")
        xpos = int((w - tw)/2)
        ypos = int(h/3)

        dc.DrawRoundedRectangle(xpos-5, ypos-3, tw+10, th+6, 3)
        dc.DrawText("FlatNotebook", xpos, ypos)
        
        dc.SetFont(self.normalfont)
        dc.SetTextForeground(wx.RED)
        tw, th = dc.GetTextExtent("Andrea Gavana")
        xpos = int((w - tw)/2)
        ypos = int(2*h/3)
        dc.DrawText("Andrea Gavana", xpos, ypos)
        tw, th = dc.GetTextExtent("02 Oct 2006")

        xpos = int((w - tw)/2)
        ypos = int(2*h/3 + 3*th/2)
        
        dc.DrawText("02 Oct 2006", xpos, ypos)
        

#---------------------------------------------------------------------------


class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        b = wx.Button(self, -1, " Test FlatNotebook ", (50,50))
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)


    def OnButton(self, evt):
        self.win = FlatNotebookDemo(self, self.log)
        self.win.Show(True)

#----------------------------------------------------------------------

def runTest(frame, nb, log):
    win = TestPanel(nb, log)
    return win

#----------------------------------------------------------------------


overview = FNB.__doc__



if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])