Mercurial > libervia-backend
comparison frontends/src/tools/xmlui.py @ 2419:c38c54c47e16
frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 05 Nov 2017 13:53:28 +0100 |
parents | 69f979adb1d7 |
children | 467ddb437a71 |
comparison
equal
deleted
inserted
replaced
2418:69f979adb1d7 | 2419:c38c54c47e16 |
---|---|
338 @property widget_factory: factory to create frontend-specific widgets | 338 @property widget_factory: factory to create frontend-specific widgets |
339 @property dialog_factory: factory to create frontend-specific dialogs | 339 @property dialog_factory: factory to create frontend-specific dialogs |
340 """ | 340 """ |
341 widget_factory = None | 341 widget_factory = None |
342 | 342 |
343 def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): | 343 def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE): |
344 """ | 344 """ |
345 @property widgets(dict): widget name => widget map | 345 @property widgets(dict): widget name => widget map |
346 @property widget_value(ValueGetter): retrieve widget value from it's name | 346 @property widget_value(ValueGetter): retrieve widget value from it's name |
347 """ | 347 """ |
348 super(XMLUIPanel, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile) | 348 super(XMLUIPanel, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile) |
349 self.ctrl_list = {} # input widget, used mainly for forms | 349 self.ctrl_list = {} # input widget, used mainly for forms |
350 self.widgets = {} # allow to access any named widgets | 350 self.widgets = {} # allow to access any named widgets |
351 self.widget_value = ValueGetter(self.widgets) | 351 self.widget_value = ValueGetter(self.widgets) |
352 self._main_cont = None | 352 self._main_cont = None |
353 if ignore is None: | |
354 ignore = [] | |
355 self._ignore = ignore | |
353 self.constructUI(parsed_dom) | 356 self.constructUI(parsed_dom) |
354 | 357 |
355 def escape(self, name): | 358 def escape(self, name): |
356 """Return escaped name for forms""" | 359 """Return escaped name for forms""" |
357 return u"%s%s" % (C.SAT_FORM_PREFIX, name) | 360 return u"%s%s" % (C.SAT_FORM_PREFIX, name) |
451 _xmlui_parent._xmluiAddRow(index) | 454 _xmlui_parent._xmluiAddRow(index) |
452 self._parseChilds(_xmlui_parent, node, ('widget', 'container')) | 455 self._parseChilds(_xmlui_parent, node, ('widget', 'container')) |
453 | 456 |
454 elif node.nodeName == "widget": | 457 elif node.nodeName == "widget": |
455 name = node.getAttribute("name") | 458 name = node.getAttribute("name") |
459 if name in self._ignore: | |
460 # current widget is ignored, but there may be already a label | |
461 if CURRENT_LABEL in data: | |
462 # if so, we remove it from parent | |
463 _xmlui_parent._xmluiRemove(data.pop(CURRENT_LABEL)) | |
464 continue | |
456 type_ = node.getAttribute("type") | 465 type_ = node.getAttribute("type") |
457 value_elt = self._getChildNode(node, "value") | 466 value_elt = self._getChildNode(node, "value") |
458 if value_elt is not None: | 467 if value_elt is not None: |
459 value = getText(value_elt) | 468 value = getText(value_elt) |
460 else: | 469 else: |
746 | 755 |
747 | 756 |
748 class XMLUIDialog(XMLUIBase): | 757 class XMLUIDialog(XMLUIBase): |
749 dialog_factory = None | 758 dialog_factory = None |
750 | 759 |
751 def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): | 760 def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE): |
752 super(XMLUIDialog, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile) | 761 super(XMLUIDialog, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile) |
753 top=parsed_dom.documentElement | 762 top=parsed_dom.documentElement |
754 dlg_elt = self._getChildNode(top, "dialog") | 763 dlg_elt = self._getChildNode(top, "dialog") |
755 if dlg_elt is None: | 764 if dlg_elt is None: |
756 raise ValueError("Invalid XMLUI: no Dialog element found !") | 765 raise ValueError("Invalid XMLUI: no Dialog element found !") |
800 """ | 809 """ |
801 assert type_ in (CLASS_PANEL, CLASS_DIALOG) | 810 assert type_ in (CLASS_PANEL, CLASS_DIALOG) |
802 class_map[type_] = class_ | 811 class_map[type_] = class_ |
803 | 812 |
804 | 813 |
805 def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None, callback=None, profile=C.PROF_KEY_NONE): | 814 def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE): |
806 """ | 815 """ |
807 @param dom_parse: methode equivalent to minidom.parseString (but which must manage unicode), or None to use default one | 816 @param dom_parse: methode equivalent to minidom.parseString (but which must manage unicode), or None to use default one |
808 @param dom_free: method used to free the parsed DOM | 817 @param dom_free: method used to free the parsed DOM |
818 @param ignore(list[unicode], None): name of widgets to ignore | |
819 widgets with name in this list and their label will be ignored | |
809 """ | 820 """ |
810 if dom_parse is None: | 821 if dom_parse is None: |
811 from xml.dom import minidom | 822 from xml.dom import minidom |
812 dom_parse = lambda xml_data: minidom.parseString(xml_data.encode('utf-8')) | 823 dom_parse = lambda xml_data: minidom.parseString(xml_data.encode('utf-8')) |
813 dom_free = lambda parsed_dom: parsed_dom.unlink() | 824 dom_free = lambda parsed_dom: parsed_dom.unlink() |
823 else: | 834 else: |
824 cls = class_map[CLASS_DIALOG] | 835 cls = class_map[CLASS_DIALOG] |
825 except KeyError: | 836 except KeyError: |
826 raise ClassNotRegistedError(_("You must register classes with registerClass before creating a XMLUI")) | 837 raise ClassNotRegistedError(_("You must register classes with registerClass before creating a XMLUI")) |
827 | 838 |
828 xmlui = cls(host, parsed_dom, title, flags, callback, profile) | 839 xmlui = cls(host, parsed_dom, |
840 title = title, | |
841 flags = flags, | |
842 callback = callback, | |
843 ignore = ignore, | |
844 profile = profile) | |
829 dom_free(parsed_dom) | 845 dom_free(parsed_dom) |
830 return xmlui | 846 return xmlui |