annotate Mac/Lib/toolbox/MiniAEFrame.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents c6a4786e7f8e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4241
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 """MiniAEFrame - A first stab at an AE Application framework.
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 This framework is still work-in-progress, so do not rely on it remaining
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 unchanged.
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 """
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 import sys
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 import traceback
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 import MacOS
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 import AE
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 from AppleEvents import *
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 import Evt
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 from Events import *
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 import Menu
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14 import Win
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 from Windows import *
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 import Qd
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 import aetools
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 import EasyDialogs
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 kHighLevelEvent = 23 # Not defined anywhere for Python yet?
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 class MiniApplication:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 """A minimal FrameWork.Application-like class"""
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 def __init__(self):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 self.quitting = 0
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 # Initialize menu
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 self.appleid = 1
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 self.quitid = 2
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 Menu.ClearMenuBar()
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 self.applemenu = applemenu = Menu.NewMenu(self.appleid, "\024")
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 applemenu.AppendMenu("All about cgitest...;(-")
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 applemenu.AppendResMenu('DRVR')
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 applemenu.InsertMenu(0)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 self.quitmenu = Menu.NewMenu(self.quitid, "File")
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37 self.quitmenu.AppendMenu("Quit")
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38 self.quitmenu.InsertMenu(0)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 Menu.DrawMenuBar()
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 def __del__(self):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 self.close()
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 def close(self):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 pass
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 def mainloop(self, mask = everyEvent, timeout = 60*60):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 while not self.quitting:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 self.dooneevent(mask, timeout)
4313
9847de940790 Added _quit() method similar to FrameWork in stead of setting
Jack Jansen <jack.jansen@cwi.nl>
parents: 4241
diff changeset
50
9847de940790 Added _quit() method similar to FrameWork in stead of setting
Jack Jansen <jack.jansen@cwi.nl>
parents: 4241
diff changeset
51 def _quit(self):
9847de940790 Added _quit() method similar to FrameWork in stead of setting
Jack Jansen <jack.jansen@cwi.nl>
parents: 4241
diff changeset
52 self.quitting = 1
4241
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 def dooneevent(self, mask = everyEvent, timeout = 60*60):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 got, event = Evt.WaitNextEvent(mask, timeout)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 if got:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 self.lowlevelhandler(event)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 def lowlevelhandler(self, event):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60 what, message, when, where, modifiers = event
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 h, v = where
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 if what == kHighLevelEvent:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 msg = "High Level Event: %s %s" % \
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 (`code(message)`, `code(h | (v<<16))`)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65 try:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 AE.AEProcessAppleEvent(event)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 except AE.Error, err:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 print 'AE error: ', err
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69 print 'in', msg
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70 traceback.print_exc()
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 return
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 elif what == keyDown:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 c = chr(message & charCodeMask)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 if c == '.' and modifiers & cmdKey:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 raise KeyboardInterrupt, "Command-period"
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76 elif what == mouseDown:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 partcode, window = Win.FindWindow(where)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 if partcode == inMenuBar:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79 result = Menu.MenuSelect(where)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 id = (result>>16) & 0xffff # Hi word
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 item = result & 0xffff # Lo word
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 if id == self.appleid:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 if item == 1:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84 EasyDialogs.Message("cgitest - First cgi test")
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85 return
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 elif item > 1:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 name = self.applemenu.GetItem(item)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
88 Qd.OpenDeskAcc(name)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
89 return
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90 if id == self.quitid and item == 1:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91 print "Menu-requested QUIT"
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 self.quitting = 1
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93 # Anything not handled is passed to Python/SIOUX
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 MacOS.HandleEvent(event)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 class AEServer:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 def __init__(self):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 self.ae_handlers = {}
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 def installaehandler(self, classe, type, callback):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 AE.AEInstallEventHandler(classe, type, self.callback_wrapper)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103 self.ae_handlers[(classe, type)] = callback
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 def close(self):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 for classe, type in self.ae_handlers.keys():
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 AE.AERemoveEventHandler(classe, type)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
109 def callback_wrapper(self, _request, _reply):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 _parameters, _attributes = aetools.unpackevent(_request)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111 _class = _attributes['evcl'].type
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112 _type = _attributes['evid'].type
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
113
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 if self.ae_handlers.has_key((_class, _type)):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 _function = self.ae_handlers[(_class, _type)]
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
116 elif self.ae_handlers.has_key((_class, '****')):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 _function = self.ae_handlers[(_class, '****')]
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
118 elif self.ae_handlers.has_key(('****', '****')):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
119 _function = self.ae_handlers[('****', '****')]
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 else:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121 raise 'Cannot happen: AE callback without handler', (_class, _type)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123 # XXXX Do key-to-name mapping here
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 _parameters['_attributes'] = _attributes
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126 _parameters['_class'] = _class
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
127 _parameters['_type'] = _type
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 if _parameters.has_key('----'):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129 _object = _parameters['----']
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
130 del _parameters['----']
4463
c6a4786e7f8e Raise a more intellegible error in the case of missing keyword args
Jack Jansen <jack.jansen@cwi.nl>
parents: 4313
diff changeset
131 print 'XXX', (_function, (_object,), _parameters)
c6a4786e7f8e Raise a more intellegible error in the case of missing keyword args
Jack Jansen <jack.jansen@cwi.nl>
parents: 4313
diff changeset
132 try:
c6a4786e7f8e Raise a more intellegible error in the case of missing keyword args
Jack Jansen <jack.jansen@cwi.nl>
parents: 4313
diff changeset
133 rv = apply(_function, (_object,), _parameters)
c6a4786e7f8e Raise a more intellegible error in the case of missing keyword args
Jack Jansen <jack.jansen@cwi.nl>
parents: 4313
diff changeset
134 except TypeError, name:
c6a4786e7f8e Raise a more intellegible error in the case of missing keyword args
Jack Jansen <jack.jansen@cwi.nl>
parents: 4313
diff changeset
135 raise TypeError, ('AppleEvent handler misses formal keyword argument', _function, name)
4241
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
136 else:
4463
c6a4786e7f8e Raise a more intellegible error in the case of missing keyword args
Jack Jansen <jack.jansen@cwi.nl>
parents: 4313
diff changeset
137 try:
c6a4786e7f8e Raise a more intellegible error in the case of missing keyword args
Jack Jansen <jack.jansen@cwi.nl>
parents: 4313
diff changeset
138 rv = apply(_function, (), _parameters)
c6a4786e7f8e Raise a more intellegible error in the case of missing keyword args
Jack Jansen <jack.jansen@cwi.nl>
parents: 4313
diff changeset
139 except TypeError, name:
c6a4786e7f8e Raise a more intellegible error in the case of missing keyword args
Jack Jansen <jack.jansen@cwi.nl>
parents: 4313
diff changeset
140 raise TypeError, ('AppleEvent handler misses formal keyword argument', _function, name)
4241
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
141
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142 if rv == None:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143 aetools.packevent(_reply, {})
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
144 else:
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
145 aetools.packevent(_reply, {'----':rv})
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
146
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
147 def code(x):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
148 "Convert a long int to the 4-character code it really is"
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
149 s = ''
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
150 for i in range(4):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
151 x, c = divmod(x, 256)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
152 s = chr(c) + s
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
153 return s
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
154
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
155 class _Test(AEServer, MiniApplication):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
156 """Mini test application, handles required events"""
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
157
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
158 def __init__(self):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
159 MiniApplication.__init__(self)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
160 AEServer.__init__(self)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
161 self.installaehandler('aevt', 'oapp', self.open_app)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
162 self.installaehandler('aevt', 'quit', self.quit)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
163 self.installaehandler('aevt', '****', self.other)
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
164 self.mainloop()
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
165
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
166 def quit(self, **args):
4313
9847de940790 Added _quit() method similar to FrameWork in stead of setting
Jack Jansen <jack.jansen@cwi.nl>
parents: 4241
diff changeset
167 self._quit()
4241
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
168
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
169 def open_app(self, **args):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
170 pass
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
171
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
172 def other(self, _object=None, _class=None, _type=None, **args):
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
173 print 'AppleEvent', (_class, _type), 'for', _object, 'Other args:', args
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
174
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
175 if __name__ == '__main__':
c62d32c5ff3d (preliminary) framework for scriptable applications
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
176 _Test()