# HG changeset patch # User Goffi # Date 1509886408 -3600 # Node ID c38c54c47e16b845874ac5605acfc50067f63b1a # Parent 69f979adb1d75c8b77f2f61d1f78da4303b4c68c frontends (xmlui): added an attribute to ignore some widgets (and their label) in create diff -r 69f979adb1d7 -r c38c54c47e16 frontends/src/jp/xmlui_manager.py --- a/frontends/src/jp/xmlui_manager.py Sun Nov 05 13:44:07 2017 +0100 +++ b/frontends/src/jp/xmlui_manager.py Sun Nov 05 13:53:28 2017 +0100 @@ -390,8 +390,14 @@ workflow = None _submit_cb = None - def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=None): - xmlui_manager.XMLUIPanel.__init__(self, host, parsed_dom, title, flags, profile=host.profile) + def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, profile=None): + xmlui_manager.XMLUIPanel.__init__(self, + host, + parsed_dom, + title = title, + flags = flags, + ignore = ignore, + profile=host.profile) self.submitted = False @property diff -r 69f979adb1d7 -r c38c54c47e16 frontends/src/primitivus/xmlui.py --- a/frontends/src/primitivus/xmlui.py Sun Nov 05 13:44:07 2017 +0100 +++ b/frontends/src/primitivus/xmlui.py Sun Nov 05 13:53:28 2017 +0100 @@ -393,10 +393,17 @@ class XMLUIPanel(xmlui.XMLUIPanel, PrimitivusWidget): widget_factory = WidgetFactory() - def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): + def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE): self.widget_factory._xmlui_main = self self._dest = None - xmlui.XMLUIPanel.__init__(self, host, parsed_xml, title, flags, callback, profile) + xmlui.XMLUIPanel.__init__(self, + host, + parsed_xml, + title = title, + flags = flags, + callback = callback, + ignore = ignore, + profile = profile) PrimitivusWidget.__init__(self, self.main_cont, self.xmlui_title) def constructUI(self, parsed_dom): diff -r 69f979adb1d7 -r c38c54c47e16 frontends/src/tools/xmlui.py --- a/frontends/src/tools/xmlui.py Sun Nov 05 13:44:07 2017 +0100 +++ b/frontends/src/tools/xmlui.py Sun Nov 05 13:53:28 2017 +0100 @@ -340,7 +340,7 @@ """ widget_factory = None - def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): + def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE): """ @property widgets(dict): widget name => widget map @property widget_value(ValueGetter): retrieve widget value from it's name @@ -350,6 +350,9 @@ self.widgets = {} # allow to access any named widgets self.widget_value = ValueGetter(self.widgets) self._main_cont = None + if ignore is None: + ignore = [] + self._ignore = ignore self.constructUI(parsed_dom) def escape(self, name): @@ -453,6 +456,12 @@ elif node.nodeName == "widget": name = node.getAttribute("name") + if name in self._ignore: + # current widget is ignored, but there may be already a label + if CURRENT_LABEL in data: + # if so, we remove it from parent + _xmlui_parent._xmluiRemove(data.pop(CURRENT_LABEL)) + continue type_ = node.getAttribute("type") value_elt = self._getChildNode(node, "value") if value_elt is not None: @@ -748,7 +757,7 @@ class XMLUIDialog(XMLUIBase): dialog_factory = None - def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): + def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE): super(XMLUIDialog, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile) top=parsed_dom.documentElement dlg_elt = self._getChildNode(top, "dialog") @@ -802,10 +811,12 @@ class_map[type_] = class_ -def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None, callback=None, profile=C.PROF_KEY_NONE): +def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE): """ @param dom_parse: methode equivalent to minidom.parseString (but which must manage unicode), or None to use default one @param dom_free: method used to free the parsed DOM + @param ignore(list[unicode], None): name of widgets to ignore + widgets with name in this list and their label will be ignored """ if dom_parse is None: from xml.dom import minidom @@ -825,6 +836,11 @@ except KeyError: raise ClassNotRegistedError(_("You must register classes with registerClass before creating a XMLUI")) - xmlui = cls(host, parsed_dom, title, flags, callback, profile) + xmlui = cls(host, parsed_dom, + title = title, + flags = flags, + callback = callback, + ignore = ignore, + profile = profile) dom_free(parsed_dom) return xmlui diff -r 69f979adb1d7 -r c38c54c47e16 src/tools/common/template_xmlui.py --- a/src/tools/common/template_xmlui.py Sun Nov 05 13:44:07 2017 +0100 +++ b/src/tools/common/template_xmlui.py Sun Nov 05 13:53:28 2017 +0100 @@ -145,6 +145,9 @@ def _xmluiAppend(self, widget): self.children.append(widget) + def _xmluiRemove(self, widget): + self.children.remove(widget) + class VerticalContainer(xmlui.VerticalContainer, Container): type = u'vertical'