diff 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
line wrap: on
line diff
--- 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