]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-05/goodExample.py
5 class RefactorExample(wx
.Frame
):
7 def __init__(self
, parent
, id):
8 wx
.Frame
.__init
__(self
, parent
, id, 'Refactor Example',
10 panel
= wx
.Panel(self
, -1)
11 panel
.SetBackgroundColour("White")
12 self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
)
14 self
.createButtonBar(panel
)
15 self
.createTextFields(panel
)
19 ("&Open", "Open in status bar", self
.OnOpen
),
20 ("&Quit", "Quit", self
.OnCloseWindow
)),
22 ("&Copy", "Copy", self
.OnCopy
),
23 ("C&ut", "Cut", self
.OnCut
),
24 ("&Paste", "Paste", self
.OnPaste
),
26 ("&Options...", "DisplayOptions", self
.OnOptions
)))
28 def createMenuBar(self
):
29 menuBar
= wx
.MenuBar()
30 for eachMenuData
in self
.menuData():
31 menuLabel
= eachMenuData
[0]
32 menuItems
= eachMenuData
[1:]
33 menuBar
.Append(self
.createMenu(menuItems
), menuLabel
)
34 self
.SetMenuBar(menuBar
)
36 def createMenu(self
, menuData
):
38 for eachLabel
, eachStatus
, eachHandler
in menuData
:
40 menu
.AppendSeparator()
42 menuItem
= menu
.Append(-1, eachLabel
, eachStatus
)
43 self
.Bind(wx
.EVT_MENU
, eachHandler
, menuItem
)
47 return (("First", self
.OnFirst
),
48 ("<< PREV", self
.OnPrev
),
49 ("NEXT >>", self
.OnNext
),
50 ("Last", self
.OnLast
))
52 def createButtonBar(self
, panel
, yPos
= 0):
54 for eachLabel
, eachHandler
in self
.buttonData():
56 button
= self
.buildOneButton(panel
, eachLabel
, eachHandler
, pos
)
57 xPos
+= button
.GetSize().width
59 def buildOneButton(self
, parent
, label
, handler
, pos
=(0,0)):
60 button
= wx
.Button(parent
, -1, label
, pos
)
61 self
.Bind(wx
.EVT_BUTTON
, handler
, button
)
64 def textFieldData(self
):
65 return (("First Name", (10, 50)),
66 ("Last Name", (10, 80)))
68 def createTextFields(self
, panel
):
69 for eachLabel
, eachPos
in self
.textFieldData():
70 self
.createCaptionedText(panel
, eachLabel
, eachPos
)
72 def createCaptionedText(self
, panel
, label
, pos
):
73 static
= wx
.StaticText(panel
, wx
.NewId(), label
, pos
)
74 static
.SetBackgroundColour("White")
75 textPos
= (pos
[0] + 75, pos
[1])
76 wx
.TextCtrl(panel
, wx
.NewId(), "", size
=(100, -1), pos
=textPos
)
78 # Just grouping the empty event handlers together
79 def OnPrev(self
, event
): pass
80 def OnNext(self
, event
): pass
81 def OnLast(self
, event
): pass
82 def OnFirst(self
, event
): pass
83 def OnOpen(self
, event
): pass
84 def OnCopy(self
, event
): pass
85 def OnCut(self
, event
): pass
86 def OnPaste(self
, event
): pass
87 def OnOptions(self
, event
): pass
88 def OnCloseWindow(self
, event
):
91 if __name__
== '__main__':
92 app
= wx
.PySimpleApp()
93 frame
= RefactorExample(parent
=None, id=-1)