comparison engine/extensions/pychan/widgets/containers.py @ 255:51cc05d862f2

Merged editor_rewrite branch to trunk. This contains changes that may break compatibility against existing clients. For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 08 Jun 2009 16:00:02 +0000
parents 1cc51d145af9
children 48c99636453e
comparison
equal deleted inserted replaced
254:10b5f7f36dd4 255:51cc05d862f2
36 def addChild(self, widget): 36 def addChild(self, widget):
37 widget.parent = self 37 widget.parent = self
38 self.children.append(widget) 38 self.children.append(widget)
39 self.real_widget.add(widget.real_widget) 39 self.real_widget.add(widget.real_widget)
40 40
41 def insertChild(self, widget, position):
42 if position > len(self.children) or 0-position > len(self.children):
43 print "insertChild: Warning: Index overflow.",
44 if position >= 0:
45 self.addChild(widget)
46 else:
47 self.insertChild(widget, 0)
48 return
49
50 children = self.children[0:position]+[widget]+self.children[position:]
51 #assert len(children) == len(self.children) + 1
52 self.removeAllChildren()
53 for child in children:
54 self.addChild(child)
55
56 def insertChildBefore(self, widget, before):
57 if before not in self.children:
58 raise RuntimeError("Couldn't find widget %s as child of %s - in insertChildBefore" % (str(widget),str(before)))
59 self.insertChild(widget, self.children.index(before))
60
41 def removeChild(self,widget): 61 def removeChild(self,widget):
42 if not widget in self.children: 62 if not widget in self.children:
43 raise RuntimeError("%s does not have %s as direct child widget." % (str(self),str(widget))) 63 raise RuntimeError("%s does not have %s as direct child widget." % (str(self),str(widget)))
44 self.children.remove(widget) 64 self.children.remove(widget)
45 self.real_widget.remove(widget.real_widget) 65 self.real_widget.remove(widget.real_widget)
55 75
56 def getMaxChildrenHeight(self): 76 def getMaxChildrenHeight(self):
57 if not self.children: return 0 77 if not self.children: return 0
58 return max(widget.height for widget in self.children) 78 return max(widget.height for widget in self.children)
59 79
60 def deepApply(self,visitorFunc): 80 def deepApply(self,visitorFunc, leaves_first = True):
61 for child in self.children: 81 if leaves_first:
62 child.deepApply(visitorFunc) 82 for child in self.children:
83 child.deepApply(visitorFunc, leaves_first = leaves_first)
63 visitorFunc(self) 84 visitorFunc(self)
85 if not leaves_first:
86 for child in self.children:
87 child.deepApply(visitorFunc, leaves_first = leaves_first)
64 88
65 def beforeShow(self): 89 def beforeShow(self):
66 self._resetTiling() 90 self._resetTiling()
67 91
68 def _resetTiling(self): 92 def _resetTiling(self):
95 self._background = getattr(self,'_background',None) 119 self._background = getattr(self,'_background',None)
96 if image is None: 120 if image is None:
97 self._background_image = image 121 self._background_image = image
98 map(self.real_widget.remove,self._background) 122 map(self.real_widget.remove,self._background)
99 self._background = [] 123 self._background = []
100 124 return
101 # Background generation is done in _resetTiling 125 # Background generation is done in _resetTiling
102 126
103 if not isinstance(image, fife.GuiImage): 127 if not isinstance(image, fife.GuiImage):
104 image = get_manager().loadImage(image) 128 image = get_manager().loadImage(image)
105 self._background_image = image 129 self._background_image = image
122 The default alignment is to the top. This can be changed by adding a Spacer 146 The default alignment is to the top. This can be changed by adding a Spacer
123 to the widget at any point (but only one!). The spacer will expand, so that 147 to the widget at any point (but only one!). The spacer will expand, so that
124 widgets above the spacer are aligned to the top, while widgets below the spacer 148 widgets above the spacer are aligned to the top, while widgets below the spacer
125 are aligned to the bottom. 149 are aligned to the bottom.
126 """ 150 """
151 DEFAULT_HEXPAND = 0
152 DEFAULT_VEXPAND = 1
153
127 def __init__(self,padding=5,**kwargs): 154 def __init__(self,padding=5,**kwargs):
128 super(VBox,self).__init__(**kwargs) 155 super(VBox,self).__init__(**kwargs)
129 self.padding = padding 156 self.padding = padding
130 157
131 158
133 """ 160 """
134 A horizontally aligned box - for containement of child widgets. 161 A horizontally aligned box - for containement of child widgets.
135 162
136 Please see L{VBox} for details - just change the directions :-). 163 Please see L{VBox} for details - just change the directions :-).
137 """ 164 """
165 DEFAULT_HEXPAND = 1
166 DEFAULT_VEXPAND = 0
167
138 def __init__(self,padding=5,**kwargs): 168 def __init__(self,padding=5,**kwargs):
139 super(HBox,self).__init__(**kwargs) 169 super(HBox,self).__init__(**kwargs)
140 self.padding = padding 170 self.padding = padding
141 171
142 class Window(VBoxLayoutMixin,Container): 172 class Window(VBoxLayoutMixin,Container):
178 h = min(self.max_size[1],h) 208 h = min(self.max_size[1],h)
179 self.real_widget.setHeight(h + self.titlebar_height) 209 self.real_widget.setHeight(h + self.titlebar_height)
180 def _getHeight(self): return self.real_widget.getHeight() - self.titlebar_height 210 def _getHeight(self): return self.real_widget.getHeight() - self.titlebar_height
181 height = property(_getHeight,_setHeight) 211 height = property(_getHeight,_setHeight)
182 212
183
184 # Spacer
185
186 class Spacer(object):
187 """ A spacer represents expandable 'whitespace' in the GUI.
188
189 In a XML file you can get this by adding a <Spacer /> inside a VBox or
190 HBox element (Windows implicitly are VBox elements).
191
192 The effect is, that elements before the spacer will be left (top)
193 and elements after the spacer will be right (bottom) aligned.
194
195 There can only be one spacer in VBox (HBox).
196 """
197 def __init__(self,parent=None,**kwargs):
198 self._parent = parent
199
200 def __str__(self):
201 return "Spacer(parent.name='%s')" % getattr(self._parent,'name','None')
202
203 def __repr__(self):
204 return "<Spacer(parent.name='%s') at %x>" % (getattr(self._parent,'name','None'),id(self))