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