changeset 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 03da3ef5fb5b
files frontends/src/jp/xmlui_manager.py frontends/src/primitivus/xmlui.py frontends/src/tools/xmlui.py src/tools/common/template_xmlui.py
diffstat 4 files changed, 40 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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):
--- 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
--- 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'