Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 1 | # A class that sits transparently between a parent and one child. |
| 2 | # First create the parent, then this thing, then the child. |
| 3 | # Use this as a base class for objects that are almost transparent. |
| 4 | # Don't use as a base class for parents with multiple children. |
| 5 | |
| 6 | Error = 'TransParent.Error' # Exception |
| 7 | |
Guido van Rossum | 564f550 | 1991-12-30 16:02:20 +0000 | [diff] [blame] | 8 | class ManageOneChild: |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 9 | # |
| 10 | # Upcalls shared with other single-child parents |
| 11 | # |
| 12 | def addchild(self, child): |
| 13 | if self.child: |
| 14 | raise Error, 'addchild: one child only' |
| 15 | if not child: |
| 16 | raise Error, 'addchild: bad child' |
| 17 | self.child = child |
| 18 | # |
| 19 | def delchild(self, child): |
| 20 | if not self.child: |
| 21 | raise Error, 'delchild: no child' |
| 22 | if child <> self.child: |
| 23 | raise Error, 'delchild: not my child' |
| 24 | self.child = 0 |
| 25 | |
Guido van Rossum | 564f550 | 1991-12-30 16:02:20 +0000 | [diff] [blame] | 26 | class TransParent(ManageOneChild): |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 27 | # |
| 28 | # Calls from creator |
| 29 | # NB derived classes may add parameters to create() |
| 30 | # |
| 31 | def create(self, parent): |
| 32 | parent.addchild(self) |
| 33 | self.parent = parent |
Guido van Rossum | e11d4cc | 1991-08-16 13:22:08 +0000 | [diff] [blame] | 34 | self.child = None # No child yet |
Guido van Rossum | 4f4794a | 1991-04-07 13:36:09 +0000 | [diff] [blame] | 35 | return self |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 36 | # |
| 37 | # Downcalls from parent to child |
| 38 | # |
| 39 | def destroy(self): |
| 40 | del self.parent |
| 41 | if self.child: self.child.destroy() |
| 42 | del self.child |
| 43 | # |
Guido van Rossum | e11d4cc | 1991-08-16 13:22:08 +0000 | [diff] [blame] | 44 | def getminsize(self, args): |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 45 | if not self.child: |
Guido van Rossum | e11d4cc | 1991-08-16 13:22:08 +0000 | [diff] [blame] | 46 | m, size = args |
| 47 | return size |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 48 | else: |
Guido van Rossum | e11d4cc | 1991-08-16 13:22:08 +0000 | [diff] [blame] | 49 | return self.child.getminsize(args) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 50 | def getbounds(self, bounds): |
| 51 | if not self.child: |
| 52 | raise Error, 'getbounds w/o child' |
| 53 | else: |
| 54 | return self.child.getbounds() |
| 55 | def setbounds(self, bounds): |
| 56 | if not self.child: |
| 57 | raise Error, 'setbounds w/o child' |
| 58 | else: |
| 59 | self.child.setbounds(bounds) |
Guido van Rossum | 4f4794a | 1991-04-07 13:36:09 +0000 | [diff] [blame] | 60 | def realize(self): |
| 61 | if self.child: |
| 62 | self.child.realize() |
Guido van Rossum | fea2af1 | 1993-01-04 09:16:51 +0000 | [diff] [blame] | 63 | def draw(self, d, area): |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 64 | if self.child: |
Guido van Rossum | fea2af1 | 1993-01-04 09:16:51 +0000 | [diff] [blame] | 65 | self.child.draw(d, area) |
| 66 | def altdraw(self, area): |
Guido van Rossum | 4f4794a | 1991-04-07 13:36:09 +0000 | [diff] [blame] | 67 | if self.child: |
Guido van Rossum | fea2af1 | 1993-01-04 09:16:51 +0000 | [diff] [blame] | 68 | self.child.altdraw(area) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 69 | # |
| 70 | # Downcalls only made after certain upcalls |
| 71 | # |
| 72 | def mouse_down(self, detail): |
| 73 | if self.child: self.child.mouse_down(detail) |
| 74 | def mouse_move(self, detail): |
| 75 | if self.child: self.child.mouse_move(detail) |
| 76 | def mouse_up(self, detail): |
| 77 | if self.child: self.child.mouse_up(detail) |
| 78 | # |
Guido van Rossum | e11d4cc | 1991-08-16 13:22:08 +0000 | [diff] [blame] | 79 | def keybd(self, type_detail): |
| 80 | self.child.keybd(type_detail) |
| 81 | def activate(self): |
| 82 | self.child.activate() |
| 83 | def deactivate(self): |
| 84 | self.child.deactivate() |
| 85 | # |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 86 | def timer(self): |
| 87 | if self.child: self.child.timer() |
| 88 | # |
| 89 | # Upcalls from child to parent |
| 90 | # |
| 91 | def need_mouse(self, child): |
| 92 | self.parent.need_mouse(self) |
| 93 | def no_mouse(self, child): |
| 94 | self.parent.no_mouse(self) |
| 95 | # |
| 96 | def need_timer(self, child): |
| 97 | self.parent.need_timer(self) |
| 98 | def no_timer(self, child): |
| 99 | self.parent.no_timer(self) |
| 100 | # |
Guido van Rossum | 4f4794a | 1991-04-07 13:36:09 +0000 | [diff] [blame] | 101 | def need_altdraw(self, child): |
| 102 | self.parent.need_altdraw(self) |
| 103 | def no_altdraw(self, child): |
| 104 | self.parent.no_altdraw(self) |
| 105 | # |
Guido van Rossum | e11d4cc | 1991-08-16 13:22:08 +0000 | [diff] [blame] | 106 | def need_keybd(self, child): |
| 107 | self.parent.need_keybd(self) |
| 108 | def no_keybd(self, child): |
| 109 | self.parent.no_keybd(self) |
| 110 | # |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 111 | def begindrawing(self): |
| 112 | return self.parent.begindrawing() |
| 113 | def beginmeasuring(self): |
| 114 | return self.parent.beginmeasuring() |
Guido van Rossum | 4f4794a | 1991-04-07 13:36:09 +0000 | [diff] [blame] | 115 | def getwindow(self): |
| 116 | return self.parent.getwindow() |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 117 | # |
| 118 | def change(self, area): |
| 119 | self.parent.change(area) |
Guido van Rossum | fea2af1 | 1993-01-04 09:16:51 +0000 | [diff] [blame] | 120 | def scroll(self, area, vector): |
| 121 | self.parent.scroll(area, vector) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 122 | def settimer(self, itimer): |
| 123 | self.parent.settimer(itimer) |