summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1996-09-17 12:35:43 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1996-09-17 12:35:43 (GMT)
commit647535d3900218093d2e7e21c92cadd52807f313 (patch)
treea6cef2568ef019766643ef11d12033d2a7ec0d15
parent29a3355ab96a7df76adaf676e695821232d4ac5a (diff)
downloadcpython-647535d3900218093d2e7e21c92cadd52807f313.zip
cpython-647535d3900218093d2e7e21c92cadd52807f313.tar.gz
cpython-647535d3900218093d2e7e21c92cadd52807f313.tar.bz2
- Use a flag (self.quitting) as preferred method of exiting mainloop
- Added optional "nomenubar" argument to Application.__init__
-rw-r--r--Mac/Lib/FrameWork.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/Mac/Lib/FrameWork.py b/Mac/Lib/FrameWork.py
index 9610b61..dc07f5e 100644
--- a/Mac/Lib/FrameWork.py
+++ b/Mac/Lib/FrameWork.py
@@ -93,9 +93,13 @@ class Application:
"Application framework -- your application should be a derived class"
- def __init__(self):
+ def __init__(self, nomenubar=0):
+ self.quitting = 0
self._windows = {}
- self.makemenubar()
+ if nomenubar:
+ self.menubar = None
+ else:
+ self.makemenubar()
def makemenubar(self):
self.menubar = MenuBar()
@@ -107,7 +111,7 @@ class Application:
self._quititem = MenuItem(m, "Quit", "Q", self._quit)
def _quit(self, *args):
- raise self
+ self.quitting = 1
def appendwindow(self, wid, window):
self._windows[wid] = window
@@ -131,12 +135,16 @@ class Application:
# way to define the mask and wait time passed to WaitNextEvent.)
def mainloop(self, mask = everyEvent, wait = 0):
+ self.quitting = 0
saveyield = MacOS.EnableAppswitch(self.yield)
try:
- while 1:
+ while not self.quitting:
try:
self.do1event(mask, wait)
except (Application, SystemExit):
+ # Note: the raising of "self" is old-fashioned idiom to
+ # exit the mainloop. Calling _quit() is better for new
+ # applications.
break
finally:
MacOS.EnableAppswitch(saveyield)
@@ -222,6 +230,9 @@ class Application:
MacOS.HandleEvent(event)
def do_inMenuBar(self, partcode, window, event):
+ if not self.menubar:
+ MacOS.HandleEvent(event)
+ return
(what, message, when, where, modifiers) = event
result = MenuSelect(where)
id = (result>>16) & 0xffff # Hi word
@@ -263,6 +274,9 @@ class Application:
if c == '.':
raise self
else:
+ if not self.menubar:
+ MacOS.HandleEvent(event)
+ return
result = MenuKey(ord(c))
id = (result>>16) & 0xffff # Hi word
item = result & 0xffff # Lo word