Jack Jansen | 2cc4160 | 1996-04-19 15:57:52 +0000 | [diff] [blame] | 1 | # Test waste 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 waste |
| 13 | import WASTEconst |
| 14 | import os |
| 15 | |
| 16 | class WasteWindow(Window): |
| 17 | def open(self, name): |
| 18 | r = (40, 40, 400, 300) |
| 19 | w = Win.NewWindow(r, name, 1, 0, -1, 1, 0x55555555) |
| 20 | r2 = (0, 0, 400-40-16, 300-40-16) |
| 21 | Qd.SetPort(w) |
| 22 | flags = WASTEconst.weDoAutoScroll | WASTEconst.weDoOutlineHilite | \ |
| 23 | WASTEconst.weDoMonoStyled |
| 24 | self.ted = waste.WENew(r2, r2, flags) |
| 25 | w.DrawGrowIcon() |
| 26 | self.wid = w |
| 27 | self.do_postopen() |
| 28 | |
| 29 | def do_idle(self): |
| 30 | self.ted.WEIdle() |
| 31 | |
| 32 | def do_activate(self, onoff, evt): |
| 33 | if onoff: |
| 34 | self.ted.WEActivate() |
| 35 | else: |
| 36 | self.ted.WEDeactivate() |
| 37 | |
| 38 | def do_update(self, wid, event): |
| 39 | Qd.EraseRect(wid.GetWindowPort().portRect) |
| 40 | self.ted.WEUpdate(wid.GetWindowPort().visRgn) |
| 41 | |
| 42 | def do_contentclick(self, local, modifiers, evt): |
| 43 | (what, message, when, where, modifiers) = evt |
| 44 | self.ted.WEClick(local, modifiers, when) |
| 45 | |
| 46 | def do_char(self, ch, event): |
| 47 | (what, message, when, where, modifiers) = event |
| 48 | self.ted.WEKey(ord(ch), modifiers) |
| 49 | |
| 50 | class TestWaste(Application): |
| 51 | def __init__(self): |
| 52 | Application.__init__(self) |
| 53 | self.num = 0 |
| 54 | self.listoflists = [] |
| 55 | |
| 56 | def makeusermenus(self): |
| 57 | self.filemenu = m = Menu(self.menubar, "File") |
| 58 | self.newitem = MenuItem(m, "New window...", "O", self.open) |
| 59 | self.quititem = MenuItem(m, "Quit", "Q", self.quit) |
| 60 | |
| 61 | def open(self, *args): |
| 62 | w = WasteWindow(self) |
| 63 | w.open('Window %d'%self.num) |
| 64 | self.num = self.num + 1 |
| 65 | self.listoflists.append(w) |
| 66 | |
| 67 | def quit(self, *args): |
| 68 | raise self |
| 69 | |
| 70 | def do_about(self, id, item, window, event): |
| 71 | EasyDialogs.Message("""Test the WASTE interface. |
| 72 | Simple window in which you can type""") |
| 73 | |
| 74 | def do_idle(self, *args): |
| 75 | for l in self.listoflists: |
| 76 | l.do_idle() |
| 77 | |
| 78 | def main(): |
| 79 | print 'Open app' |
| 80 | App = TestWaste() |
| 81 | print 'run' |
| 82 | App.mainloop() |
| 83 | |
| 84 | if __name__ == '__main__': |
| 85 | main() |
| 86 | |