Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame^] | 1 | # A 'WindowParent' is the only module that uses real stdwin functionality. |
| 2 | # It is the root of the tree. |
| 3 | # It should have exactly one child when realized. |
| 4 | |
| 5 | import stdwin |
| 6 | from stdwinevents import * |
| 7 | |
| 8 | from TransParent import ManageOneChild |
| 9 | |
| 10 | Error = 'WindowParent.Error' # Exception |
| 11 | |
| 12 | class WindowParent() = ManageOneChild(): |
| 13 | # |
| 14 | def create(self, (title, size)): |
| 15 | self.title = title |
| 16 | self.size = size # (width, height) |
| 17 | self.child = 0 # i.e., no child yet |
| 18 | self.win = 0 # i.e., no window yet |
| 19 | self.itimer = 0 |
| 20 | self.do_mouse = 0 |
| 21 | self.do_timer = 0 |
| 22 | return self |
| 23 | # |
| 24 | def need_mouse(self, child): self.do_mouse = 1 |
| 25 | def no_mouse(self, child): self.do_mouse = 0 |
| 26 | # |
| 27 | def need_timer(self, child): self.do_timer = 1 |
| 28 | def no_timer(self, child): self.do_timer = 0 |
| 29 | # |
| 30 | def realize(self): |
| 31 | if self.win: |
| 32 | raise Error, 'realize(): called twice' |
| 33 | if not self.child: |
| 34 | raise Error, 'realize(): no child' |
| 35 | size = self.child.minsize(self.beginmeasuring()) |
| 36 | self.size = max(self.size[0], size[0]), \ |
| 37 | max(self.size[1], size[1]) |
| 38 | stdwin.setdefwinsize(self.size) |
| 39 | self.win = stdwin.open(self.title) |
| 40 | if self.itimer: |
| 41 | self.win.settimer(self.itimer) |
| 42 | bounds = (0, 0), self.win.getwinsize() |
| 43 | self.child.setbounds(bounds) |
| 44 | # |
| 45 | def beginmeasuring(self): |
| 46 | # Return something with which a child can measure text |
| 47 | if self.win: |
| 48 | return self.win.begindrawing() |
| 49 | else: |
| 50 | return stdwin |
| 51 | # |
| 52 | def begindrawing(self): |
| 53 | if self.win: |
| 54 | return self.win.begindrawing() |
| 55 | else: |
| 56 | raise Error, 'begindrawing(): not realized yet' |
| 57 | # |
| 58 | def change(self, area): |
| 59 | if self.win: |
| 60 | self.win.change(area) |
| 61 | # |
| 62 | def scroll(self, args): |
| 63 | if self.win: |
| 64 | self.win.scroll(args) |
| 65 | # |
| 66 | def settimer(self, itimer): |
| 67 | if self.win: |
| 68 | self.win.settimer(itimer) |
| 69 | else: |
| 70 | self.itimer = itimer |
| 71 | # |
| 72 | # Only call dispatch if we have a child |
| 73 | # |
| 74 | def dispatch(self, (type, win, detail)): |
| 75 | if win <> self.win: |
| 76 | return |
| 77 | elif type = WE_DRAW: |
| 78 | d = self.win.begindrawing() |
| 79 | self.child.draw(d, detail) |
| 80 | elif type = WE_MOUSE_DOWN: |
| 81 | if self.do_mouse: self.child.mouse_down(detail) |
| 82 | elif type = WE_MOUSE_MOVE: |
| 83 | if self.do_mouse: self.child.mouse_move(detail) |
| 84 | elif type = WE_MOUSE_UP: |
| 85 | if self.do_mouse: self.child.mouse_up(detail) |
| 86 | elif type = WE_TIMER: |
| 87 | if self.do_timer: self.child.timer() |
| 88 | elif type = WE_SIZE: |
| 89 | self.win.change((0, 0), (10000, 10000)) # XXX |
| 90 | bounds = (0, 0), self.win.getwinsize() |
| 91 | self.child.setbounds(bounds) |
| 92 | # |