Fix three PyChecker-detected gotchas.
[python/dscho.git] / Mac / Lib / test / ttedit.py
bloba4cd7746af51216fc02c2c362314c17b242b425e
1 # Test TE module.
2 # Draw a window in which the user can type.
4 # This test expects Win, Evt and FrameWork (and anything used by those)
5 # to work.
7 # Actually, it is more a test of FrameWork by now....
9 from FrameWork import *
10 import Win
11 import Qd
12 import TE
13 import os
15 class TEWindow(Window):
16 def open(self, name):
17 r = (40, 40, 400, 300)
18 w = Win.NewWindow(r, name, 1, 0, -1, 1, 0x55555555)
19 r2 = (0, 0, 345, 245)
20 Qd.SetPort(w)
21 self.ted = TE.TENew(r2, r2)
22 self.ted.TEAutoView(1)
23 w.DrawGrowIcon()
24 self.wid = w
25 self.do_postopen()
27 def do_idle(self):
28 self.ted.TEIdle()
30 def do_activate(self, onoff, evt):
31 if onoff:
32 self.ted.TEActivate()
33 else:
34 self.ted.TEDeactivate()
36 def do_update(self, wid, event):
37 Qd.EraseRect(wid.GetWindowPort().portRect)
38 self.ted.TEUpdate(wid.GetWindowPort().portRect)
40 def do_contentclick(self, local, modifiers, evt):
41 shifted = (modifiers & 0x200)
42 self.ted.TEClick(local, shifted)
44 def do_char(self, ch, event):
45 self.ted.TEKey(ord(ch))
47 class TestList(Application):
48 def __init__(self):
49 Application.__init__(self)
50 self.num = 0
51 self.listoflists = []
53 def makeusermenus(self):
54 self.filemenu = m = Menu(self.menubar, "File")
55 self.newitem = MenuItem(m, "New window...", "O", self.open)
56 self.quititem = MenuItem(m, "Quit", "Q", self.quit)
58 def open(self, *args):
59 w = TEWindow(self)
60 w.open('Window %d'%self.num)
61 self.num = self.num + 1
62 self.listoflists.append(w)
64 def quit(self, *args):
65 raise self
67 def do_about(self, id, item, window, event):
68 EasyDialogs.Message("""Test the TextEdit interface.
69 Simple window in which you can type""")
71 def do_idle(self, *args):
72 for l in self.listoflists:
73 l.do_idle()
75 def main():
76 App = TestList()
77 App.mainloop()
79 if __name__ == '__main__':
80 main()