]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Treebook.py
fixed child windows scrolling to use wxSIZE_ALLOW_MINUS_ONE
[wxWidgets.git] / wxPython / demo / Treebook.py
1
2 import wx
3
4 import ColorPanel
5 import images
6
7 colourList = [ "Aquamarine", "Grey", "Blue", "Blue Violet", "Brown", "Cadet Blue",
8 "Coral", "Wheat", "Cyan", "Dark Grey", "Dark Green",
9 "Steel Blue",
10 ]
11
12 #----------------------------------------------------------------------------
13
14 def getNextImageID(count):
15 imID = 0
16 while True:
17 yield imID
18 imID += 1
19 if imID == count:
20 imID = 0
21
22
23 class TestTB(wx.Treebook):
24 def __init__(self, parent, id, log):
25 wx.Treebook.__init__(self, parent, id, style=
26 wx.BK_DEFAULT
27 #wx.BK_TOP
28 #wx.BK_BOTTOM
29 #wx.BK_LEFT
30 #wx.BK_RIGHT
31 )
32 self.log = log
33
34 # make an image list using the LBXX images
35 il = wx.ImageList(32, 32)
36 for x in range(12):
37 f = getattr(images, 'getLB%02dBitmap' % (x+1))
38 bmp = f()
39 il.Add(bmp)
40 self.AssignImageList(il)
41 imageIdGenerator = getNextImageID(il.GetImageCount())
42
43 # Now make a bunch of panels for the list book
44 first = True
45 for colour in colourList:
46 win = self.makeColorPanel(colour)
47 self.AddPage(win, colour, imageId=imageIdGenerator.next())
48 if first:
49 st = wx.StaticText(win.win, -1,
50 "You can put nearly any type of window here,\n"
51 "and the wx.TreeCtrl can be on either side of the\n"
52 "Treebook",
53 wx.Point(10, 10))
54 first = False
55
56 win = self.makeColorPanel(colour)
57 st = wx.StaticText(win.win, -1, "this is a sub-page", (10,10))
58 self.AddSubPage(win, 'a sub-page', imageId=imageIdGenerator.next())
59
60 self.Bind(wx.EVT_TREEBOOK_PAGE_CHANGED, self.OnPageChanged)
61 self.Bind(wx.EVT_TREEBOOK_PAGE_CHANGING, self.OnPageChanging)
62
63 # This is a workaround for a sizing bug on Mac...
64 wx.FutureCall(100, self.AdjustSize)
65
66 def AdjustSize(self):
67 #print self.GetTreeCtrl().GetBestSize()
68 self.GetTreeCtrl().InvalidateBestSize()
69 self.SendSizeEvent()
70 #print self.GetTreeCtrl().GetBestSize()
71
72
73 def makeColorPanel(self, color):
74 p = wx.Panel(self, -1)
75 win = ColorPanel.ColoredPanel(p, color)
76 p.win = win
77 def OnCPSize(evt, win=win):
78 win.SetPosition((0,0))
79 win.SetSize(evt.GetSize())
80 p.Bind(wx.EVT_SIZE, OnCPSize)
81 return p
82
83
84 def OnPageChanged(self, event):
85 old = event.GetOldSelection()
86 new = event.GetSelection()
87 sel = self.GetSelection()
88 self.log.write('OnPageChanged, old:%d, new:%d, sel:%d\n' % (old, new, sel))
89 event.Skip()
90
91 def OnPageChanging(self, event):
92 old = event.GetOldSelection()
93 new = event.GetSelection()
94 sel = self.GetSelection()
95 self.log.write('OnPageChanging, old:%d, new:%d, sel:%d\n' % (old, new, sel))
96 event.Skip()
97
98 #----------------------------------------------------------------------------
99
100 def runTest(frame, nb, log):
101 testWin = TestTB(nb, -1, log)
102 return testWin
103
104 #----------------------------------------------------------------------------
105
106
107 overview = """\
108 <html><body>
109 <h2>wx.Treebook</h2>
110 <p>
111 This class is a control similar to a notebook control, but with a
112 wx.TreeCtrl instead of a set of tabs.
113
114 """
115
116
117
118 if __name__ == '__main__':
119 import sys,os
120 import run
121 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
122
123
124