Mercurial > libervia-backend
changeset 2377:e50aee5caf33
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)
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 16 Oct 2017 07:21:44 +0200 |
parents | 825608d4eaf8 |
children | 3704cb959ae8 |
files | frontends/src/tools/xmlui.py |
diffstat | 1 files changed, 20 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/tools/xmlui.py Mon Oct 16 07:18:07 2017 +0200 +++ b/frontends/src/tools/xmlui.py Mon Oct 16 07:21:44 2017 +0200 @@ -368,8 +368,10 @@ @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 @@ 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 @@ 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 @@ 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']) + except KeyError: + index = node.getAttribute('index') or None + else: data['index'] += 1 - except TypeError: - index = node.getAttribute('index') or None _xmlui_parent._xmluiAddRow(index) self._parseChilds(_xmlui_parent, node, ('widget', 'container')) @@ -454,10 +457,14 @@ 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 @@ 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 @@ 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)