comparison engine/extensions/pychan/widgets.py @ 236:e476b6b7b2f0

Added removeAllChildren method. (untested) Documentation on event groups.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 24 Mar 2009 08:24:34 +0000
parents 4a5e8e638b0d
children d76169461729
comparison
equal deleted inserted replaced
235:4a5e8e638b0d 236:e476b6b7b2f0
194 194
195 It might be useful to check out L{tools.callbackWithArguments}. 195 It might be useful to check out L{tools.callbackWithArguments}.
196 196
197 @param callback: Event callback - may accept keyword arguments event and widget. 197 @param callback: Event callback - may accept keyword arguments event and widget.
198 @paran event_name: The event to capture - may be one of L{events.EVENTS} and defaults to "action" 198 @paran event_name: The event to capture - may be one of L{events.EVENTS} and defaults to "action"
199 @paran group_name: Event group.
200
201 Event groups are used to have different B{channels} which don't interfere with each other.
202 For derived widgets that need to capture events it's advised to use the group_name 'widget'.
203 The 'default' group is used by default, and should be reserved for the application programmers.
199 """ 204 """
200 self.event_mapper.capture( event_name, callback, group_name ) 205 self.event_mapper.capture( event_name, callback, group_name )
201 206
202 def isCaptured(self): 207 def isCaptured(self):
203 """ 208 """
287 """ 292 """
288 Find all contained child widgets by attribute values. 293 Find all contained child widgets by attribute values.
289 294
290 Usage:: 295 Usage::
291 closeButtons = root_widget.findChildren(name='close') 296 closeButtons = root_widget.findChildren(name='close')
297 buttons = root_widget.findChildren(__class__=pychan.widgets.Button)
292 """ 298 """
293 299
294 children = [] 300 children = []
295 def _childCollector(widget): 301 def _childCollector(widget):
296 if widget.match(**kwargs): 302 if widget.match(**kwargs):
327 """ 333 """
328 raise RuntimeError("Trying to remove a widget from %s, which is not a container widget." % repr(self)) 334 raise RuntimeError("Trying to remove a widget from %s, which is not a container widget." % repr(self))
329 335
330 def removeChildren(self,*widgets): 336 def removeChildren(self,*widgets):
331 for widget in widgets: 337 for widget in widgets:
338 self.removeChild(widget)
339
340 def removeAllChildren(self):
341 """
342 This function will remove all direct child widgets.
343 This will work even for non-container widgets.
344 """
345 children = self.findChildren(parent=self)
346 for widget in children:
332 self.removeChild(widget) 347 self.removeChild(widget)
333 348
334 def mapEvents(self,eventMap,ignoreMissing = False): 349 def mapEvents(self,eventMap,ignoreMissing = False):
335 """ 350 """
336 Convenience function to map widget events to functions 351 Convenience function to map widget events to functions