]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxMenu.py
Patch [ 588732 ] makes wxRB_GROUP/radiobuttons working
[wxWidgets.git] / wxPython / demo / wxMenu.py
1 #-------------------------------------------------------------------
2 # essaimenu.py
3 #
4 # menus in wxPython 2.3.3
5 #
6 #-------------------------------------------------------------------
7
8 from wxPython.wx import *
9
10 #-------------------------------------------------------------------
11
12 class MyFrame(wxFrame):
13
14 def __init__(self, parent, id, log):
15 wxFrame.__init__(self, parent, id, 'Playing with menus', size=(400, 200))
16 self.log = log
17 self.CenterOnScreen()
18
19 self.CreateStatusBar()
20 self.SetStatusText("This is the statusbar")
21
22 # Prepare the menu bar
23 menuBar = wxMenuBar()
24
25 # 1st menu from left
26 menu1 = wxMenu()
27 menu1.Append(101, "Mercury", "This the text in the Statusbar")
28 menu1.Append(102, "Venus", "")
29 menu1.Append(103, "Earth", "You may select Earth too")
30 menu1.AppendSeparator()
31 menu1.Append(104, "Exit", "Close this frame")
32 # Add menu to the menu bar
33 menuBar.Append(menu1, "&Planets")
34
35 # 2nd menu from left
36 menu2 = wxMenu()
37 menu2.Append(201, "Hydrogen")
38 menu2.Append(202, "Helium")
39 # a submenu in the 2nd menu
40 submenu = wxMenu()
41 submenu.Append(2031,"Lanthanium")
42 submenu.Append(2032,"Cerium")
43 submenu.Append(2033,"Praseodymium")
44 menu2.AppendMenu(203, "Lanthanides", submenu)
45 # Append 2nd menu
46 menuBar.Append(menu2, "&Elements")
47
48 menu3 = wxMenu()
49 menu3.Append(301, "IDLE", "a Python shell using tcl/tk as GUI", wxITEM_RADIO)
50 menu3.Append(302, "PyCrust", "a Python shell using wxPython as GUI", wxITEM_RADIO)
51 menu3.Append(303, "psi", "a simple Python shell using wxPython as GUI", wxITEM_RADIO)
52 menu3.AppendSeparator()
53 menu3.Append(304, "project1", "", wxITEM_NORMAL)
54 menu3.Append(305, "project2", "", wxITEM_NORMAL)
55 menuBar.Append(menu3, "&Shells")
56
57 menu4 = wxMenu()
58 menu4.Append(401, "letters", "abcde...", wxITEM_CHECK)
59 menu4.Append(402, "digits", "123...", wxITEM_CHECK)
60 menu4.Append(403, "letters and digits", "abcd... + 123...", wxITEM_CHECK)
61 menuBar.Append(menu4, "Chec&k")
62
63 menu5 = wxMenu()
64 menu5.Append(501, "Interesting thing\tCtrl+A", "Note the shortcut!")
65
66 menu5.AppendSeparator()
67 menu5.Append(502, "Hello\tShift+H")
68 menuBar.Append(menu5, "&Fun")
69
70 self.SetMenuBar(menuBar)
71
72 # Menu events
73 EVT_MENU(self, 101, self.Menu101)
74 EVT_MENU(self, 102, self.Menu102)
75 EVT_MENU(self, 103, self.Menu103)
76 EVT_MENU(self, 104, self.CloseWindow)
77
78 EVT_MENU(self, 201, self.Menu201)
79 EVT_MENU(self, 202, self.Menu202)
80 EVT_MENU(self, 2031, self.Menu2031)
81 EVT_MENU(self, 2032, self.Menu2032)
82 EVT_MENU(self, 2033, self.Menu2033)
83
84 EVT_MENU(self, 301, self.Menu301To303)
85 EVT_MENU(self, 302, self.Menu301To303)
86 EVT_MENU(self, 303, self.Menu301To303)
87 EVT_MENU(self, 304, self.Menu304)
88 EVT_MENU(self, 305, self.Menu305)
89
90 EVT_MENU_RANGE(self, 401, 403, self.Menu401To403)
91
92 EVT_MENU(self, 501, self.Menu501)
93 EVT_MENU(self, 502, self.Menu502)
94
95 # Methods
96
97 def Menu101(self, event):
98 self.log.write('Welcome to Mercury\n')
99
100 def Menu102(self, event):
101 self.log.write('Welcome to Venus\n')
102
103 def Menu103(self, event):
104 self.log.write('Welcome to the Earth\n')
105
106 def CloseWindow(self, event):
107 self.Close()
108
109 def Menu201(self, event):
110 self.log.write('Chemical element number 1\n')
111
112 def Menu202(self, event):
113 self.log.write('Chemical element number 2\n')
114
115 def Menu2031(self, event):
116 self.log.write('Element number 57\n')
117
118 def Menu2032(self, event):
119 self.log.write('Element number 58\n')
120
121 def Menu2033(self, event):
122 self.log.write('Element number 59\n')
123
124 def Menu301To303(self, event):
125 id = event.GetId()
126 self.log.write('Event id: %d\n' % id)
127
128 def Menu304(self, event):
129 self.log.write('Not yet available\n')
130
131 def Menu305(self, event):
132 self.log.write('Still vapour\n')
133
134 def Menu401To403(self, event):
135 self.log.write('From a EVT_MENU_RANGE event\n')
136
137 def Menu501(self, event):
138 self.log.write('Look in the code how the shortcut has been realized\n')
139
140 def Menu502(self, event):
141 self.log.write('Hello from Jean-Michel\n')
142
143 #-------------------------------------------------------------------
144
145 def runTest(frame, nb, log):
146 win = MyFrame(frame, -1, log)
147 frame.otherWin = win
148 win.Show(true)
149
150
151 #-------------------------------------------------------------------
152
153
154 overview = """\
155 A demo of using wxMenuBar and wxMenu in various ways.
156 """
157
158
159
160
161 if __name__ == '__main__':
162 import sys,os
163 import run
164 run.main(['', os.path.basename(sys.argv[0])])
165