diff frontends/src/tools/xmlui.py @ 1265:e3a9ea76de35 frontends_multi_profiles

quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p): This refactoring allow primitivus to manage correctly several profiles at once, with various other improvments: - profile_manager can now plug several profiles at once, requesting password when needed. No more profile plug specific method is used anymore in backend, instead a "validated" key is used in actions - Primitivus widget are now based on a common "PrimitivusWidget" classe which mainly manage the decoration so far - all widgets are treated in the same way (contactList, Chat, Progress, etc), no more chat_wins specific behaviour - widgets are created in a dedicated manager, with facilities to react on new widget creation or other events - quick_frontend introduce a new QuickWidget class, which aims to be as generic and flexible as possible. It can manage several targets (jids or something else), and several profiles - each widget class return a Hash according to its target. For example if given a target jid and a profile, a widget class return a hash like (target.bare, profile), the same widget will be used for all resources of the same jid - better management of CHAT_GROUP mode for Chat widgets - some code moved from Primitivus to QuickFrontend, the final goal is to have most non backend code in QuickFrontend, and just graphic code in subclasses - no more (un)escapePrivate/PRIVATE_PREFIX - contactList improved a lot: entities not in roster and special entities (private MUC conversations) are better managed - resources can be displayed in Primitivus, and their status messages - profiles are managed in QuickFrontend with dedicated managers This is work in progress, other frontends are broken. Urwid SàText need to be updated. Most of features of Primitivus should work as before (or in a better way ;))
author Goffi <goffi@goffi.org>
date Wed, 10 Dec 2014 19:00:09 +0100
parents f91e7028e2c3
children faa1129559b8
line wrap: on
line diff
--- a/frontends/src/tools/xmlui.py	Wed Dec 10 18:37:14 2014 +0100
+++ b/frontends/src/tools/xmlui.py	Wed Dec 10 19:00:09 2014 +0100
@@ -202,7 +202,7 @@
     This class must not be instancied directly
     """
 
-    def __init__(self, host, parsed_dom, title = None, flags = None):
+    def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
         """Initialise the XMLUI instance
 
         @param host: %(doc_host)s
@@ -210,15 +210,18 @@
         @param title: force the title, or use XMLUI one if None
         @param flags: list of string which can be:
             - NO_CANCEL: the UI can't be cancelled
+        @param callback: if present, will be use with launchAction
         """
         self.host = host
         top=parsed_dom.documentElement
         self.session_id = top.getAttribute("session_id") or None
         self.submit_id = top.getAttribute("submit") or None
-        self.title = title or top.getAttribute("title") or u""
+        self.xmlui_title = title or top.getAttribute("title") or u""
         if flags is None:
             flags = []
         self.flags = flags
+        self.callback = callback
+        self.profile = profile
 
     def _isAttrSet(self, name, node):
         """Returnw widget boolean attribute status
@@ -253,7 +256,7 @@
         self._xmluiLaunchAction(self.submit_id, data)
 
     def _xmluiLaunchAction(self, action_id, data):
-        self.host.launchAction(action_id, data, profile_key = self.host.profile)
+        self.host.launchAction(action_id, data, callback=self.callback, profile=self.profile)
 
 
 class XMLUIPanel(XMLUIBase):
@@ -265,8 +268,8 @@
     """
     widget_factory = None
 
-    def __init__(self, host, parsed_dom, title = None, flags = None):
-        super(XMLUIPanel, self).__init__(host, parsed_dom, title = None, flags = None)
+    def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
+        super(XMLUIPanel, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile)
         self.ctrl_list = {}  # usefull to access ctrl
         self._main_cont = None
         self.constructUI(parsed_dom)
@@ -462,7 +465,7 @@
         raise NotImplementedError
 
     def _xmluiSetParam(self, name, value, category):
-        self.host.bridge.setParam(name, value, category, profile_key=self.host.profile)
+        self.host.bridge.setParam(name, value, category, profile=self.profile)
 
     ##EVENTS##
 
@@ -639,8 +642,8 @@
 class XMLUIDialog(XMLUIBase):
     dialog_factory = None
 
-    def __init__(self, host, parsed_dom, title = None, flags = None):
-        super(XMLUIDialog, self).__init__(host, parsed_dom, title = None, flags = None)
+    def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
+        super(XMLUIDialog, self).__init__(host, parsed_dom, title=None, flags=None, callback=callback, profile=C.PROF_KEY_NONE)
         top=parsed_dom.documentElement
         dlg_elt =  self._getChildNode(top, "dialog")
         if dlg_elt is None:
@@ -654,23 +657,23 @@
         level = dlg_elt.getAttribute(C.XMLUI_DATA_LVL) or C.XMLUI_DATA_LVL_INFO
 
         if dlg_type == C.XMLUI_DIALOG_MESSAGE:
-            self.dlg = self.dialog_factory.createMessageDialog(self, self.title, message, level)
+            self.dlg = self.dialog_factory.createMessageDialog(self, self.xmlui_title, message, level)
         elif dlg_type == C.XMLUI_DIALOG_NOTE:
-            self.dlg = self.dialog_factory.createNoteDialog(self, self.title, message, level)
+            self.dlg = self.dialog_factory.createNoteDialog(self, self.xmlui_title, message, level)
         elif dlg_type == C.XMLUI_DIALOG_CONFIRM:
             try:
                 buttons_elt = self._getChildNode(dlg_elt, "buttons")
                 buttons_set = buttons_elt.getAttribute("set") or C.XMLUI_DATA_BTNS_SET_DEFAULT
             except (TypeError, AttributeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
                 buttons_set = C.XMLUI_DATA_BTNS_SET_DEFAULT
-            self.dlg = self.dialog_factory.createConfirmDialog(self, self.title, message, level, buttons_set)
+            self.dlg = self.dialog_factory.createConfirmDialog(self, self.xmlui_title, message, level, buttons_set)
         elif dlg_type == C.XMLUI_DIALOG_FILE:
             try:
                 file_elt = self._getChildNode(dlg_elt, "file")
                 filetype = file_elt.getAttribute("type") or C.XMLUI_DATA_FILETYPE_DEFAULT
             except (TypeError, AttributeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
                 filetype = C.XMLUI_DATA_FILETYPE_DEFAULT
-            self.dlg = self.dialog_factory.createFileDialog(self, self.title, message, level, filetype)
+            self.dlg = self.dialog_factory.createFileDialog(self, self.xmlui_title, message, level, filetype)
         else:
             raise ValueError("Unknown dialog type [%s]" % dlg_type)
 
@@ -690,7 +693,7 @@
     class_map[type_] = class_
 
 
-def create(host, xml_data, title = None, flags = None, dom_parse=None, dom_free=None):
+def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None, callback=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
@@ -713,6 +716,6 @@
     except KeyError:
         raise ClassNotRegistedError(_("You must register classes with registerClass before creating a XMLUI"))
 
-    xmlui = cls(host, parsed_dom, title, flags)
+    xmlui = cls(host, parsed_dom, title, flags, callback, profile)
     dom_free(parsed_dom)
     return xmlui