comparison frontends/src/tools/xmlui.py @ 2418:69f979adb1d7

frotends(xmlui): fixed _xmlui_for_name attribute for labels
author Goffi <goffi@goffi.org>
date Sun, 05 Nov 2017 13:44:07 +0100
parents 8b37a62336c3
children c38c54c47e16
comparison
equal deleted inserted replaced
2417:192ae573901a 2418:69f979adb1d7
25 25
26 26
27 class_map = {} 27 class_map = {}
28 CLASS_PANEL = 'panel' 28 CLASS_PANEL = 'panel'
29 CLASS_DIALOG = 'dialog' 29 CLASS_DIALOG = 'dialog'
30 CURRENT_LABEL = 'current_label'
30 31
31 class InvalidXMLUI(Exception): 32 class InvalidXMLUI(Exception):
32 pass 33 pass
33 34
34 35
394 elif type_ == "pairs": 395 elif type_ == "pairs":
395 cont = self.widget_factory.createPairsContainer(_xmlui_parent) 396 cont = self.widget_factory.createPairsContainer(_xmlui_parent)
396 self._parseChilds(cont, node, ('widget', 'container')) 397 self._parseChilds(cont, node, ('widget', 'container'))
397 elif type_ == "label": 398 elif type_ == "label":
398 cont = self.widget_factory.createLabelContainer(_xmlui_parent) 399 cont = self.widget_factory.createLabelContainer(_xmlui_parent)
399 self._parseChilds(cont, node, ('widget', 'container'), {'current_label': None}) 400 self._parseChilds(cont, node, ('widget', 'container'), {CURRENT_LABEL: None})
400 elif type_ == "advanced_list": 401 elif type_ == "advanced_list":
401 try: 402 try:
402 columns = int(node.getAttribute('columns')) 403 columns = int(node.getAttribute('columns'))
403 except (TypeError, ValueError): 404 except (TypeError, ValueError):
404 raise DataError("Invalid columns") 405 raise DataError("Invalid columns")
458 value = getText(value_elt) 459 value = getText(value_elt)
459 else: 460 else:
460 value = node.getAttribute("value") if node.hasAttribute('value') else u'' 461 value = node.getAttribute("value") if node.hasAttribute('value') else u''
461 if type_=="empty": 462 if type_=="empty":
462 ctrl = self.widget_factory.createEmptyWidget(_xmlui_parent) 463 ctrl = self.widget_factory.createEmptyWidget(_xmlui_parent)
463 if 'current_label' in data: 464 if CURRENT_LABEL in data:
464 data['current_label'] = None 465 data[CURRENT_LABEL] = None
465 elif type_=="text": 466 elif type_=="text":
466 ctrl = self.widget_factory.createTextWidget(_xmlui_parent, value) 467 ctrl = self.widget_factory.createTextWidget(_xmlui_parent, value)
467 elif type_=="label": 468 elif type_=="label":
468 ctrl = self.widget_factory.createLabelWidget(_xmlui_parent, value) 469 ctrl = self.widget_factory.createLabelWidget(_xmlui_parent, value)
469 if 'current_label' in data: 470 data[CURRENT_LABEL] = ctrl
470 data['current_label'] = ctrl
471 elif type_=="jid": 471 elif type_=="jid":
472 ctrl = self.widget_factory.createJidWidget(_xmlui_parent, value) 472 ctrl = self.widget_factory.createJidWidget(_xmlui_parent, value)
473 elif type_=="divider": 473 elif type_=="divider":
474 style = node.getAttribute("style") or 'line' 474 style = node.getAttribute("style") or 'line'
475 ctrl = self.widget_factory.createDividerWidget(_xmlui_parent, style) 475 ctrl = self.widget_factory.createDividerWidget(_xmlui_parent, style)
535 else: 535 else:
536 ctrl._xmluiOnChange(self.onChangeInternal) 536 ctrl._xmluiOnChange(self.onChangeInternal)
537 537
538 ctrl._xmlui_name = name 538 ctrl._xmlui_name = name
539 _xmlui_parent._xmluiAppend(ctrl) 539 _xmlui_parent._xmluiAppend(ctrl)
540 if 'current_label' in data and not isinstance(ctrl, LabelWidget): 540 if CURRENT_LABEL in data and not isinstance(ctrl, LabelWidget):
541 # this key is set in LabelContainer, when present 541 # this key is set in LabelContainer, when present
542 # we can associate the label with the widget it is labelling 542 # we can associate the label with the widget it is labelling
543 data['current_label']._xmlui_for_name = name 543 data.pop(CURRENT_LABEL)._xmlui_for_name = name
544 544
545 else: 545 else:
546 raise NotImplementedError(_('Unknown tag [%s]') % node.nodeName) 546 raise NotImplementedError(_('Unknown tag [%s]') % node.nodeName)
547 547
548 def constructUI(self, parsed_dom, post_treat=None): 548 def constructUI(self, parsed_dom, post_treat=None):