diff frontends/src/tools/xmlui.py @ 1489:039d96e131be

frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present): - actionManager is used by default (no callback provided) - in XMLUI, the dialog is closed before calling actionManager - if keys are not managed in resuling data, an exceptions is raised
author Goffi <goffi@goffi.org>
date Tue, 25 Aug 2015 14:41:42 +0200
parents a77217511afd
children cb1b0fe10415
line wrap: on
line diff
--- a/frontends/src/tools/xmlui.py	Tue Aug 25 14:22:21 2015 +0200
+++ b/frontends/src/tools/xmlui.py	Tue Aug 25 14:41:42 2015 +0200
@@ -237,7 +237,10 @@
         @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 used with launchAction
+        @param callback(callable, None): if not None, will be used with launchAction:
+            - if None is used, default behaviour will be used (closing the dialog and calling host.actionManager)
+            - if a callback is provided, it will be used instead, so you'll have to manage
+                dialog closing or new xmlui to display, or other action (you can call host.actionManager)
         """
         self.host = host
         top=parsed_dom.documentElement
@@ -247,9 +250,15 @@
         if flags is None:
             flags = []
         self.flags = flags
-        self.callback = callback
+        self.callback = callback or self._defaultCb
         self.profile = profile
 
+    def _defaultCb(self, data, cb_id, profile):
+        # TODO: when XMLUI updates will be managed, the _xmluiClose
+        #       must be called only if there is not update
+        self._xmluiClose()
+        self.host.actionManager(data, profile=profile)
+
     def _isAttrSet(self, name, node):
         """Returnw widget boolean attribute status
 
@@ -285,6 +294,13 @@
     def _xmluiLaunchAction(self, action_id, data):
         self.host.launchAction(action_id, data, callback=self.callback, profile=self.profile)
 
+    def _xmluiClose(self):
+        """Close the window/popup/... where the constructeur XMLUI is
+
+        this method must be overrided
+        """
+        raise NotImplementedError
+
 
 class XMLUIPanel(XMLUIBase):
     """XMLUI Panel
@@ -493,13 +509,6 @@
         if post_treat is not None:
             post_treat()
 
-    def _xmluiClose(self):
-        """Close the window/popup/... where the constructeur XMLUI is
-
-        this method must be overrided
-        """
-        raise NotImplementedError
-
     def _xmluiSetParam(self, name, value, category):
         self.host.bridge.setParam(name, value, category, profile_key=self.profile)