annotate Mac/Lib/test/tae.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 8f6cc717d817
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3460
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 # The oldest AppleEvent test program.
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 # Its function has been overtaken by echo.py and tell.py.
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 import AE
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 from AppleEvents import *
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 import Evt
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 from Events import *
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 import struct
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 import aetools
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 import macfs
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 import sys
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 import MacOS
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13
5733
8f6cc717d817 Replaced MacOS.EnableAppswitch by MacOS.SchedParams
Jack Jansen <jack.jansen@cwi.nl>
parents: 3460
diff changeset
14 MacOS.SchedParams(1, 0)
3460
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 def aehandler(request, reply):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 tosend = []
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 print 'request:', aetools.unpackevent(request)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 param = request.AEGetParamDesc(keyDirectObject, typeWildCard)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 if param.type == typeAEList:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 n = param.AECountItems()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22 print 'List has', n, 'items'
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 for i in range(1, 1+n):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 type, item = param.AEGetNthDesc(i, typeFSS)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 data = item.data
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 print 'item', i, ':', type, item.type, len(data), 'bytes'
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 vol, dir, fnlen = struct.unpack('hlb', data[:7])
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 filename = data[7:7+fnlen]
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 print 'vol:', vol, '; dir:', dir, '; filename:', `filename`
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 print 'full path:', macfs.FSSpec((vol,dir,filename)).as_pathname()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 tosend.append(item)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 else:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 pass
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 print 'param:', (param.type, param.data[:20]), param.data[20:] and '...'
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 if tosend:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 passtothink(tosend)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 def passtothink(list):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 target = AE.AECreateDesc(typeApplSignature, 'KAHL')
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 event = AE.AECreateAppleEvent(kCoreEventClass,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 kAEOpenDocuments,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 target,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 kAutoGenerateReturnID,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 kAnyTransactionID)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 aetools.packevent(event, {keyDirectObject: list})
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 reply = event.AESend(kAENoReply | kAEAlwaysInteract | kAECanSwitchLayer,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 kAENormalPriority,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 kAEDefaultTimeout)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 #print "Reply:", aetools.unpackevent(reply)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 return
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52 event = AE.AECreateAppleEvent(kCoreEventClass,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 kAEOpenApplication,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 target,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 kAutoGenerateReturnID,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 kAnyTransactionID)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 reply = event.AESend(kAENoReply | kAEAlwaysInteract | kAECanSwitchLayer,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58 kAENormalPriority,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 kAEDefaultTimeout)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 def unihandler(req, rep):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 print 'unihandler'
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 aehandler(req, rep)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65 quit = 0
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 def quithandler(req, rep):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 global quit
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 quit = 1
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70 def corehandler(req, rep):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 print 'core event!'
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 parameters, attributes = aetools.unpackevent(req)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 print "event class =", attributes['evcl']
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 print "event id =", attributes['evid']
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 print 'parameters:', parameters
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76 # echo the arguments, to see how Script Editor formats them
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 aetools.packevent(rep, parameters)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79 def wildhandler(req, rep):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 print 'wildcard event!'
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 parameters, attributes = aetools.unpackevent(req)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 print "event class =", attributes['evcl']
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 print "event id =", attributes['evid']
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84 print 'parameters:', parameters
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 AE.AEInstallEventHandler(typeAppleEvent, kAEOpenApplication, aehandler)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 AE.AEInstallEventHandler(typeAppleEvent, kAEOpenDocuments, aehandler)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
88 AE.AEInstallEventHandler(typeAppleEvent, kAEPrintDocuments, aehandler)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
89 AE.AEInstallEventHandler(typeAppleEvent, kAEQuitApplication, quithandler)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90 AE.AEInstallEventHandler(typeAppleEvent, typeWildCard, unihandler)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91 AE.AEInstallEventHandler('core', typeWildCard, corehandler)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 #AE.AEInstallEventHandler(typeWildCard, typeWildCard, wildhandler)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 def main():
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 global quit
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 quit = 0
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 while not quit:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 ok, e = Evt.WaitNextEvent(-1, 60)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100 if ok:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 print 'Event:', e
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 if e[0] == 23: # kHighLevelEvent
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103 AE.AEProcessAppleEvent(e)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 elif e[0] == keyDown and chr(e[1]&0xff) == '.' and e[4]&cmdKey:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 raise KeyboardInterrupt, "Command-Period"
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 else:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 MacOS.HandleEvent(e)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
109 if __name__ == '__main__':
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 main()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112 print "This module is obsolete -- use echo.py or tell.py ..."