1 #-------------------------------------------------------------------
4 # menus in wxPython 2.3.3
6 #-------------------------------------------------------------------
8 from wxPython
.wx
import *
10 #-------------------------------------------------------------------
12 class MyFrame(wxFrame
):
14 def __init__(self
, parent
, id, log
):
15 wxFrame
.__init
__(self
, parent
, id, 'Playing with menus', size
=(400, 200))
19 self
.CreateStatusBar()
20 self
.SetStatusText("This is the statusbar")
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
)
28 # Prepare the menu bar
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()
37 menu1
.Append(104, "Close", "Close this frame")
38 # Add menu to the menu bar
39 menuBar
.Append(menu1
, "&Planets")
43 menu2
.Append(201, "Hydrogen")
44 menu2
.Append(202, "Helium")
45 # a submenu in the 2nd menu
47 submenu
.Append(2031,"Lanthanium")
48 submenu
.Append(2032,"Cerium")
49 submenu
.Append(2033,"Praseodymium")
50 menu2
.AppendMenu(203, "Lanthanides", submenu
)
52 menuBar
.Append(menu2
, "&Elements")
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")
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")
70 menu5
.Append(501, "Interesting thing\tCtrl+A", "Note the shortcut!")
72 menu5
.AppendSeparator()
73 menu5
.Append(502, "Hello\tShift+H")
74 menuBar
.Append(menu5
, "&Fun")
76 self
.SetMenuBar(menuBar
)
79 EVT_MENU(self
, 101, self
.Menu101
)
80 EVT_MENU(self
, 102, self
.Menu102
)
81 EVT_MENU(self
, 103, self
.Menu103
)
82 EVT_MENU(self
, 104, self
.CloseWindow
)
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
)
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
)
96 EVT_MENU_RANGE(self
, 401, 403, self
.Menu401To403
)
98 EVT_MENU(self
, 501, self
.Menu501
)
99 EVT_MENU(self
, 502, self
.Menu502
)
103 def Menu101(self
, event
):
104 self
.log
.write('Welcome to Mercury\n')
106 def Menu102(self
, event
):
107 self
.log
.write('Welcome to Venus\n')
109 def Menu103(self
, event
):
110 self
.log
.write('Welcome to the Earth\n')
112 def CloseWindow(self
, event
):
115 def Menu201(self
, event
):
116 self
.log
.write('Chemical element number 1\n')
118 def Menu202(self
, event
):
119 self
.log
.write('Chemical element number 2\n')
121 def Menu2031(self
, event
):
122 self
.log
.write('Element number 57\n')
124 def Menu2032(self
, event
):
125 self
.log
.write('Element number 58\n')
127 def Menu2033(self
, event
):
128 self
.log
.write('Element number 59\n')
130 def Menu301To303(self
, event
):
132 self
.log
.write('Event id: %d\n' % id)
134 def Menu304(self
, event
):
135 self
.log
.write('Not yet available\n')
137 def Menu305(self
, event
):
138 self
.log
.write('Still vapour\n')
140 def Menu401To403(self
, event
):
141 self
.log
.write('From a EVT_MENU_RANGE event\n')
143 def Menu501(self
, event
):
144 self
.log
.write('Look in the code how the shortcut has been realized\n')
146 def Menu502(self
, event
):
147 self
.log
.write('Hello from Jean-Michel\n')
149 #-------------------------------------------------------------------
151 def runTest(frame
, nb
, log
):
152 win
= MyFrame(frame
, -1, log
)
157 #-------------------------------------------------------------------
161 A demo of using wxMenuBar and wxMenu in various ways.
167 if __name__
== '__main__':
170 run
.main(['', os
.path
.basename(sys
.argv
[0])])