Skip to content

Commit 7caa19e

Browse files
2 parents 77f3c57 + bcb570a commit 7caa19e

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

week-09/code/jeffs_menu_demo.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import wx
2+
3+
def file_open(obj):
4+
"""This method opens a file"""
5+
print "Open a file from file_open()"
6+
7+
def file_close(obj):
8+
"""This method closes a file"""
9+
print "Close a file from file_close()"
10+
11+
12+
13+
class MyForm(wx.Frame):
14+
15+
16+
def __init__(self):
17+
wx.Frame.__init__(self, None, wx.ID_ANY, "wx.Menu Tutorial")
18+
19+
# Add a panel so it looks the correct on all platforms
20+
self.panel = wx.Panel(self, wx.ID_ANY)
21+
22+
menuBar = wx.MenuBar()
23+
24+
fileMenu = wx.Menu()
25+
openMenuItem = fileMenu.Append(wx.NewId(), "Open",
26+
"Open a file" )
27+
self.Bind(wx.EVT_MENU, file_open, openMenuItem )
28+
closeMenuItem = fileMenu.Append(wx.NewId(), "Close",
29+
"Close a file" )
30+
self.Bind(wx.EVT_MENU, file_close, closeMenuItem )
31+
exitMenuItem = fileMenu.Append(wx.NewId(), "Exit",
32+
"Exit the application")
33+
self.Bind(wx.EVT_MENU, self.onExit, exitMenuItem)
34+
menuBar.Append(fileMenu, "&File")
35+
36+
helpMenu = wx.Menu()
37+
helpMenuItem = helpMenu.Append(wx.NewId(), "Help",
38+
"Get help")
39+
menuBar.Append(helpMenu, "&Help")
40+
self.SetMenuBar(menuBar)
41+
42+
def onExit(self, obj):
43+
print "Exit the program here"
44+
print "The object passed to onExit is type ", type(obj),\
45+
"and has attributes", dir(obj)
46+
47+
48+
49+
# Run the program
50+
if __name__ == "__main__":
51+
app = wx.PySimpleApp()
52+
frame = MyForm().Show()
53+
app.MainLoop()

week-09/presentation-week09.tex

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ \section{wxPython}
107107

108108
\vfill
109109
{\Large Legacy: it was the best option for me when I first needed something...}
110+
See http://www.wxpython.org for more information
110111

111112
\end{frame}
112113

0 commit comments

Comments
 (0)