diff sat_frontends/tools/xmlui.py @ 2669:bdb8276fd2da

frontends (xmlui): class_map is now an arg of create function: class_map was so far used as a global value, but in some cases, several XMLUI managers may be used (it's the case in Cagou's remote controllers plugins, template_xmlui is used to manage remotes). This patch set class_map as a create argument, this way it can be set with partial, and several XMLUI managers can be instanced at the same time.
author Goffi <goffi@goffi.org>
date Fri, 31 Aug 2018 16:03:12 +0200
parents c274201cea94
children 5c2ed8a5ae22
line wrap: on
line diff
--- a/sat_frontends/tools/xmlui.py	Fri Aug 31 15:57:11 2018 +0200
+++ b/sat_frontends/tools/xmlui.py	Fri Aug 31 16:03:12 2018 +0200
@@ -25,7 +25,7 @@
 from sat.core import exceptions
 
 
-class_map = {}
+_class_map = {}
 CLASS_PANEL = "panel"
 CLASS_DIALOG = "dialog"
 CURRENT_LABEL = "current_label"
@@ -986,22 +986,22 @@
         CLASS_DIALOG: XMLUI dialog
     @param class_: the class to use to instanciate given type
     """
+    # TODO: remove this method, as there are seme use cases where different XMLUI
+    #       classes can be used in the same frontend, so a global value is not good
     assert type_ in (CLASS_PANEL, CLASS_DIALOG)
-    class_map[type_] = class_
+    log.warning(u"registerClass for XMLUI is deprecated, please use partial with "
+                u"xmlui.create and class_map instead")
+    if type_ in _class_map:
+        log.debug(_(u"XMLUI class already registered for {type_}, ignoring").format(
+            type_=type_))
+        return
+
+    _class_map[type_] = class_
 
 
-def create(
-    host,
-    xml_data,
-    title=None,
-    flags=None,
-    dom_parse=None,
-    dom_free=None,
-    callback=None,
-    ignore=None,
-    whitelist=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, whitelist=None, class_map=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
@@ -1011,6 +1011,8 @@
             when not None, only widgets in this list and their label will be kept
             mutually exclusive with ignore
     """
+    if class_map is None:
+        class_map = _class_map
     if dom_parse is None:
         from xml.dom import minidom