changeset 336:16112ef84609

PyChan fixes: * Previous commits removed the ability to map events to unnamed widgets. Fixed.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 24 Aug 2009 15:34:23 +0000
parents 162662bf5c8a
children f9aca52c7c45
files engine/extensions/pychan/widgets/widget.py
diffstat 1 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/engine/extensions/pychan/widgets/widget.py	Mon Aug 24 14:53:17 2009 +0000
+++ b/engine/extensions/pychan/widgets/widget.py	Mon Aug 24 15:34:23 2009 +0000
@@ -304,12 +304,14 @@
 		self.deepApply(_childCollector)
 		return children
 
-	def getNamedChildren(self):
+	def getNamedChildren(self, include_unnamed = False):
 		"""
 		Create a dictionary of child widgets with the keys being
 		their name. This will contain only Widgets which have
 		a name different from "__unnamed__" (which is the default).
 		
+		@param include_unnamed Defaults to false. If this is true unnamed widgets are added, too.
+		
 		The values are lists of widgets, so not only unique names
 		are handled correctly.
 
@@ -319,9 +321,13 @@
 				print widget.name , " == info"
 		"""
 		children = {}
-		def _childCollector(widget):
-			if widget.has_name:
+		if include_unnamed:
+			def _childCollector(widget):
 				children.setdefault(widget._name,[]).append(widget)
+		else:
+			def _childCollector(widget):
+				if widget.has_name:
+					children.setdefault(widget._name,[]).append(widget)
 		self.deepApply(_childCollector)
 		return children
 
@@ -467,7 +473,7 @@
 			})
 
 		"""
-		children = self.getNamedChildren()
+		children = self.getNamedChildren(include_unnamed=True)
 		for descr,func in eventMap.items():
 			name, event_name, group_name = events.splitEventDescriptor(descr)
 			#print name, event_name, group_name
@@ -521,7 +527,7 @@
 		  })
 
 		"""
-		children = self.getNamedChildren()
+		children = self.getNamedChildren(include_unnamed=True)
 		for name,data in initialDataMap.items():
 			widgetList = children.get(name,[])
 			for widget in widgetList:
@@ -540,7 +546,7 @@
 		  })
 
 		"""
-		children = self.getNamedChildren()
+		children = self.getNamedChildren(include_unnamed=True)
 		for name,data in dataMap.items():
 			widgetList = children.get(name,[])
 			if len(widgetList) != 1:
@@ -561,7 +567,7 @@
 		  print "You entered:",data['myTextField']," and selected ",data['myListBox']
 
 		"""
-		children = self.getNamedChildren()
+		children = self.getNamedChildren(include_unnamed=True)
 		dataMap = {}
 		for name in widgetNames:
 			widgetList = children.get(name,[])
@@ -594,7 +600,7 @@
 		  test = guiElement.collectData('testElement')
 
 		"""
-		children = self.getNamedChildren()
+		children = self.getNamedChildren(include_unnamed=True)
 		dataList = []
 		for name in widgetNames:
 			widgetList = children.get(name,[])