]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Notebook.py
797f453e715981569674e05370f057422914892a
[wxWidgets.git] / wxPython / demo / Notebook.py
1
2 import sys
3
4 import wx
5
6 import ColorPanel
7 import GridSimple
8 import ListCtrl
9 import ScrolledWindow
10 import images
11
12 #----------------------------------------------------------------------------
13
14 class TestNB(wx.Notebook):
15 def __init__(self, parent, id, log):
16 wx.Notebook.__init__(self, parent, id, size=(21,21), style=
17 wx.BK_DEFAULT
18 #wx.BK_TOP
19 #wx.BK_BOTTOM
20 #wx.BK_LEFT
21 #wx.BK_RIGHT
22 # | wx.NB_MULTILINE
23 )
24 self.log = log
25
26 win = self.makeColorPanel(wx.BLUE)
27 self.AddPage(win, "Blue")
28 st = wx.StaticText(win.win, -1,
29 "You can put nearly any type of window here,\n"
30 "and if the platform supports it then the\n"
31 "tabs can be on any side of the notebook.",
32 (10, 10))
33
34 st.SetForegroundColour(wx.WHITE)
35 st.SetBackgroundColour(wx.BLUE)
36
37 # Show how to put an image on one of the notebook tabs,
38 # first make the image list:
39 il = wx.ImageList(16, 16)
40 idx1 = il.Add(images.getSmilesBitmap())
41 self.AssignImageList(il)
42
43 # now put an image on the first tab we just created:
44 self.SetPageImage(0, idx1)
45
46
47 win = self.makeColorPanel(wx.RED)
48 self.AddPage(win, "Red")
49
50 win = ScrolledWindow.MyCanvas(self)
51 self.AddPage(win, 'ScrolledWindow')
52
53 win = self.makeColorPanel(wx.GREEN)
54 self.AddPage(win, "Green")
55
56 win = GridSimple.SimpleGrid(self, log)
57 self.AddPage(win, "Grid")
58
59 win = ListCtrl.TestListCtrlPanel(self, log)
60 self.AddPage(win, 'List')
61
62 win = self.makeColorPanel(wx.CYAN)
63 self.AddPage(win, "Cyan")
64
65 # win = self.makeColorPanel(wxWHITE)
66 # self.AddPage(win, "White")
67
68 # win = self.makeColorPanel(wxBLACK)
69 # self.AddPage(win, "Black")
70
71 win = self.makeColorPanel(wx.NamedColour('MIDNIGHT BLUE'))
72 self.AddPage(win, "MIDNIGHT BLUE")
73
74 win = self.makeColorPanel(wx.NamedColour('INDIAN RED'))
75 self.AddPage(win, "INDIAN RED")
76
77 self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
78 self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
79
80
81 def makeColorPanel(self, color):
82 p = wx.Panel(self, -1)
83 win = ColorPanel.ColoredPanel(p, color)
84 p.win = win
85
86 def OnCPSize(evt, win=win):
87 win.SetSize(evt.GetSize())
88
89 p.Bind(wx.EVT_SIZE, OnCPSize)
90 return p
91
92 def OnPageChanged(self, event):
93 old = event.GetOldSelection()
94 new = event.GetSelection()
95 sel = self.GetSelection()
96 self.log.write('OnPageChanged, old:%d, new:%d, sel:%d\n' % (old, new, sel))
97 event.Skip()
98
99 def OnPageChanging(self, event):
100 old = event.GetOldSelection()
101 new = event.GetSelection()
102 sel = self.GetSelection()
103 self.log.write('OnPageChanging, old:%d, new:%d, sel:%d\n' % (old, new, sel))
104 event.Skip()
105
106 #----------------------------------------------------------------------------
107
108 def runTest(frame, nb, log):
109 testWin = TestNB(nb, -1, log)
110 return testWin
111
112 #----------------------------------------------------------------------------
113
114
115 overview = """\
116 <html><body>
117 <h2>wx.Notebook</h2>
118 <p>
119 This class represents a notebook control, which manages multiple
120 windows with associated tabs.
121 <p>
122 To use the class, create a wx.Notebook object and call AddPage or
123 InsertPage, passing a window to be used as the page. Do not explicitly
124 delete the window for a page that is currently managed by wx.Notebook.
125
126 """
127
128
129 if __name__ == '__main__':
130 import sys,os
131 import run
132 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
133
134
135
136
137