blob: 8cee28318b30d055fef16fa25058a3a464ff2f0f [file] [log] [blame]
Guido van Rossum2e449671990-11-05 19:44:36 +00001# 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
6Error = 'TransParent.Error' # Exception
7
8class ManageOneChild():
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
26class TransParent() = ManageOneChild():
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
34 self.child = 0 # No child yet
35 #
36 # Downcalls from parent to child
37 #
38 def destroy(self):
39 del self.parent
40 if self.child: self.child.destroy()
41 del self.child
42 #
43 def minsize(self, m):
44 if not self.child:
45 return 0, 0
46 else:
47 return self.child.minsize(m)
48 def getbounds(self, bounds):
49 if not self.child:
50 raise Error, 'getbounds w/o child'
51 else:
52 return self.child.getbounds()
53 def setbounds(self, bounds):
54 if not self.child:
55 raise Error, 'setbounds w/o child'
56 else:
57 self.child.setbounds(bounds)
58 def draw(self, args):
59 if self.child:
60 self.child.draw(args)
61 #
62 # Downcalls only made after certain upcalls
63 #
64 def mouse_down(self, detail):
65 if self.child: self.child.mouse_down(detail)
66 def mouse_move(self, detail):
67 if self.child: self.child.mouse_move(detail)
68 def mouse_up(self, detail):
69 if self.child: self.child.mouse_up(detail)
70 #
71 def timer(self):
72 if self.child: self.child.timer()
73 #
74 # Upcalls from child to parent
75 #
76 def need_mouse(self, child):
77 self.parent.need_mouse(self)
78 def no_mouse(self, child):
79 self.parent.no_mouse(self)
80 #
81 def need_timer(self, child):
82 self.parent.need_timer(self)
83 def no_timer(self, child):
84 self.parent.no_timer(self)
85 #
86 def begindrawing(self):
87 return self.parent.begindrawing()
88 def beginmeasuring(self):
89 return self.parent.beginmeasuring()
90 #
91 def change(self, area):
92 self.parent.change(area)
93 def scroll(self, args):
94 self.parent.scroll(args)
95 def settimer(self, itimer):
96 self.parent.settimer(itimer)