]>
Commit | Line | Data |
---|---|---|
3115ef3e RD |
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 | ||
eb0f373c RD |
22 | tc = wxTextCtrl(self, -1, """ |
23 | A bunch of bogus menus have been created for this frame. You | |
24 | can play around with them to see how they behave and then | |
25 | check the source for this sample to see how to implement them. | |
26 | """, style=wxTE_READONLY|wxTE_MULTILINE) | |
27 | ||
3115ef3e RD |
28 | # Prepare the menu bar |
29 | menuBar = wxMenuBar() | |
30 | ||
31 | # 1st menu from left | |
32 | menu1 = wxMenu() | |
33 | menu1.Append(101, "Mercury", "This the text in the Statusbar") | |
34 | menu1.Append(102, "Venus", "") | |
35 | menu1.Append(103, "Earth", "You may select Earth too") | |
36 | menu1.AppendSeparator() | |
eb0f373c | 37 | menu1.Append(104, "Close", "Close this frame") |
3115ef3e RD |
38 | # Add menu to the menu bar |
39 | menuBar.Append(menu1, "&Planets") | |
40 | ||
41 | # 2nd menu from left | |
42 | menu2 = wxMenu() | |
43 | menu2.Append(201, "Hydrogen") | |
44 | menu2.Append(202, "Helium") | |
45 | # a submenu in the 2nd menu | |
46 | submenu = wxMenu() | |
47 | submenu.Append(2031,"Lanthanium") | |
48 | submenu.Append(2032,"Cerium") | |
49 | submenu.Append(2033,"Praseodymium") | |
50 | menu2.AppendMenu(203, "Lanthanides", submenu) | |
51 | # Append 2nd menu | |
52 | menuBar.Append(menu2, "&Elements") | |
53 | ||
54 | menu3 = wxMenu() | |
55 | menu3.Append(301, "IDLE", "a Python shell using tcl/tk as GUI", wxITEM_RADIO) | |
56 | menu3.Append(302, "PyCrust", "a Python shell using wxPython as GUI", wxITEM_RADIO) | |
57 | menu3.Append(303, "psi", "a simple Python shell using wxPython as GUI", wxITEM_RADIO) | |
58 | menu3.AppendSeparator() | |
59 | menu3.Append(304, "project1", "", wxITEM_NORMAL) | |
60 | menu3.Append(305, "project2", "", wxITEM_NORMAL) | |
61 | menuBar.Append(menu3, "&Shells") | |
62 | ||
63 | menu4 = wxMenu() | |
64 | menu4.Append(401, "letters", "abcde...", wxITEM_CHECK) | |
65 | menu4.Append(402, "digits", "123...", wxITEM_CHECK) | |
66 | menu4.Append(403, "letters and digits", "abcd... + 123...", wxITEM_CHECK) | |
67 | menuBar.Append(menu4, "Chec&k") | |
68 | ||
69 | menu5 = wxMenu() | |
70 | menu5.Append(501, "Interesting thing\tCtrl+A", "Note the shortcut!") | |
71 | ||
72 | menu5.AppendSeparator() | |
73 | menu5.Append(502, "Hello\tShift+H") | |
74 | menuBar.Append(menu5, "&Fun") | |
75 | ||
76 | self.SetMenuBar(menuBar) | |
77 | ||
78 | # Menu events | |
79 | EVT_MENU(self, 101, self.Menu101) | |
80 | EVT_MENU(self, 102, self.Menu102) | |
81 | EVT_MENU(self, 103, self.Menu103) | |
ba2b238e | 82 | EVT_MENU(self, 104, self.CloseWindow) |
3115ef3e RD |
83 | |
84 | EVT_MENU(self, 201, self.Menu201) | |
85 | EVT_MENU(self, 202, self.Menu202) | |
86 | EVT_MENU(self, 2031, self.Menu2031) | |
87 | EVT_MENU(self, 2032, self.Menu2032) | |
88 | EVT_MENU(self, 2033, self.Menu2033) | |
89 | ||
90 | EVT_MENU(self, 301, self.Menu301To303) | |
91 | EVT_MENU(self, 302, self.Menu301To303) | |
92 | EVT_MENU(self, 303, self.Menu301To303) | |
93 | EVT_MENU(self, 304, self.Menu304) | |
94 | EVT_MENU(self, 305, self.Menu305) | |
95 | ||
96 | EVT_MENU_RANGE(self, 401, 403, self.Menu401To403) | |
97 | ||
98 | EVT_MENU(self, 501, self.Menu501) | |
99 | EVT_MENU(self, 502, self.Menu502) | |
100 | ||
101 | # Methods | |
102 | ||
103 | def Menu101(self, event): | |
104 | self.log.write('Welcome to Mercury\n') | |
105 | ||
106 | def Menu102(self, event): | |
107 | self.log.write('Welcome to Venus\n') | |
108 | ||
109 | def Menu103(self, event): | |
110 | self.log.write('Welcome to the Earth\n') | |
111 | ||
ba2b238e RD |
112 | def CloseWindow(self, event): |
113 | self.Close() | |
3115ef3e RD |
114 | |
115 | def Menu201(self, event): | |
116 | self.log.write('Chemical element number 1\n') | |
117 | ||
118 | def Menu202(self, event): | |
119 | self.log.write('Chemical element number 2\n') | |
120 | ||
121 | def Menu2031(self, event): | |
122 | self.log.write('Element number 57\n') | |
123 | ||
124 | def Menu2032(self, event): | |
125 | self.log.write('Element number 58\n') | |
126 | ||
127 | def Menu2033(self, event): | |
128 | self.log.write('Element number 59\n') | |
129 | ||
130 | def Menu301To303(self, event): | |
131 | id = event.GetId() | |
132 | self.log.write('Event id: %d\n' % id) | |
133 | ||
134 | def Menu304(self, event): | |
135 | self.log.write('Not yet available\n') | |
136 | ||
137 | def Menu305(self, event): | |
138 | self.log.write('Still vapour\n') | |
139 | ||
140 | def Menu401To403(self, event): | |
141 | self.log.write('From a EVT_MENU_RANGE event\n') | |
142 | ||
143 | def Menu501(self, event): | |
144 | self.log.write('Look in the code how the shortcut has been realized\n') | |
145 | ||
146 | def Menu502(self, event): | |
147 | self.log.write('Hello from Jean-Michel\n') | |
148 | ||
149 | #------------------------------------------------------------------- | |
150 | ||
151 | def runTest(frame, nb, log): | |
152 | win = MyFrame(frame, -1, log) | |
153 | frame.otherWin = win | |
154 | win.Show(true) | |
155 | ||
156 | ||
157 | #------------------------------------------------------------------- | |
158 | ||
159 | ||
160 | overview = """\ | |
161 | A demo of using wxMenuBar and wxMenu in various ways. | |
162 | """ | |
163 | ||
164 | ||
165 | ||
166 | ||
167 | if __name__ == '__main__': | |
168 | import sys,os | |
169 | import run | |
170 | run.main(['', os.path.basename(sys.argv[0])]) | |
171 |