@@ -93,9 +93,13 @@ class Application:
9393
9494 "Application framework -- your application should be a derived class"
9595
96- def __init__ (self ):
96+ def __init__ (self , nomenubar = 0 ):
97+ self .quitting = 0
9798 self ._windows = {}
98- self .makemenubar ()
99+ if nomenubar :
100+ self .menubar = None
101+ else :
102+ self .makemenubar ()
99103
100104 def makemenubar (self ):
101105 self .menubar = MenuBar ()
@@ -107,7 +111,7 @@ def makeusermenus(self):
107111 self ._quititem = MenuItem (m , "Quit" , "Q" , self ._quit )
108112
109113 def _quit (self , * args ):
110- raise self
114+ self . quitting = 1
111115
112116 def appendwindow (self , wid , window ):
113117 self ._windows [wid ] = window
@@ -131,12 +135,16 @@ def do_about(self, id, item, window, event):
131135 # way to define the mask and wait time passed to WaitNextEvent.)
132136
133137 def mainloop (self , mask = everyEvent , wait = 0 ):
138+ self .quitting = 0
134139 saveyield = MacOS .EnableAppswitch (self .yield )
135140 try :
136- while 1 :
141+ while not self . quitting :
137142 try :
138143 self .do1event (mask , wait )
139144 except (Application , SystemExit ):
145+ # Note: the raising of "self" is old-fashioned idiom to
146+ # exit the mainloop. Calling _quit() is better for new
147+ # applications.
140148 break
141149 finally :
142150 MacOS .EnableAppswitch (saveyield )
@@ -222,6 +230,9 @@ def do_inDesk(self, partcode, window, event):
222230 MacOS .HandleEvent (event )
223231
224232 def do_inMenuBar (self , partcode , window , event ):
233+ if not self .menubar :
234+ MacOS .HandleEvent (event )
235+ return
225236 (what , message , when , where , modifiers ) = event
226237 result = MenuSelect (where )
227238 id = (result >> 16 ) & 0xffff # Hi word
@@ -263,6 +274,9 @@ def do_key(self, event):
263274 if c == '.' :
264275 raise self
265276 else :
277+ if not self .menubar :
278+ MacOS .HandleEvent (event )
279+ return
266280 result = MenuKey (ord (c ))
267281 id = (result >> 16 ) & 0xffff # Hi word
268282 item = result & 0xffff # Lo word
0 commit comments