Mercurial > cpython-lru_cache-weakref
annotate Mac/Lib/MiniAEFrame.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 42b2f1936254 |
| children | 564629d1f1ac |
| rev | line source |
|---|---|
|
19385
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
1 """MiniAEFrame - A minimal AppleEvent Application framework. |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
2 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
3 There are two classes: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
4 AEServer -- a mixin class offering nice AE handling. |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
5 MiniApplication -- a very minimal alternative to FrameWork.py, |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
6 only suitable for the simplest of AppleEvent servers. |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
7 """ |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
8 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
9 import sys |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
10 import traceback |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
11 import MacOS |
|
19488
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19385
diff
changeset
|
12 from Carbon import AE |
|
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19385
diff
changeset
|
13 from Carbon.AppleEvents import * |
|
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19385
diff
changeset
|
14 from Carbon import Evt |
|
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19385
diff
changeset
|
15 from Carbon.Events import * |
|
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19385
diff
changeset
|
16 from Carbon import Menu |
|
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19385
diff
changeset
|
17 from Carbon import Win |
|
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19385
diff
changeset
|
18 from Carbon.Windows import * |
|
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19385
diff
changeset
|
19 from Carbon import Qd |
|
19385
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
20 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
21 import aetools |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
22 import EasyDialogs |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
23 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
24 kHighLevelEvent = 23 # Not defined anywhere for Python yet? |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
25 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
26 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
27 class MiniApplication: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
28 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
29 """A minimal FrameWork.Application-like class""" |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
30 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
31 def __init__(self): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
32 self.quitting = 0 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
33 # Initialize menu |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
34 self.appleid = 1 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
35 self.quitid = 2 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
36 Menu.ClearMenuBar() |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
37 self.applemenu = applemenu = Menu.NewMenu(self.appleid, "\024") |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
38 applemenu.AppendMenu("%s;(-" % self.getaboutmenutext()) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
39 if MacOS.runtimemodel == 'ppc': |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
40 applemenu.AppendResMenu('DRVR') |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
41 applemenu.InsertMenu(0) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
42 self.quitmenu = Menu.NewMenu(self.quitid, "File") |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
43 self.quitmenu.AppendMenu("Quit") |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
44 self.quitmenu.SetItemCmd(1, ord("Q")) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
45 self.quitmenu.InsertMenu(0) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
46 Menu.DrawMenuBar() |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
47 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
48 def __del__(self): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
49 self.close() |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
50 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
51 def close(self): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
52 pass |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
53 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
54 def mainloop(self, mask = everyEvent, timeout = 60*60): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
55 while not self.quitting: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
56 self.dooneevent(mask, timeout) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
57 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
58 def _quit(self): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
59 self.quitting = 1 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
60 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
61 def dooneevent(self, mask = everyEvent, timeout = 60*60): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
62 got, event = Evt.WaitNextEvent(mask, timeout) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
63 if got: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
64 self.lowlevelhandler(event) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
65 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
66 def lowlevelhandler(self, event): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
67 what, message, when, where, modifiers = event |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
68 h, v = where |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
69 if what == kHighLevelEvent: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
70 msg = "High Level Event: %s %s" % \ |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
71 (`code(message)`, `code(h | (v<<16))`) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
72 try: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
73 AE.AEProcessAppleEvent(event) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
74 except AE.Error, err: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
75 print 'AE error: ', err |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
76 print 'in', msg |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
77 traceback.print_exc() |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
78 return |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
79 elif what == keyDown: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
80 c = chr(message & charCodeMask) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
81 if modifiers & cmdKey: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
82 if c == '.': |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
83 raise KeyboardInterrupt, "Command-period" |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
84 if c == 'q': |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
85 MacOS.OutputSeen() |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
86 self.quitting = 1 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
87 return |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
88 elif what == mouseDown: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
89 partcode, window = Win.FindWindow(where) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
90 if partcode == inMenuBar: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
91 result = Menu.MenuSelect(where) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
92 id = (result>>16) & 0xffff # Hi word |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
93 item = result & 0xffff # Lo word |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
94 if id == self.appleid: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
95 if item == 1: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
96 EasyDialogs.Message(self.getabouttext()) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
97 elif item > 1 and hasattr(Menu, 'OpenDeskAcc'): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
98 name = self.applemenu.GetMenuItemText(item) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
99 Menu.OpenDeskAcc(name) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
100 elif id == self.quitid and item == 1: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
101 MacOS.OutputSeen() |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
102 self.quitting = 1 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
103 Menu.HiliteMenu(0) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
104 return |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
105 # Anything not handled is passed to Python/SIOUX |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
106 MacOS.HandleEvent(event) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
107 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
108 def getabouttext(self): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
109 return self.__class__.__name__ |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
110 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
111 def getaboutmenutext(self): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
112 return "About %s\311" % self.__class__.__name__ |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
113 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
114 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
115 class AEServer: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
116 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
117 def __init__(self): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
118 self.ae_handlers = {} |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
119 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
120 def installaehandler(self, classe, type, callback): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
121 AE.AEInstallEventHandler(classe, type, self.callback_wrapper) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
122 self.ae_handlers[(classe, type)] = callback |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
123 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
124 def close(self): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
125 for classe, type in self.ae_handlers.keys(): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
126 AE.AERemoveEventHandler(classe, type) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
127 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
128 def callback_wrapper(self, _request, _reply): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
129 _parameters, _attributes = aetools.unpackevent(_request) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
130 _class = _attributes['evcl'].type |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
131 _type = _attributes['evid'].type |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
132 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
133 if self.ae_handlers.has_key((_class, _type)): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
134 _function = self.ae_handlers[(_class, _type)] |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
135 elif self.ae_handlers.has_key((_class, '****')): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
136 _function = self.ae_handlers[(_class, '****')] |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
137 elif self.ae_handlers.has_key(('****', '****')): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
138 _function = self.ae_handlers[('****', '****')] |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
139 else: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
140 raise 'Cannot happen: AE callback without handler', (_class, _type) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
141 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
142 # XXXX Do key-to-name mapping here |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
143 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
144 _parameters['_attributes'] = _attributes |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
145 _parameters['_class'] = _class |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
146 _parameters['_type'] = _type |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
147 if _parameters.has_key('----'): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
148 _object = _parameters['----'] |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
149 del _parameters['----'] |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
150 # The try/except that used to be here can mask programmer errors. |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
151 # Let the program crash, the programmer can always add a **args |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
152 # to the formal parameter list. |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
153 rv = apply(_function, (_object,), _parameters) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
154 else: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
155 #Same try/except comment as above |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
156 rv = apply(_function, (), _parameters) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
157 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
158 if rv == None: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
159 aetools.packevent(_reply, {}) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
160 else: |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
161 aetools.packevent(_reply, {'----':rv}) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
162 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
163 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
164 def code(x): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
165 "Convert a long int to the 4-character code it really is" |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
166 s = '' |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
167 for i in range(4): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
168 x, c = divmod(x, 256) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
169 s = chr(c) + s |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
170 return s |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
171 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
172 class _Test(AEServer, MiniApplication): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
173 """Mini test application, handles required events""" |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
174 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
175 def __init__(self): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
176 MiniApplication.__init__(self) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
177 AEServer.__init__(self) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
178 self.installaehandler('aevt', 'oapp', self.open_app) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
179 self.installaehandler('aevt', 'quit', self.quit) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
180 self.installaehandler('****', '****', self.other) |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
181 self.mainloop() |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
182 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
183 def quit(self, **args): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
184 self._quit() |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
185 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
186 def open_app(self, **args): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
187 pass |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
188 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
189 def other(self, _object=None, _class=None, _type=None, **args): |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
190 print 'AppleEvent', (_class, _type), 'for', _object, 'Other args:', args |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
191 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
192 |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
193 if __name__ == '__main__': |
|
ce6ea4449e97
Moved here from lib-toolbox, where they should never have been in the first place (all the other stuff there wa generated with bgen).
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
194 _Test() |
