frontends (xmlui): new _xmlui_for_name attribute:

_xmlui_for_name is an attribute which can be set to Label widgets to indicate the name of the linked widget.
This attribute is set automatically for LabelContainer.
data argument in _parseChilds is now a dict (or None)
This commit is contained in:
Goffi 2017-10-16 07:21:44 +02:00
commit d78aa6f922

View file

@ -368,8 +368,10 @@ class XMLUIPanel(XMLUIBase):
@param _xmlui_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
@param data: additionnal data which are needed in some cases
@param data(None, dict): additionnal data which are needed in some cases
"""
if data is None:
data = {}
for node in current_node.childNodes:
if wanted and not node.nodeName in wanted:
raise InvalidXMLUI('Unexpected node: [%s]' % node.nodeName)
@ -382,7 +384,7 @@ class XMLUIPanel(XMLUIBase):
self.main_cont = _xmlui_parent
if type_ == "tabs":
cont = self.widget_factory.createTabsContainer(_xmlui_parent)
self._parseChilds(_xmlui_parent, node, ('tab',), cont)
self._parseChilds(_xmlui_parent, node, ('tab',), {'tabs_cont': cont})
elif type_ == "vertical":
cont = self.widget_factory.createVerticalContainer(_xmlui_parent)
self._parseChilds(cont, node, ('widget', 'container'))
@ -391,7 +393,7 @@ class XMLUIPanel(XMLUIBase):
self._parseChilds(cont, node, ('widget', 'container'))
elif type_ == "label":
cont = self.widget_factory.createLabelContainer(_xmlui_parent)
self._parseChilds(cont, node, ('widget', 'container'))
self._parseChilds(cont, node, ('widget', 'container'), {'current_label': None})
elif type_ == "advanced_list":
try:
columns = int(node.getAttribute('columns'))
@ -427,20 +429,21 @@ class XMLUIPanel(XMLUIBase):
name = node.getAttribute('name')
label = node.getAttribute('label')
selected = C.bool(node.getAttribute('selected') or C.BOOL_FALSE)
if not name or not isinstance(data, TabsContainer):
if not name or not 'tabs_cont' in data:
raise InvalidXMLUI
if self.type == 'param':
self._current_category = name #XXX: awful hack because params need category and we don't keep parent
tab_cont = data
tab_cont = data['tabs_cont']
new_tab = tab_cont._xmluiAddTab(label or name, selected)
self._parseChilds(new_tab, node, ('widget', 'container'))
elif node.nodeName == 'row':
try:
index = str(data['index'])
data['index'] += 1
except TypeError:
except KeyError:
index = node.getAttribute('index') or None
else:
data['index'] += 1
_xmlui_parent._xmluiAddRow(index)
self._parseChilds(_xmlui_parent, node, ('widget', 'container'))
@ -454,10 +457,14 @@ class XMLUIPanel(XMLUIBase):
value = node.getAttribute("value") if node.hasAttribute('value') else u''
if type_=="empty":
ctrl = self.widget_factory.createEmptyWidget(_xmlui_parent)
if 'current_label' in data:
data['current_label'] = None
elif type_=="text":
ctrl = self.widget_factory.createTextWidget(_xmlui_parent, value)
elif type_=="label":
ctrl = self.widget_factory.createLabelWidget(_xmlui_parent, value)
if 'current_label' in data:
data['current_label'] = ctrl
elif type_=="jid":
ctrl = self.widget_factory.createJidWidget(_xmlui_parent, value)
elif type_=="divider":
@ -515,8 +522,8 @@ class XMLUIPanel(XMLUIBase):
callback = node.getAttribute("internal_callback") or None
if callback:
fields = [field.getAttribute('name') for field in node.getElementsByTagName("internal_field")]
data = self.getInternalCallbackData(callback, node)
ctrl._xmlui_param_internal = (callback, fields, data)
cb_data = self.getInternalCallbackData(callback, node)
ctrl._xmlui_param_internal = (callback, fields, cb_data)
if type_ == 'button':
ctrl._xmluiOnClick(self.onChangeInternal)
else:
@ -524,6 +531,10 @@ class XMLUIPanel(XMLUIBase):
ctrl._xmlui_name = name
_xmlui_parent._xmluiAppend(ctrl)
if 'current_label' in data and not isinstance(ctrl, LabelWidget):
# this key is set in LabelContainer, when present
# we can associate the label with the widget it is labelling
data['current_label']._xmlui_for_name = name
else:
raise NotImplementedError(_('Unknown tag [%s]') % node.nodeName)