Mercurial > cpython-lru_cache-weakref
annotate Mac/Lib/test/twedit.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 728d5745ae7b |
| children |
| rev | line source |
|---|---|
|
3532
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
1 # Test waste module. |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
2 # Draw a window in which the user can type. |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
3 # |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
4 # This test expects Win, Evt and FrameWork (and anything used by those) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
5 # to work. |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
6 # |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
7 # Actually, it is more a test of FrameWork by now.... |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
8 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
9 from FrameWork import * |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
10 import Win |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
11 import Qd |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
12 import waste |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
13 import WASTEconst |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
14 import os |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
15 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
16 class WasteWindow(Window): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
17 def open(self, name): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
18 r = (40, 40, 400, 300) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
19 w = Win.NewWindow(r, name, 1, 0, -1, 1, 0x55555555) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
20 r2 = (0, 0, 400-40-16, 300-40-16) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
21 Qd.SetPort(w) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
22 flags = WASTEconst.weDoAutoScroll | WASTEconst.weDoOutlineHilite | \ |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
23 WASTEconst.weDoMonoStyled |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
24 self.ted = waste.WENew(r2, r2, flags) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
25 w.DrawGrowIcon() |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
26 self.wid = w |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
27 self.do_postopen() |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
28 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
29 def do_idle(self): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
30 self.ted.WEIdle() |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
31 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
32 def do_activate(self, onoff, evt): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
33 if onoff: |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
34 self.ted.WEActivate() |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
35 else: |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
36 self.ted.WEDeactivate() |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
37 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
38 def do_update(self, wid, event): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
39 Qd.EraseRect(wid.GetWindowPort().portRect) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
40 self.ted.WEUpdate(wid.GetWindowPort().visRgn) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
41 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
42 def do_contentclick(self, local, modifiers, evt): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
43 (what, message, when, where, modifiers) = evt |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
44 self.ted.WEClick(local, modifiers, when) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
45 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
46 def do_char(self, ch, event): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
47 (what, message, when, where, modifiers) = event |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
48 self.ted.WEKey(ord(ch), modifiers) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
49 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
50 class TestWaste(Application): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
51 def __init__(self): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
52 Application.__init__(self) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
53 self.num = 0 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
54 self.listoflists = [] |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
55 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
56 def makeusermenus(self): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
57 self.filemenu = m = Menu(self.menubar, "File") |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
58 self.newitem = MenuItem(m, "New window...", "O", self.open) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
59 self.quititem = MenuItem(m, "Quit", "Q", self.quit) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
60 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
61 def open(self, *args): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
62 w = WasteWindow(self) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
63 w.open('Window %d'%self.num) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
64 self.num = self.num + 1 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
65 self.listoflists.append(w) |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
66 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
67 def quit(self, *args): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
68 raise self |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
69 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
70 def do_about(self, id, item, window, event): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
71 EasyDialogs.Message("""Test the WASTE interface. |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
72 Simple window in which you can type""") |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
73 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
74 def do_idle(self, *args): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
75 for l in self.listoflists: |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
76 l.do_idle() |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
77 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
78 def main(): |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
79 print 'Open app' |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
80 App = TestWaste() |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
81 print 'run' |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
82 App.mainloop() |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
83 |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
84 if __name__ == '__main__': |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
85 main() |
|
728d5745ae7b
Minimal waste test program, modified from ttedit.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
86 |
