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. """MiniAEFrame - A minimal AppleEvent Application framework.
This framework is still work-in-progress, so do not rely on it remaining
unchanged. 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 import sys
...@@ -20,7 +23,9 @@ import EasyDialogs ...@@ -20,7 +23,9 @@ import EasyDialogs
kHighLevelEvent = 23 # Not defined anywhere for Python yet? kHighLevelEvent = 23 # Not defined anywhere for Python yet?
class MiniApplication: class MiniApplication:
"""A minimal FrameWork.Application-like class""" """A minimal FrameWork.Application-like class"""
def __init__(self): def __init__(self):
...@@ -30,11 +35,12 @@ class MiniApplication: ...@@ -30,11 +35,12 @@ class MiniApplication:
self.quitid = 2 self.quitid = 2
Menu.ClearMenuBar() Menu.ClearMenuBar()
self.applemenu = applemenu = Menu.NewMenu(self.appleid, "\024") self.applemenu = applemenu = Menu.NewMenu(self.appleid, "\024")
applemenu.AppendMenu("All about cgitest...;(-") applemenu.AppendMenu("About %s...;(-" % self.__class__.__name__)
applemenu.AppendResMenu('DRVR') applemenu.AppendResMenu('DRVR')
applemenu.InsertMenu(0) applemenu.InsertMenu(0)
self.quitmenu = Menu.NewMenu(self.quitid, "File") self.quitmenu = Menu.NewMenu(self.quitid, "File")
self.quitmenu.AppendMenu("Quit") self.quitmenu.AppendMenu("Quit")
self.quitmenu.SetItemCmd(1, ord("Q"))
self.quitmenu.InsertMenu(0) self.quitmenu.InsertMenu(0)
Menu.DrawMenuBar() Menu.DrawMenuBar()
...@@ -71,8 +77,11 @@ class MiniApplication: ...@@ -71,8 +77,11 @@ class MiniApplication:
return return
elif what == keyDown: elif what == keyDown:
c = chr(message & charCodeMask) c = chr(message & charCodeMask)
if c == '.' and modifiers & cmdKey: if modifiers & cmdKey:
if c == '.':
raise KeyboardInterrupt, "Command-period" raise KeyboardInterrupt, "Command-period"
if c == 'q':
self.quitting = 1
elif what == mouseDown: elif what == mouseDown:
partcode, window = Win.FindWindow(where) partcode, window = Win.FindWindow(where)
if partcode == inMenuBar: if partcode == inMenuBar:
...@@ -81,18 +90,21 @@ class MiniApplication: ...@@ -81,18 +90,21 @@ class MiniApplication:
item = result & 0xffff # Lo word item = result & 0xffff # Lo word
if id == self.appleid: if id == self.appleid:
if item == 1: if item == 1:
EasyDialogs.Message("cgitest - First cgi test") EasyDialogs.Message(self.getabouttext())
return
elif item > 1: elif item > 1:
name = self.applemenu.GetItem(item) name = self.applemenu.GetMenuItemText(item)
Qd.OpenDeskAcc(name) Menu.OpenDeskAcc(name)
return elif id == self.quitid and item == 1:
if id == self.quitid and item == 1:
print "Menu-requested QUIT"
self.quitting = 1 self.quitting = 1
Menu.HiliteMenu(0)
else:
# Anything not handled is passed to Python/SIOUX # Anything not handled is passed to Python/SIOUX
MacOS.HandleEvent(event) MacOS.HandleEvent(event)
def getabouttext(self):
return self.__class__.__name__
class AEServer: class AEServer:
def __init__(self): def __init__(self):
...@@ -143,6 +155,7 @@ class AEServer: ...@@ -143,6 +155,7 @@ class AEServer:
else: else:
aetools.packevent(_reply, {'----':rv}) aetools.packevent(_reply, {'----':rv})
def code(x): def code(x):
"Convert a long int to the 4-character code it really is" "Convert a long int to the 4-character code it really is"
s = '' s = ''
...@@ -171,5 +184,6 @@ class _Test(AEServer, MiniApplication): ...@@ -171,5 +184,6 @@ class _Test(AEServer, MiniApplication):
def other(self, _object=None, _class=None, _type=None, **args): def other(self, _object=None, _class=None, _type=None, **args):
print 'AppleEvent', (_class, _type), 'for', _object, 'Other args:', args print 'AppleEvent', (_class, _type), 'for', _object, 'Other args:', args
if __name__ == '__main__': if __name__ == '__main__':
_Test() _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