Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 1 | # Generic Split implementation. |
| 2 | # Use as a base class for other splits. |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 3 | # Derived classes should at least implement the methods that call |
| 4 | # unimpl() below: minsize(), getbounds() and setbounds(). |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 5 | |
| 6 | Error = 'Split.Error' # Exception |
| 7 | |
| 8 | import rect |
| 9 | from util import remove |
| 10 | |
| 11 | class Split(): |
| 12 | # |
| 13 | # Calls from creator |
| 14 | # NB derived classes may add parameters to create() |
| 15 | # |
| 16 | def create(self, parent): |
| 17 | parent.addchild(self) |
| 18 | self.parent = parent |
| 19 | self.children = [] |
| 20 | self.mouse_interest = [] |
| 21 | self.timer_interest = [] |
| 22 | self.mouse_focus = 0 |
| 23 | return self |
| 24 | # |
| 25 | # Downcalls from parent to child |
| 26 | # |
| 27 | def destroy(self): |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 28 | self.parent = None |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 29 | for child in self.children: |
| 30 | child.destroy() |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 31 | del self.children[:] |
| 32 | del self.mouse_interest[:] |
| 33 | del self.timer_interest[:] |
| 34 | self.mouse_focus = None |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 35 | # |
| 36 | def minsize(self, m): return unimpl() |
| 37 | def getbounds(self): return unimpl() |
| 38 | def setbounds(self, bounds): unimpl() |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 39 | # |
| 40 | def draw(self, d_detail): |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 41 | # (Could avoid calls to children outside the area) |
| 42 | for child in self.children: |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 43 | child.draw(d_detail) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 44 | # |
| 45 | # Downcalls only made after certain upcalls |
| 46 | # |
| 47 | def mouse_down(self, detail): |
| 48 | if self.mouse_focus: |
| 49 | self.mouse_focus.mouse_down(detail) |
| 50 | p = detail[0] |
| 51 | for child in self.mouse_interest: |
| 52 | if rect.pointinrect(p, child.getbounds()): |
| 53 | self.mouse_focus = child |
| 54 | child.mouse_down(detail) |
| 55 | def mouse_move(self, detail): |
| 56 | if self.mouse_focus: |
| 57 | self.mouse_focus.mouse_move(detail) |
| 58 | def mouse_up(self, detail): |
| 59 | if self.mouse_focus: |
| 60 | self.mouse_focus.mouse_up(detail) |
| 61 | self.mouse_focus = 0 |
| 62 | # |
| 63 | def timer(self): |
| 64 | for child in self.timer_interest: |
| 65 | child.timer() |
| 66 | # |
| 67 | # Upcalls from child to parent |
| 68 | # |
| 69 | def addchild(self, child): |
| 70 | if child in self.children: |
| 71 | raise Error, 'addchild: child already inlist' |
| 72 | self.children.append(child) |
| 73 | def delchild(self, child): |
| 74 | if child not in self.children: |
| 75 | raise Error, 'delchild: child not in list' |
| 76 | remove(child, self.children) |
| 77 | if child in self.mouse_interest: |
| 78 | remove(child, self.mouse_interest) |
| 79 | if child in self.timer_interest: |
| 80 | remove(child, self.timer_interest) |
| 81 | if child = self.mouse_focus: |
| 82 | self.mouse_focus = 0 |
| 83 | # |
| 84 | def need_mouse(self, child): |
| 85 | if child not in self.mouse_interest: |
| 86 | self.mouse_interest.append(child) |
| 87 | self.parent.need_mouse(self) |
| 88 | def no_mouse(self, child): |
| 89 | if child in self.mouse_interest: |
| 90 | remove(child, self.mouse_interest) |
| 91 | if not self.mouse_interest: |
| 92 | self.parent.no_mouse(self) |
| 93 | # |
| 94 | def need_timer(self, child): |
| 95 | if child not in self.timer_interest: |
| 96 | self.timer_interest.append(child) |
| 97 | self.parent.need_timer(self) |
| 98 | def no_timer(self, child): |
| 99 | if child in self.timer_interest: |
| 100 | remove(child, self.timer_interest) |
| 101 | if not self.timer_interest: |
| 102 | self.parent.no_timer(self) |
| 103 | # |
| 104 | # The rest are transparent: |
| 105 | # |
| 106 | def begindrawing(self): |
| 107 | return self.parent.begindrawing() |
| 108 | def beginmeasuring(self): |
| 109 | return self.parent.beginmeasuring() |
| 110 | # |
| 111 | def change(self, area): |
| 112 | self.parent.change(area) |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 113 | def scroll(self, area_vector): |
| 114 | self.parent.scroll(area_vector) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 115 | def settimer(self, itimer): |
| 116 | self.parent.settimer(itimer) |