]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-06/example4.py
2 from example1
import SketchWindow
5 class SketchFrame(wx
.Frame
):
6 def __init__(self
, parent
):
7 wx
.Frame
.__init
__(self
, parent
, -1, "Sketch Frame",
9 self
.sketch
= SketchWindow(self
, -1)
10 self
.sketch
.Bind(wx
.EVT_MOTION
, self
.OnSketchMotion
)
14 def initStatusBar(self
):
15 self
.statusbar
= self
.CreateStatusBar()
16 self
.statusbar
.SetFieldsCount(3)
17 self
.statusbar
.SetStatusWidths([-1, -2, -3])
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)
30 ("&New", "New Sketch file", self
.OnNew
),
31 ("&Open", "Open sketch file", self
.OnOpen
),
32 ("&Save", "Save sketch file", self
.OnSave
),
35 ("&Black", "", self
.OnColor
,
37 ("&Red", "", self
.OnColor
,
39 ("&Green", "", self
.OnColor
,
41 ("&Blue", "", self
.OnColor
,
44 ("&Quit", "Quit", self
.OnCloseWindow
)))]
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
)
54 def createMenu(self
, menuData
):
56 for eachItem
in menuData
:
57 if len(eachItem
) == 2:
59 subMenu
= self
.createMenu(eachItem
[1])
60 menu
.AppendMenu(wx
.NewId(), label
, subMenu
)
62 self
.createMenuItem(menu
, *eachItem
)
65 def createMenuItem(self
, menu
, label
, status
, handler
,
68 menu
.AppendSeparator()
70 menuItem
= menu
.Append(-1, label
, status
, kind
)
71 self
.Bind(wx
.EVT_MENU
, handler
, menuItem
)
73 def OnNew(self
, event
): pass
74 def OnOpen(self
, event
): pass
75 def OnSave(self
, event
): pass
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
)
84 def OnCloseWindow(self
, event
):
88 if __name__
== '__main__':
89 app
= wx
.PySimpleApp()
90 frame
= SketchFrame(None)