diff frontends/src/primitivus/primitivus @ 759:93bd868b8fb6

backend, frontends: callbacks refactoring: - launchAction is now async, and return a dictionary for its result - no more action_id, actionResult* are deprecated - callback system is about to be unified
author Goffi <goffi@goffi.org>
date Tue, 24 Dec 2013 15:19:08 +0100
parents e3ad48a2aab2
children bfabeedbf32e
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus	Tue Dec 24 15:19:08 2013 +0100
+++ b/frontends/src/primitivus/primitivus	Tue Dec 24 15:19:08 2013 +0100
@@ -282,7 +282,6 @@
             return input
 
     def _dynamicMenuCb(self, xmlui):
-        misc = {}
         ui = XMLUI(self, xml_data = xmlui)
         ui.show('popup')
 
@@ -448,6 +447,29 @@
                 #No notification left, we can hide the bar
                 self.main_widget.footer = self.editBar
 
+    def launchAction(self, callback_id, data=None, profile_key="@NONE@"):
+        """ Launch a dynamic action
+        @param callback_id: id of the action to launch
+        @param data: data needed only for certain actions
+        @param profile_key: %(doc_profile_key)s
+
+        """
+        if data is None:
+            data = dict()
+        def action_cb(data):
+            if not data:
+                # action was a one shot, nothing to do
+                pass
+            elif "xmlui" in data:
+                ui = XMLUI(self, xml_data = data['xmlui'])
+                ui.show('popup')
+            else:
+                self.showPopUp(sat_widgets.Alert(_("Error"), _(u"Unmanaged action result"), ok_cb=self.removePopUp))
+        def action_eb(failure):
+            self.showPopUp(sat_widgets.Alert(_("Error"), unicode(failure), ok_cb=self.removePopUp))
+
+        self.bridge.launchAction(callback_id, data, profile_key, callback=action_cb, errback=action_eb)
+
     def askConfirmation(self, confirmation_id, confirmation_type, data, profile):
         if not self.check_profile(profile):
             return