diff frontends/src/primitivus/primitivus @ 1093:11e2bb20e896

core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
author Goffi <goffi@goffi.org>
date Thu, 26 Jun 2014 00:05:20 +0200
parents 6ec513ad92c2
children a096b8579a3c
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus	Wed Jun 25 20:54:15 2014 +0200
+++ b/frontends/src/primitivus/primitivus	Thu Jun 26 00:05:20 2014 +0200
@@ -282,6 +282,22 @@
         except AttributeError:
             return input
 
+    def addMenus(self, menu, type_, menu_data=None):
+        """Add cached menus to instance
+        @param menu: sat_widgets.Menu instance
+        @param type_: menu type like is sat.core.sat_main.importMenu
+        @param menu_data: data to send with these menus
+
+        """
+        menus = self.profiles[self.profile]['menus'].get(type_,[])
+        def add_menu_cb(callback_id):
+            self.launchAction(callback_id, menu_data, profile_key = self.profile)
+        for id_, path, path_i18n  in menus:
+            if len(path) != 2:
+                raise NotImplementedError("Menu with a path != 2 are not implemented yet")
+            menu.addMenu(path_i18n[0], path_i18n[1], lambda dummy,id_=id_: add_menu_cb(id_))
+
+
     def _buildMenuRoller(self):
         menu = sat_widgets.Menu(self.loop)
         general = _("General")
@@ -296,14 +312,7 @@
         menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
         #additionals menus
         #FIXME: do this in a more generic way (in quickapp)
-        add_menus = self.bridge.getMenus('', C.NO_SECURITY_LIMIT)
-        def add_menu_cb(callback_id):
-            self.launchAction(callback_id, None, profile_key = self.profile)
-        for id_, type_, path, path_i18n  in add_menus:
-            assert(type_=="NORMAL") #TODO: manage other types
-            if len(path) != 2:
-                raise NotImplementedError("Menu with a path != 2 are not implemented yet")
-            menu.addMenu(path_i18n[0], path_i18n[1], lambda menu,id_=id_: add_menu_cb(id_))
+        self.addMenus(menu, C.MENU_GLOBAL)
 
         menu_roller = sat_widgets.MenuRoller([(_('Main menu'),menu)])
         return menu_roller