The 0.5 release happened on 2/15, not on 2/14. :-)
[python/dscho.git] / Lib / lib-stdwin / TransParent.py
blob49dcd3d0719ec15d76f7754ac2391296f6661307
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.
6 Error = 'TransParent.Error' # Exception
8 class ManageOneChild:
10 # Upcalls shared with other single-child parents
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
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
26 class TransParent(ManageOneChild):
28 # Calls from creator
29 # NB derived classes may add parameters to create()
31 def create(self, parent):
32 parent.addchild(self)
33 self.parent = parent
34 self.child = None # No child yet
35 return self
37 # Downcalls from parent to child
39 def destroy(self):
40 del self.parent
41 if self.child: self.child.destroy()
42 del self.child
44 def getminsize(self, args):
45 if not self.child:
46 m, size = args
47 return size
48 else:
49 return self.child.getminsize(args)
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)
60 def realize(self):
61 if self.child:
62 self.child.realize()
63 def draw(self, d, area):
64 if self.child:
65 self.child.draw(d, area)
66 def altdraw(self, area):
67 if self.child:
68 self.child.altdraw(area)
70 # Downcalls only made after certain upcalls
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)
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()
86 def timer(self):
87 if self.child: self.child.timer()
89 # Upcalls from child to parent
91 def need_mouse(self, child):
92 self.parent.need_mouse(self)
93 def no_mouse(self, child):
94 self.parent.no_mouse(self)
96 def need_timer(self, child):
97 self.parent.need_timer(self)
98 def no_timer(self, child):
99 self.parent.no_timer(self)
101 def need_altdraw(self, child):
102 self.parent.need_altdraw(self)
103 def no_altdraw(self, child):
104 self.parent.no_altdraw(self)
106 def need_keybd(self, child):
107 self.parent.need_keybd(self)
108 def no_keybd(self, child):
109 self.parent.no_keybd(self)
111 def begindrawing(self):
112 return self.parent.begindrawing()
113 def beginmeasuring(self):
114 return self.parent.beginmeasuring()
115 def getwindow(self):
116 return self.parent.getwindow()
118 def change(self, area):
119 self.parent.change(area)
120 def scroll(self, area, vector):
121 self.parent.scroll(area, vector)
122 def settimer(self, itimer):
123 self.parent.settimer(itimer)