]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxMenu.py
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 # Prepare the menu bar
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")
37 menu2
.Append(201, "Hydrogen")
38 menu2
.Append(202, "Helium")
39 # a submenu in the 2nd menu
41 submenu
.Append(2031,"Lanthanium")
42 submenu
.Append(2032,"Cerium")
43 submenu
.Append(2033,"Praseodymium")
44 menu2
.AppendMenu(203, "Lanthanides", submenu
)
46 menuBar
.Append(menu2
, "&Elements")
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")
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")
64 menu5
.Append(501, "Interesting thing\tCtrl+A", "Note the shortcut!")
66 menu5
.AppendSeparator()
67 menu5
.Append(502, "Hello\tShift+H")
68 menuBar
.Append(menu5
, "&Fun")
70 self
.SetMenuBar(menuBar
)
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
)
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
)
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
)
90 EVT_MENU_RANGE(self
, 401, 403, self
.Menu401To403
)
92 EVT_MENU(self
, 501, self
.Menu501
)
93 EVT_MENU(self
, 502, self
.Menu502
)
97 def Menu101(self
, event
):
98 self
.log
.write('Welcome to Mercury\n')
100 def Menu102(self
, event
):
101 self
.log
.write('Welcome to Venus\n')
103 def Menu103(self
, event
):
104 self
.log
.write('Welcome to the Earth\n')
106 def CloseWindow(self
, event
):
109 def Menu201(self
, event
):
110 self
.log
.write('Chemical element number 1\n')
112 def Menu202(self
, event
):
113 self
.log
.write('Chemical element number 2\n')
115 def Menu2031(self
, event
):
116 self
.log
.write('Element number 57\n')
118 def Menu2032(self
, event
):
119 self
.log
.write('Element number 58\n')
121 def Menu2033(self
, event
):
122 self
.log
.write('Element number 59\n')
124 def Menu301To303(self
, event
):
126 self
.log
.write('Event id: %d\n' % id)
128 def Menu304(self
, event
):
129 self
.log
.write('Not yet available\n')
131 def Menu305(self
, event
):
132 self
.log
.write('Still vapour\n')
134 def Menu401To403(self
, event
):
135 self
.log
.write('From a EVT_MENU_RANGE event\n')
137 def Menu501(self
, event
):
138 self
.log
.write('Look in the code how the shortcut has been realized\n')
140 def Menu502(self
, event
):
141 self
.log
.write('Hello from Jean-Michel\n')
143 #-------------------------------------------------------------------
145 def runTest(frame
, nb
, log
):
146 win
= MyFrame(frame
, -1, log
)
151 #-------------------------------------------------------------------
155 A demo of using wxMenuBar and wxMenu in various ways.
161 if __name__
== '__main__':
164 run
.main(['', os
.path
.basename(sys
.argv
[0])])