diff sat_frontends/jp/xmlui_manager.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 56f94936df1e
children e8dc00f612fb
line wrap: on
line diff
--- a/sat_frontends/jp/xmlui_manager.py	Fri Aug 31 15:57:11 2018 +0200
+++ b/sat_frontends/jp/xmlui_manager.py	Fri Aug 31 16:03:12 2018 +0200
@@ -20,7 +20,7 @@
 from sat.core.log import getLogger
 
 log = getLogger(__name__)
-from sat_frontends.tools import xmlui as xmlui_manager
+from sat_frontends.tools import xmlui as xmlui_base
 from sat_frontends.jp.constants import Const as C
 from sat.tools.common.ansi import ANSI as A
 from sat.core.i18n import _
@@ -50,7 +50,7 @@
         if self._root is not None:
             return self._root
         root = self
-        while not isinstance(root, xmlui_manager.XMLUIBase):
+        while not isinstance(root, xmlui_base.XMLUIBase):
             root = root.xmlui_parent
         self._root = root
         return root
@@ -173,19 +173,19 @@
         return u"noselect" in self.style
 
 
-class EmptyWidget(xmlui_manager.EmptyWidget, Widget):
+class EmptyWidget(xmlui_base.EmptyWidget, Widget):
     def __init__(self, _xmlui_parent):
         Widget.__init__(self)
 
 
-class TextWidget(xmlui_manager.TextWidget, ValueWidget):
+class TextWidget(xmlui_base.TextWidget, ValueWidget):
     type = u"text"
 
     def show(self):
         self.host.disp(self.value)
 
 
-class LabelWidget(xmlui_manager.LabelWidget, ValueWidget):
+class LabelWidget(xmlui_base.LabelWidget, ValueWidget):
     type = u"label"
 
     @property
@@ -204,7 +204,7 @@
         self.disp(A.color(ansi, self.value), no_lf=no_lf)
 
 
-class StringWidget(xmlui_manager.StringWidget, InputWidget):
+class StringWidget(xmlui_base.StringWidget, InputWidget):
     type = u"string"
 
     def show(self):
@@ -223,15 +223,15 @@
                 self.value = value
 
 
-class JidInputWidget(xmlui_manager.JidInputWidget, StringWidget):
+class JidInputWidget(xmlui_base.JidInputWidget, StringWidget):
     type = u"jid_input"
 
 
-class TextBoxWidget(xmlui_manager.TextWidget, StringWidget):
+class TextBoxWidget(xmlui_base.TextWidget, StringWidget):
     type = u"textbox"
 
 
-class ListWidget(xmlui_manager.ListWidget, OptionsWidget):
+class ListWidget(xmlui_base.ListWidget, OptionsWidget):
     type = u"list"
     # TODO: handle flags, notably multi
 
@@ -277,7 +277,7 @@
         self.disp("")
 
 
-class BoolWidget(xmlui_manager.BoolWidget, InputWidget):
+class BoolWidget(xmlui_base.BoolWidget, InputWidget):
     type = u"bool"
 
     def show(self):
@@ -324,15 +324,15 @@
             child.show()
 
 
-class VerticalContainer(xmlui_manager.VerticalContainer, Container):
+class VerticalContainer(xmlui_base.VerticalContainer, Container):
     type = u"vertical"
 
 
-class PairsContainer(xmlui_manager.PairsContainer, Container):
+class PairsContainer(xmlui_base.PairsContainer, Container):
     type = u"pairs"
 
 
-class LabelContainer(xmlui_manager.PairsContainer, Container):
+class LabelContainer(xmlui_base.PairsContainer, Container):
     type = u"label"
 
     def show(self):
@@ -377,14 +377,14 @@
         raise NotImplementedError(self.__class__)
 
 
-class NoteDialog(xmlui_manager.NoteDialog, Dialog):
+class NoteDialog(xmlui_base.NoteDialog, Dialog):
     def show(self):
         # TODO: handle title and level
         self.disp(self.message)
 
     def __init__(self, _xmlui_parent, title, message, level):
         Dialog.__init__(self, _xmlui_parent)
-        xmlui_manager.NoteDialog.__init__(self, _xmlui_parent)
+        xmlui_base.NoteDialog.__init__(self, _xmlui_parent)
         self.title, self.message, self.level = title, message, level
 
 
@@ -398,7 +398,7 @@
             return cls
 
 
-class XMLUIPanel(xmlui_manager.XMLUIPanel):
+class XMLUIPanel(xmlui_base.XMLUIPanel):
     widget_factory = WidgetFactory()
     _actions = 0  # use to keep track of bridge's launchAction calls
     read_only = False
@@ -406,18 +406,9 @@
     workflow = None
     _submit_cb = None
 
-    def __init__(
-        self,
-        host,
-        parsed_dom,
-        title=None,
-        flags=None,
-        callback=None,
-        ignore=None,
-        whitelist=None,
-        profile=None,
-    ):
-        xmlui_manager.XMLUIPanel.__init__(
+    def __init__(self, host, parsed_dom, title=None, flags=None, callback=None,
+                 ignore=None, whitelist=None, profile=None):
+        xmlui_base.XMLUIPanel.__init__(
             self,
             host,
             parsed_dom,
@@ -500,7 +491,7 @@
         assert XMLUIPanel._actions >= 0
         if u"xmlui" in data:
             xmlui_raw = data["xmlui"]
-            xmlui = xmlui_manager.create(self.host, xmlui_raw)
+            xmlui = create(self.host, xmlui_raw)
             xmlui.show()
             if xmlui.submit_id:
                 xmlui.onFormSubmitted()
@@ -526,7 +517,7 @@
         )
 
 
-class XMLUIDialog(xmlui_manager.XMLUIDialog):
+class XMLUIDialog(xmlui_base.XMLUIDialog):
     type = "dialog"
     dialog_factory = WidgetFactory()
     read_only = False
@@ -538,6 +529,6 @@
         pass
 
 
-xmlui_manager.registerClass(xmlui_manager.CLASS_PANEL, XMLUIPanel)
-xmlui_manager.registerClass(xmlui_manager.CLASS_DIALOG, XMLUIDialog)
-create = xmlui_manager.create
+create = partial(xmlui_base.create, class_map={
+    xmlui_base.CLASS_PANEL: XMLUIPanel,
+    xmlui_base.CLASS_DIALOG: XMLUIDialog})