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