]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-06/example4.py
don't use invalid wxIconBundles, it results in asserts after recent changes
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-06 / example4.py
1 import wx
2 from example1 import SketchWindow
3
4
5 class SketchFrame(wx.Frame):
6 def __init__(self, parent):
7 wx.Frame.__init__(self, parent, -1, "Sketch Frame",
8 size=(800,600))
9 self.sketch = SketchWindow(self, -1)
10 self.sketch.Bind(wx.EVT_MOTION, self.OnSketchMotion)
11 self.initStatusBar()
12 self.createMenuBar()
13
14 def initStatusBar(self):
15 self.statusbar = self.CreateStatusBar()
16 self.statusbar.SetFieldsCount(3)
17 self.statusbar.SetStatusWidths([-1, -2, -3])
18
19 def OnSketchMotion(self, event):
20 self.statusbar.SetStatusText("Pos: %s" %
21 str(event.GetPositionTuple()), 0)
22 self.statusbar.SetStatusText("Current Pts: %s" %
23 len(self.sketch.curLine), 1)
24 self.statusbar.SetStatusText("Line Count: %s" %
25 len(self.sketch.lines), 2)
26 event.Skip()
27
28 def menuData(self):
29 return [("&File", (
30 ("&New", "New Sketch file", self.OnNew),
31 ("&Open", "Open sketch file", self.OnOpen),
32 ("&Save", "Save sketch file", self.OnSave),
33 ("", "", ""),
34 ("&Color", (
35 ("&Black", "", self.OnColor,
36 wx.ITEM_RADIO),
37 ("&Red", "", self.OnColor,
38 wx.ITEM_RADIO),
39 ("&Green", "", self.OnColor,
40 wx.ITEM_RADIO),
41 ("&Blue", "", self.OnColor,
42 wx.ITEM_RADIO))),
43 ("", "", ""),
44 ("&Quit", "Quit", self.OnCloseWindow)))]
45
46 def createMenuBar(self):
47 menuBar = wx.MenuBar()
48 for eachMenuData in self.menuData():
49 menuLabel = eachMenuData[0]
50 menuItems = eachMenuData[1]
51 menuBar.Append(self.createMenu(menuItems), menuLabel)
52 self.SetMenuBar(menuBar)
53
54 def createMenu(self, menuData):
55 menu = wx.Menu()
56 for eachItem in menuData:
57 if len(eachItem) == 2:
58 label = eachItem[0]
59 subMenu = self.createMenu(eachItem[1])
60 menu.AppendMenu(wx.NewId(), label, subMenu)
61 else:
62 self.createMenuItem(menu, *eachItem)
63 return menu
64
65 def createMenuItem(self, menu, label, status, handler,
66 kind=wx.ITEM_NORMAL):
67 if not label:
68 menu.AppendSeparator()
69 return
70 menuItem = menu.Append(-1, label, status, kind)
71 self.Bind(wx.EVT_MENU, handler, menuItem)
72
73 def OnNew(self, event): pass
74 def OnOpen(self, event): pass
75 def OnSave(self, event): pass
76
77 def OnColor(self, event):
78 menubar = self.GetMenuBar()
79 itemId = event.GetId()
80 item = menubar.FindItemById(itemId)
81 color = item.GetLabel()
82 self.sketch.SetColor(color)
83
84 def OnCloseWindow(self, event):
85 self.Destroy()
86
87
88 if __name__ == '__main__':
89 app = wx.PySimpleApp()
90 frame = SketchFrame(None)
91 frame.Show(True)
92 app.MainLoop()