comparison frontends/src/tools/xmlui.py @ 1086:2cb30f46e560

core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
author Goffi <goffi@goffi.org>
date Wed, 25 Jun 2014 14:01:57 +0200
parents 7a39ae3950f7
children b3b7a2863060
comparison
equal deleted inserted replaced
1085:7a39ae3950f7 1086:2cb30f46e560
199 @return (bool): True if widget's attribute is set ("true") 199 @return (bool): True if widget's attribute is set ("true")
200 """ 200 """
201 read_only = node.getAttribute(name) or "false" 201 read_only = node.getAttribute(name) or "false"
202 return read_only.lower().strip() == "true" 202 return read_only.lower().strip() == "true"
203 203
204 def _getChildNode(self, node, name):
205 """Return the first child node with the given name
206
207 @param node: Node instance
208 @param name: name of the wanted node
209
210 @return: The found element or None
211 """
212 for child in node.childNodes:
213 if child.nodeName == name:
214 return child
215 return None
216
204 def _parseChilds(self, parent, current_node, wanted = ('container',), data = None): 217 def _parseChilds(self, parent, current_node, wanted = ('container',), data = None):
205 """ Recursively parse childNodes of an elemen 218 """Recursively parse childNodes of an elemen
206 @param parent: widget container with '_xmluiAppend' method 219 @param parent: widget container with '_xmluiAppend' method
207 @param current_node: element from which childs will be parsed 220 @param current_node: element from which childs will be parsed
208 @param wanted: list of tag names that can be present in the childs to be SàT XMLUI compliant 221 @param wanted: list of tag names that can be present in the childs to be SàT XMLUI compliant
209 @param data: additionnal data which are needed in some cases 222 @param data: additionnal data which are needed in some cases
210 223
279 292
280 elif node.nodeName == "widget": 293 elif node.nodeName == "widget":
281 id_ = node.getAttribute("id") 294 id_ = node.getAttribute("id")
282 name = node.getAttribute("name") 295 name = node.getAttribute("name")
283 type_ = node.getAttribute("type") 296 type_ = node.getAttribute("type")
284 value = node.getAttribute("value") if node.hasAttribute('value') else u'' 297 value_elt = self._getChildNode(node, "value")
298 if value_elt is not None:
299 value = getText(value_elt)
300 else:
301 value = node.getAttribute("value") if node.hasAttribute('value') else u''
285 if type_=="empty": 302 if type_=="empty":
286 ctrl = self.widget_factory.createEmptyWidget(parent) 303 ctrl = self.widget_factory.createEmptyWidget(parent)
287 elif type_=="text": 304 elif type_=="text":
288 try:
289 value = node.childNodes[0].wholeText
290 except IndexError:
291 # warning (_("text node has no child !"))
292 pass # FIXME proper warning (this one is not OK with Libervia)
293 ctrl = self.widget_factory.createTextWidget(parent, value) 305 ctrl = self.widget_factory.createTextWidget(parent, value)
294 elif type_=="label": 306 elif type_=="label":
295 ctrl = self.widget_factory.createLabelWidget(parent, value) 307 ctrl = self.widget_factory.createLabelWidget(parent, value)
296 elif type_=="jid": 308 elif type_=="jid":
297 ctrl = self.widget_factory.createJidWidget(parent, value) 309 ctrl = self.widget_factory.createJidWidget(parent, value)