annotate Mac/Lib/test/AEservertest.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 90ede5165d1f
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 """AEservertest - Test AppleEvent server interface
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 (adapted from Guido's 'echo' program).
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 Build an applet from this source, and include the aete resource that you
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 want to test. Use the AEservertest script to try things.
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 """
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 import sys
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 sys.stdout = sys.stderr
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 import traceback
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 import AE
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14 from AppleEvents import *
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 import Evt
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 from Events import *
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 import Menu
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 import Dlg
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 import Win
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 from Windows import *
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 import Qd
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22 import macfs
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 import aetools
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 import EasyDialogs
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 kHighLevelEvent = 23 # Not defined anywhere for Python yet?
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 Quit='Quit'
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 def mymessage(str):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 err = AE.AEInteractWithUser(kAEDefaultTimeout)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 if err:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 print str
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 EasyDialogs.Message(str)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37 def myaskstring(str, default=''):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38 err = AE.AEInteractWithUser(kAEDefaultTimeout)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 if err:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 return default
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 return EasyDialogs.AskString(str, default)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 def main():
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 echo = EchoServer()
5733
8f6cc717d817 Replaced MacOS.EnableAppswitch by MacOS.SchedParams
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
45 savepars = MacOS.SchedParams(0, 0) # Disable Python's own "event handling"
3460
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 try:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 try:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 echo.mainloop(everyEvent, 0)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 except Quit:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 pass
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 finally:
5733
8f6cc717d817 Replaced MacOS.EnableAppswitch by MacOS.SchedParams
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
52 apply(MacOS.SchedParams, savepars) # Let Python have a go at events
3460
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 echo.close()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 class EchoServer:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58 suites = ['aevt', 'core', 'reqd']
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60 def __init__(self):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 self.active = 0
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 #
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 # Install the handlers
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 for suite in self.suites:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 AE.AEInstallEventHandler(suite, typeWildCard, self.aehandler)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 print (suite, typeWildCard, self.aehandler)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 self.active = 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 # Setup the apple menu and file/quit
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 #
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 self.appleid = 1
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 self.fileid = 2
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 Menu.ClearMenuBar()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76 self.applemenu = applemenu = Menu.NewMenu(self.appleid, "\024")
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 applemenu.AppendMenu("All about echo...;(-")
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 applemenu.AppendResMenu('DRVR')
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79 applemenu.InsertMenu(0)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 self.filemenu = Menu.NewMenu(self.fileid, 'File')
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 self.filemenu.AppendMenu("Quit/Q")
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 self.filemenu.InsertMenu(0)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85 Menu.DrawMenuBar()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 #
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 # Set interaction allowed (for the return values)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
88 #
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
89 AE.AESetInteractionAllowed(kAEInteractWithAll)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91 def __del__(self):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 self.close()
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 def close(self):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 if self.active:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 self.active = 0
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 for suite in self.suites:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 AE.AERemoveEventHandler(suite, typeWildCard)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100 def mainloop(self, mask = everyEvent, timeout = 60*60):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 while 1:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 self.dooneevent(mask, timeout)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 def dooneevent(self, mask = everyEvent, timeout = 60*60):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 got, event = Evt.WaitNextEvent(mask, timeout)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 if got:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 self.lowlevelhandler(event)
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 def lowlevelhandler(self, event):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 what, message, when, where, modifiers = event
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111 h, v = where
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112 if what == kHighLevelEvent:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
113 msg = "High Level Event: %s %s" % \
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 (`code(message)`, `code(h | (v<<16))`)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 self.handled_by_us = 0
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
116 try:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 AE.AEProcessAppleEvent(event)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
118 except AE.Error, err:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
119 mymessage(msg + "\015AEProcessAppleEvent error: %s" % str(err))
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 traceback.print_exc()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121 else:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122 if self.handled_by_us == 0:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123 print msg, "Handled by AE, somehow"
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124 else:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 print msg, 'Handled by us.'
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126 elif what == keyDown:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
127 c = chr(message & charCodeMask)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 if modifiers & cmdKey:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129 if c == '.':
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
130 raise KeyboardInterrupt, "Command-period"
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
131 else:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132 self.menuhit(Menu.MenuKey(message&charCodeMask))
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
133 ##MacOS.HandleEvent(event)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
134 elif what == mouseDown:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
135 partcode, window = Win.FindWindow(where)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
136 if partcode == inMenuBar:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
137 result = Menu.MenuSelect(where)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138 self.menuhit(result)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
139 elif what <> autoKey:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
140 print "Event:", (eventname(what), message, when, (h, v), modifiers)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
141 ## MacOS.HandleEvent(event)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143 def menuhit(self, result):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
144 id = (result>>16) & 0xffff # Hi word
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
145 item = result & 0xffff # Lo word
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
146 if id == self.appleid:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
147 if item == 1:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
148 mymessage("Echo -- echo AppleEvents")
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
149 elif item > 1:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
150 name = self.applemenu.GetItem(item)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
151 Qd.OpenDeskAcc(name)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
152 elif id == self.fileid:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
153 if item == 1:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
154 raise Quit
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
155
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
156 def aehandler(self, request, reply):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
157 print "Apple Event!"
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
158 self.handled_by_us = 1
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
159 parameters, attributes = aetools.unpackevent(request)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
160 print "class =", `attributes['evcl'].type`,
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
161 print "id =", `attributes['evid'].type`
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
162 print "Parameters:"
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
163 keys = parameters.keys()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
164 keys.sort()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
165 for key in keys:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
166 print "%s: %.150s" % (`key`, `parameters[key]`)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
167 print " :", str(parameters[key])
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
168 print "Attributes:"
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
169 keys = attributes.keys()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
170 keys.sort()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
171 for key in keys:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
172 print "%s: %.150s" % (`key`, `attributes[key]`)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
173 parameters['----'] = self.askreplyvalue()
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
174 aetools.packevent(reply, parameters)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
175
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
176 def askreplyvalue(self):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
177 while 1:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
178 str = myaskstring('Reply value to send (python-style)', 'None')
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
179 try:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
180 rv = eval(str)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
181 break
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
182 except:
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
183 pass
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
184 return rv
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
185
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
186 _eventnames = {
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
187 keyDown: 'keyDown',
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
188 autoKey: 'autoKey',
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
189 mouseDown: 'mouseDown',
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
190 mouseUp: 'mouseUp',
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
191 updateEvt: 'updateEvt',
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
192 diskEvt: 'diskEvt',
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
193 activateEvt: 'activateEvt',
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
194 osEvt: 'osEvt',
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
195 }
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
196
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
197 def eventname(what):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
198 if _eventnames.has_key(what): return _eventnames[what]
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
199 else: return `what`
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
200
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
201 def code(x):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
202 "Convert a long int to the 4-character code it really is"
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
203 s = ''
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
204 for i in range(4):
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
205 x, c = divmod(x, 256)
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
206 s = chr(c) + s
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
207 return s
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
208
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
209
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
210 if __name__ == '__main__':
97b0e9625eb1 Oops... I Inadvertently lost their cvs files...
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
211 main()