diff frontends/src/quick_frontend/quick_app.py @ 2126:2f264f3df280

core (menus): improvments: - use the new convention for bridge names (getMenus ==> menusGet, etc.) - menu now use canonical path, which is the untranslated path with each element stripped and lowercase, it must be unique by menu type - added menuLaunch method to manually launch a menu like an action, canonical path is used instead of id - added SECURITY_LIMIT_MAX constant
author Goffi <goffi@goffi.org>
date Thu, 26 Jan 2017 20:29:48 +0100
parents c42aab22c2c0
children aa94f33fd2ad
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Thu Jan 26 20:24:58 2017 +0100
+++ b/frontends/src/quick_frontend/quick_app.py	Thu Jan 26 20:29:48 2017 +0100
@@ -857,8 +857,15 @@
         if action_data:
             raise exceptions.DataError(u"Not all keys in action_data are managed ({keys})".format(keys=', '.join(action_data.keys())))
 
+
+    def _actionCb(self, data, callback, callback_id, profile):
+        if callback is None:
+            self.actionManager(data, profile=profile)
+        else:
+            callback(data=data, cb_id=callback_id, profile=profile)
+
     def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE):
-        """ Launch a dynamic action
+        """Launch a dynamic action
 
         @param callback_id: id of the action to launch
         @param data: data needed only for certain actions
@@ -873,15 +880,28 @@
         """
         if data is None:
             data = dict()
+        action_cb = lambda data: self._actionCb(data, callback, callback_id, profile)
+        self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure)
 
+    def launchMenu(self, menu_type, path, data=None, callback=None, security_limit=C.SECURITY_LIMIT_MAX, profile=C.PROF_KEY_NONE):
+        """Launch a menu manually
 
-        def action_cb(data):
-            if callback is None:
-                self.actionManager(data, profile=profile)
-            else:
-                callback(data=data, cb_id=callback_id, profile=profile)
+        @param menu_type(unicode): type of the menu to launch
+        @param path(iterable[unicode]): path to the menu
+        @param data: data needed only for certain actions
+        @param callback(callable, None): will be called with the resut
+            if None, self.actionManager will be called
+            else the callable will be called with the following kw parameters:
+                - data: action_data
+                - cb_id: (menu_type, path) tuple
+                - profile: %(doc_profile)s
+        @param profile: %(doc_profile)s
 
-        self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure)
+        """
+        if data is None:
+            data = dict()
+        action_cb = lambda data: self._actionCb(data, callback, (menu_type, path), profile)
+        self.bridge.menuLaunch(menu_type, path, data, security_limit, profile, callback=action_cb, errback=self.dialogFailure)
 
     def _avatarGetCb(self, avatar_path, entity, contact_list, profile):
         path = avatar_path or self.getDefaultAvatar(entity)