core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.

This commit is contained in:
Goffi 2014-06-25 14:01:57 +02:00
commit 8ca72f8a9f
2 changed files with 26 additions and 9 deletions

View file

@ -201,8 +201,21 @@ class XMLUI(object):
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 @@ class XMLUI(object):
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)

View file

@ -609,8 +609,10 @@ class TextWidget(Widget):
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 @@ class StringWidget(InputWidget):
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):