diff frontends/src/wix/main_window.py @ 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/wix/main_window.py	Wed Jun 25 20:54:15 2014 +0200
+++ b/frontends/src/wix/main_window.py	Thu Jun 26 00:05:20 2014 +0200
@@ -19,6 +19,7 @@
 
 
 from sat.core.i18n import _
+from sat_frontends.wix.constants import Const as C
 from sat_frontends.quick_frontend.quick_chat_list import QuickChatList
 from sat_frontends.quick_frontend.quick_app import QuickApp
 import wx
@@ -90,10 +91,6 @@
         #events
         self.Bind(wx.EVT_CLOSE, self.onClose, self)
 
-        #menus
-        self.createMenus()
-        for i in range(self.menuBar.GetMenuCount()):
-            self.menuBar.EnableTop(i, False)
 
         #profile panel
         self.profile_pan = ProfileManager(self)
@@ -109,9 +106,40 @@
         self.profile_pan.Hide()
         self.contact_list.Show()
         self.sizer.Layout()
-        for i in range(self.menuBar.GetMenuCount()):
-            self.menuBar.EnableTop(i, True)
         super(MainWindow, self).plug_profile_1(profile_key)
+        #menus
+        self.createMenus()
+
+    def addMenus(self, menubar, type_, menu_data=None):
+        """Add cached menus to instance
+        @param menu: wx.MenuBar 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_,[])
+        for id_, path, path_i18n  in menus:
+            if len(path) != 2:
+                raise NotImplementedError("Menu with a path != 2 are not implemented yet")
+            category = path_i18n[0] # TODO: manage path with more than 2 levels
+            name = path_i18n[1]
+            menu_idx = menubar.FindMenu(category)
+            current_menu = None
+            if menu_idx == wx.NOT_FOUND:
+                #the menu is new, we create it
+                current_menu = wx.Menu()
+                menubar.Append(current_menu, category)
+            else:
+                current_menu = menubar.GetMenu(menu_idx)
+            assert(current_menu != None)
+            item_id = wx.NewId()
+            help_string = self.bridge.getMenuHelp(id_, '')
+            current_menu.Append(item_id, name, help=help_string)
+            #now we register the event
+            def event_answer(e, id_=id_):
+                self.launchAction(id_, menu_data, profile_key = self.profile)
+
+            wx.EVT_MENU(menubar.Parent, item_id, event_answer)
 
     def createMenus(self):
         log.info(_("Creating menus"))
@@ -133,30 +161,7 @@
 
         #additionals menus
         #FIXME: do this in a more generic way (in quickapp)
-        add_menus = self.bridge.getMenus('', Const.NO_SECURITY_LIMIT)
-        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")
-            category = path_i18n[0] # TODO: manage path with more than 2 levels
-            name = path_i18n[1]
-            menu_idx = self.menuBar.FindMenu(category)
-            current_menu = None
-            if menu_idx == wx.NOT_FOUND:
-                #the menu is new, we create it
-                current_menu = wx.Menu()
-                self.menuBar.Append(current_menu, category)
-            else:
-                current_menu = self.menuBar.GetMenu(menu_idx)
-            assert(current_menu != None)
-            item_id = wx.NewId()
-            help_string = self.bridge.getMenuHelp(id_, '')
-            current_menu.Append(item_id, name, help=help_string)
-            #now we register the event
-            def event_answer(e, id_=id_):
-                self.launchAction(id_, None, profile_key = self.profile)
-
-            wx.EVT_MENU(self, item_id, event_answer)
+        self.addMenus(self.menuBar, C.MENU_GLOBAL)
 
         # menu items that should be displayed after the automatically added ones
         contactMenu.AppendSeparator()