Commit 7ec7c8ad authored by Just van Rossum's avatar Just van Rossum

fixed several event handling buglets, added command Q support, added a new...

fixed several event handling buglets, added command Q support, added a new module doc string, some formatting nits. (jvr)
parent 89489fa1
"""MiniAEFrame - A first stab at an AE Application framework.
This framework is still work-in-progress, so do not rely on it remaining
unchanged.
"""MiniAEFrame - A minimal AppleEvent Application framework.
There are two classes:
AEServer -- a mixin class offering nice AE handling.
MiniApplication -- a very minimal alternative to FrameWork.py,
only suitable for the simplest of AppleEvent servers.
"""
import sys
......@@ -20,7 +23,9 @@ import EasyDialogs
kHighLevelEvent = 23 # Not defined anywhere for Python yet?
class MiniApplication:
"""A minimal FrameWork.Application-like class"""
def __init__(self):
......@@ -30,11 +35,12 @@ class MiniApplication:
self.quitid = 2
Menu.ClearMenuBar()
self.applemenu = applemenu = Menu.NewMenu(self.appleid, "\024")
applemenu.AppendMenu("All about cgitest...;(-")
applemenu.AppendMenu("About %s...;(-" % self.__class__.__name__)
applemenu.AppendResMenu('DRVR')
applemenu.InsertMenu(0)
self.quitmenu = Menu.NewMenu(self.quitid, "File")
self.quitmenu.AppendMenu("Quit")
self.quitmenu.SetItemCmd(1, ord("Q"))
self.quitmenu.InsertMenu(0)
Menu.DrawMenuBar()
......@@ -71,8 +77,11 @@ class MiniApplication:
return
elif what == keyDown:
c = chr(message & charCodeMask)
if c == '.' and modifiers & cmdKey:
if modifiers & cmdKey:
if c == '.':
raise KeyboardInterrupt, "Command-period"
if c == 'q':
self.quitting = 1
elif what == mouseDown:
partcode, window = Win.FindWindow(where)
if partcode == inMenuBar:
......@@ -81,18 +90,21 @@ class MiniApplication:
item = result & 0xffff # Lo word
if id == self.appleid:
if item == 1:
EasyDialogs.Message("cgitest - First cgi test")
return
EasyDialogs.Message(self.getabouttext())
elif item > 1:
name = self.applemenu.GetItem(item)
Qd.OpenDeskAcc(name)
return
if id == self.quitid and item == 1:
print "Menu-requested QUIT"
name = self.applemenu.GetMenuItemText(item)
Menu.OpenDeskAcc(name)
elif id == self.quitid and item == 1:
self.quitting = 1
Menu.HiliteMenu(0)
else:
# Anything not handled is passed to Python/SIOUX
MacOS.HandleEvent(event)
def getabouttext(self):
return self.__class__.__name__
class AEServer:
def __init__(self):
......@@ -143,6 +155,7 @@ class AEServer:
else:
aetools.packevent(_reply, {'----':rv})
def code(x):
"Convert a long int to the 4-character code it really is"
s = ''
......@@ -171,5 +184,6 @@ class _Test(AEServer, MiniApplication):
def other(self, _object=None, _class=None, _type=None, **args):
print 'AppleEvent', (_class, _type), 'for', _object, 'Other args:', args
if __name__ == '__main__':
_Test()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment