Mercurial > libervia-backend
changeset 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 |
files | frontends/src/tools/xmlui.py src/tools/xml_tools.py |
diffstat | 2 files changed, 26 insertions(+), 9 deletions(-) [+] |
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)
--- a/src/tools/xml_tools.py Wed Jun 25 14:01:56 2014 +0200 +++ b/src/tools/xml_tools.py Wed Jun 25 14:01:57 2014 +0200 @@ -609,8 +609,10 @@ def __init__(self, xmlui, value, name=None, parent=None): super(TextWidget, self).__init__(xmlui, name, parent) + value_elt = self.xmlui.doc.createElement('value') text = self.xmlui.doc.createTextNode(value) - self.elem.appendChild(text) + value_elt.appendChild(text) + self.elem.appendChild(value_elt) class LabelWidget(Widget): @@ -675,7 +677,10 @@ def __init__(self, xmlui, value=None, name=None, parent=None, read_only=False): super(StringWidget, self).__init__(xmlui, name, parent, read_only=read_only) if value: - self.elem.setAttribute('value', value) + value_elt = self.xmlui.doc.createElement('value') + text = self.xmlui.doc.createTextNode(value) + value_elt.appendChild(text) + self.elem.appendChild(value_elt) class PasswordWidget(StringWidget):