From fc2af0da9ed2f66918b731a27a34ab7e8434669e Mon Sep 17 00:00:00 2001 From: Goffi Date: Sun, 5 Nov 2017 13:53:28 +0100 Subject: [PATCH] frontends (xmlui): added an attribute to ignore some widgets (and their label) in create --- frontends/src/jp/xmlui_manager.py | 10 ++++++++-- frontends/src/primitivus/xmlui.py | 11 +++++++++-- frontends/src/tools/xmlui.py | 24 ++++++++++++++++++++---- src/tools/common/template_xmlui.py | 3 +++ 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/frontends/src/jp/xmlui_manager.py b/frontends/src/jp/xmlui_manager.py index 387e91a1..55eaa7c6 100644 --- a/frontends/src/jp/xmlui_manager.py +++ b/frontends/src/jp/xmlui_manager.py @@ -390,8 +390,14 @@ class XMLUIPanel(xmlui_manager.XMLUIPanel): 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 --git a/frontends/src/primitivus/xmlui.py b/frontends/src/primitivus/xmlui.py index 8932bec9..72afd2c9 100644 --- a/frontends/src/primitivus/xmlui.py +++ b/frontends/src/primitivus/xmlui.py @@ -393,10 +393,17 @@ class WidgetFactory(GenericFactory): 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 --git a/frontends/src/tools/xmlui.py b/frontends/src/tools/xmlui.py index b03fca3c..c3e1816e 100644 --- a/frontends/src/tools/xmlui.py +++ b/frontends/src/tools/xmlui.py @@ -340,7 +340,7 @@ class XMLUIPanel(XMLUIBase): """ 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 @@ class XMLUIPanel(XMLUIBase): 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 @@ class XMLUIPanel(XMLUIBase): 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 XMLUIPanel(XMLUIBase): 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 @@ def registerClass(type_, class_): 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 @@ def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None 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 --git a/src/tools/common/template_xmlui.py b/src/tools/common/template_xmlui.py index 68bde77a..996ada4f 100644 --- a/src/tools/common/template_xmlui.py +++ b/src/tools/common/template_xmlui.py @@ -145,6 +145,9 @@ class Container(object): def _xmluiAppend(self, widget): self.children.append(widget) + def _xmluiRemove(self, widget): + self.children.remove(widget) + class VerticalContainer(xmlui.VerticalContainer, Container): type = u'vertical'