|
| 1 | +# Test TE module. |
| 2 | +# Draw a window in which the user can type. |
| 3 | +# |
| 4 | +# This test expects Win, Evt and FrameWork (and anything used by those) |
| 5 | +# to work. |
| 6 | +# |
| 7 | +# Actually, it is more a test of FrameWork by now.... |
| 8 | + |
| 9 | +from FrameWork import * |
| 10 | +import Win |
| 11 | +import Qd |
| 12 | +import TE |
| 13 | +import os |
| 14 | + |
| 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 | + w.DrawGrowIcon() |
| 23 | + self.wid = w |
| 24 | + self.do_postopen() |
| 25 | + |
| 26 | + def do_idle(self): |
| 27 | + self.ted.TEIdle() |
| 28 | + |
| 29 | + def do_activate(self, onoff, evt): |
| 30 | + if onoff: |
| 31 | + self.ted.TEActivate() |
| 32 | + else: |
| 33 | + self.ted.TEDeactivate() |
| 34 | + |
| 35 | + def do_rawupdate(self, window, event): |
| 36 | + window.BeginUpdate() |
| 37 | + self.do_update(window, event) |
| 38 | + window.EndUpdate() |
| 39 | + |
| 40 | + def do_update(self, *args): |
| 41 | + Qd.EraseRect(self.wid.GetWindowPort().portRect) |
| 42 | + self.ted.TEUpdate(self.wid.GetWindowPort().portRect) |
| 43 | + |
| 44 | + def do_contentclick(self, local, modifiers, evt): |
| 45 | + shifted = (modifiers & 0x200) |
| 46 | + self.ted.TEClick(local, shifted) |
| 47 | + |
| 48 | + def do_char(self, ch, event): |
| 49 | + self.ted.TEKey(ch) |
| 50 | + |
| 51 | +class TestList(Application): |
| 52 | + def __init__(self): |
| 53 | + Application.__init__(self) |
| 54 | + self.num = 0 |
| 55 | + self.listoflists = [] |
| 56 | + |
| 57 | + def makeusermenus(self): |
| 58 | + self.filemenu = m = Menu(self.menubar, "File") |
| 59 | + self.newitem = MenuItem(m, "New window...", "O", self.open) |
| 60 | + self.quititem = MenuItem(m, "Quit", "Q", self.quit) |
| 61 | + |
| 62 | + def open(self, *args): |
| 63 | + w = TEWindow(self) |
| 64 | + w.open('Window %d'%self.num) |
| 65 | + self.num = self.num + 1 |
| 66 | + self.listoflists.append(w) |
| 67 | + |
| 68 | + def quit(self, *args): |
| 69 | + raise self |
| 70 | + |
| 71 | + def do_about(self, id, item, window, event): |
| 72 | + EasyDialogs.Message("""Test the TextEdit interface. |
| 73 | + Simple window in which you can type""") |
| 74 | + |
| 75 | + def do_idle(self, *args): |
| 76 | + for l in self.listoflists: |
| 77 | + l.do_idle() |
| 78 | + |
| 79 | +def main(): |
| 80 | + App = TestList() |
| 81 | + App.mainloop() |
| 82 | + |
| 83 | +if __name__ == '__main__': |
| 84 | + main() |
| 85 | + |
0 commit comments