diff 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
line wrap: on
line diff
--- a/frontends/src/tools/xmlui.py	Wed Jun 25 14:01:56 2014 +0200
+++ b/frontends/src/tools/xmlui.py	Wed Jun 25 14:01:57 2014 +0200
@@ -201,8 +201,21 @@
         read_only = node.getAttribute(name) or "false"
         return read_only.lower().strip() == "true"
 
+    def _getChildNode(self, node, name):
+        """Return the first child node with the given name
+
+        @param node: Node instance
+        @param name: name of the wanted node
+
+        @return: The found element or None
+        """
+        for child in node.childNodes:
+            if child.nodeName == name:
+                return child
+        return None
+
     def _parseChilds(self, parent, current_node, wanted = ('container',), data = None):
-        """ Recursively parse childNodes of an elemen
+        """Recursively parse childNodes of an elemen
         @param parent: widget container with '_xmluiAppend' method
         @param current_node: element from which childs will be parsed
         @param wanted: list of tag names that can be present in the childs to be SàT XMLUI compliant
@@ -281,15 +294,14 @@
                 id_ = node.getAttribute("id")
                 name = node.getAttribute("name")
                 type_ = node.getAttribute("type")
-                value = node.getAttribute("value") if node.hasAttribute('value') else u''
+                value_elt = self._getChildNode(node, "value")
+                if value_elt is not None:
+                    value = getText(value_elt)
+                else:
+                    value = node.getAttribute("value") if node.hasAttribute('value') else u''
                 if type_=="empty":
                     ctrl = self.widget_factory.createEmptyWidget(parent)
                 elif type_=="text":
-                    try:
-                        value = node.childNodes[0].wholeText
-                    except IndexError:
-                        # warning (_("text node has no child !"))
-                        pass # FIXME proper warning (this one is not OK with Libervia)
                     ctrl = self.widget_factory.createTextWidget(parent, value)
                 elif type_=="label":
                     ctrl = self.widget_factory.createLabelWidget(parent, value)