Mercurial > cpython-lru_cache-weakref
annotate Mac/Contrib/BBPy/PythonSlave.py @ 17954:248418cbd005 2.1
This commit was manufactured by cvs2svn to create branch
'release21-maint'.
| author | cvs2svn <tools@python.org> |
|---|---|
| date | Wed, 23 May 2001 14:52:45 +0000 |
| parents | |
| children |
| rev | line source |
|---|---|
|
17954
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
1 """PythonSlave.py |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
2 An application that responds to three types of apple event: |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
3 'pyth'/'EXEC': execute direct parameter as Python |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
4 'aevt', 'quit': quit |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
5 'aevt', 'odoc': perform python scripts |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
6 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
7 Copyright © 1996, Just van Rossum, Letterror |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
8 """ |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
9 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
10 __version__ = "0.1.3" |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
11 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
12 import FrameWork |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
13 import sys |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
14 import traceback |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
15 import aetools |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
16 import string |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
17 import AE |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
18 import EasyDialogs |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
19 import os |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
20 import Qd |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
21 from Types import * |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
22 from Events import charCodeMask, cmdKey |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
23 import MacOS |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
24 import Evt |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
25 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
26 def dummyfunc(): pass |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
27 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
28 modulefilename = dummyfunc.func_code.co_filename |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
29 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
30 def Interact(timeout = 50000000): # timeout after 10 days... |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
31 AE.AEInteractWithUser(timeout) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
32 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
33 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
34 class PythonSlave(FrameWork.Application): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
35 def __init__(self): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
36 FrameWork.Application.__init__(self) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
37 AE.AEInstallEventHandler('pyth', 'EXEC', ExecHandler) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
38 AE.AEInstallEventHandler('aevt', 'quit', QuitHandler) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
39 AE.AEInstallEventHandler('aevt', 'odoc', OpenDocumentHandler) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
40 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
41 def makeusermenus(self): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
42 self.filemenu = m = FrameWork.Menu(self.menubar, "File") |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
43 self._quititem = FrameWork.MenuItem(m, "Quit", "Q", self._quit) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
44 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
45 def do_kHighLevelEvent(self, event): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
46 (what, message, when, where, modifiers) = event |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
47 try: |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
48 AE.AEProcessAppleEvent(event) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
49 except AE.Error, detail: |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
50 print "Apple Event was not handled, error:", detail |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
51 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
52 def do_key(self, event): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
53 (what, message, when, where, modifiers) = event |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
54 c = chr(message & charCodeMask) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
55 if modifiers & cmdKey and c == '.': |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
56 return |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
57 FrameWork.Application.do_key(self, event) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
58 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
59 def idle(self, event): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
60 Qd.InitCursor() |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
61 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
62 def quit(self, *args): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
63 raise self |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
64 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
65 def getabouttext(self): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
66 return "About PythonSlave" |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
67 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
68 def do_about(self, id, item, window, event): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
69 EasyDialogs.Message("PythonSlave " + __version__ + "\rCopyright © 1996, Letterror, JvR") |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
70 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
71 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
72 def ExecHandler(theAppleEvent, theReply): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
73 parameters, args = aetools.unpackevent(theAppleEvent) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
74 if parameters.has_key('----'): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
75 if parameters.has_key('NAME'): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
76 print '--- executing "' + parameters['NAME'] + '" ---' |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
77 else: |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
78 print '--- executing "<unknown>" ---' |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
79 stuff = parameters['----'] |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
80 MyExec(stuff + "\n") # execute input |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
81 print '--- done ---' |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
82 return 0 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
83 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
84 def MyExec(stuff): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
85 stuff = string.splitfields(stuff, '\r') # convert return chars |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
86 stuff = string.joinfields(stuff, '\n') # to newline chars |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
87 Interact() |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
88 saveyield = MacOS.EnableAppswitch(1) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
89 try: |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
90 exec stuff in {} |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
91 except: |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
92 MacOS.EnableAppswitch(saveyield) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
93 traceback.print_exc() |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
94 MacOS.EnableAppswitch(saveyield) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
95 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
96 def OpenDocumentHandler(theAppleEvent, theReply): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
97 parameters, args = aetools.unpackevent(theAppleEvent) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
98 docs = parameters['----'] |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
99 if type(docs) <> ListType: |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
100 docs = [docs] |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
101 for doc in docs: |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
102 fss, a = doc.Resolve() |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
103 path = fss.as_pathname() |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
104 if path <> modulefilename: |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
105 MyExecFile(path) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
106 return 0 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
107 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
108 def MyExecFile(path): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
109 saveyield = MacOS.EnableAppswitch(1) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
110 savewd = os.getcwd() |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
111 os.chdir(os.path.split(path)[0]) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
112 print '--- Executing file "' + os.path.split(path)[1] + '"' |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
113 try: |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
114 execfile(path, {"__name__": "__main__"}) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
115 except: |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
116 traceback.print_exc() |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
117 MacOS.EnableAppswitch(saveyield) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
118 MacOS.EnableAppswitch(saveyield) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
119 os.chdir(savewd) |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
120 print "--- done ---" |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
121 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
122 def QuitHandler(theAppleEvent, theReply): |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
123 slave.quit() |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
124 return 0 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
125 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
126 |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
127 slave = PythonSlave() |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
128 print "PythonSlave", __version__, "ready." |
|
248418cbd005
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
129 slave.mainloop() |
