blob: 49dcd3d0719ec15d76f7754ac2391296f6661307 [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
Guido van Rossum564f5501991-12-30 16:02:20 +00008class ManageOneChild:
Guido van Rossum2e449671990-11-05 19:44:36 +00009 #
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 Rossum564f5501991-12-30 16:02:20 +000026class TransParent(ManageOneChild):
Guido van Rossum2e449671990-11-05 19:44:36 +000027 #
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 Rossume11d4cc1991-08-16 13:22:08 +000034 self.child = None # No child yet
Guido van Rossum4f4794a1991-04-07 13:36:09 +000035 return self
Guido van Rossum2e449671990-11-05 19:44:36 +000036 #
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 Rossume11d4cc1991-08-16 13:22:08 +000044 def getminsize(self, args):
Guido van Rossum2e449671990-11-05 19:44:36 +000045 if not self.child:
Guido van Rossume11d4cc1991-08-16 13:22:08 +000046 m, size = args
47 return size
Guido van Rossum2e449671990-11-05 19:44:36 +000048 else:
Guido van Rossume11d4cc1991-08-16 13:22:08 +000049 return self.child.getminsize(args)
Guido van Rossum2e449671990-11-05 19:44:36 +000050 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 Rossum4f4794a1991-04-07 13:36:09 +000060 def realize(self):
61 if self.child:
62 self.child.realize()
Guido van Rossumfea2af11993-01-04 09:16:51 +000063 def draw(self, d, area):
Guido van Rossum2e449671990-11-05 19:44:36 +000064 if self.child:
Guido van Rossumfea2af11993-01-04 09:16:51 +000065 self.child.draw(d, area)
66 def altdraw(self, area):
Guido van Rossum4f4794a1991-04-07 13:36:09 +000067 if self.child:
Guido van Rossumfea2af11993-01-04 09:16:51 +000068 self.child.altdraw(area)
Guido van Rossum2e449671990-11-05 19:44:36 +000069 #
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 Rossume11d4cc1991-08-16 13:22:08 +000079 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 Rossum2e449671990-11-05 19:44:36 +000086 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 Rossum4f4794a1991-04-07 13:36:09 +0000101 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 Rossume11d4cc1991-08-16 13:22:08 +0000106 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 Rossum2e449671990-11-05 19:44:36 +0000111 def begindrawing(self):
112 return self.parent.begindrawing()
113 def beginmeasuring(self):
114 return self.parent.beginmeasuring()
Guido van Rossum4f4794a1991-04-07 13:36:09 +0000115 def getwindow(self):
116 return self.parent.getwindow()
Guido van Rossum2e449671990-11-05 19:44:36 +0000117 #
118 def change(self, area):
119 self.parent.change(area)
Guido van Rossumfea2af11993-01-04 09:16:51 +0000120 def scroll(self, area, vector):
121 self.parent.scroll(area, vector)
Guido van Rossum2e449671990-11-05 19:44:36 +0000122 def settimer(self, itimer):
123 self.parent.settimer(itimer)