diff frontends/wix/main_window.py @ 101:783e9d6980ec

Couchsurfing plugin: first draft SàT core: adding additionnal menu method bridge: new methods getMenus, getMenuHelp and callMenu wix: new menu are added on startup CS plugin: login on CS
author Goffi <goffi@goffi.org>
date Sat, 19 Jun 2010 17:15:30 +0800
parents 39c672544593
children 94011f553cd0
line wrap: on
line diff
--- a/frontends/wix/main_window.py	Fri Jun 18 17:14:14 2010 +0800
+++ b/frontends/wix/main_window.py	Sat Jun 19 17:15:30 2010 +0800
@@ -76,9 +76,6 @@
         
         self.chat_wins=ChatList(self)
         self.CreateStatusBar()
-        self.createMenus()
-        for i in range(self.menuBar.GetMenuCount()):
-            self.menuBar.EnableTop(i, False)
 
         #ToolBar
         self.tools=self.CreateToolBar()
@@ -105,6 +102,11 @@
         QuickApp.__init__(self)
         #self.plug_profile() #gof:
         
+        #menus
+        self.createMenus()
+        for i in range(self.menuBar.GetMenuCount()):
+            self.menuBar.EnableTop(i, False)
+        
         #profile panel
         self.profile_pan = ProfileManager(self) 
         #self.profile_pan.Hide()  #gof:
@@ -149,6 +151,31 @@
         self.menuBar.Append(communicationMenu,_("&Communication"))
         self.SetMenuBar(self.menuBar)
 
+        #additionals menus
+        #FIXME: do this in a more generic way (in quickapp)
+        add_menus = self.bridge.getMenus()
+        for menu in add_menus:
+            category,item,type = menu
+            assert(type=="NORMAL") #TODO: manage other types
+            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(category, item, type)
+            current_menu.Append(item_id, item, help = help_string)
+            #now we register the event
+            def event_answer(e):
+                id = self.bridge.callMenu(category, item, type)
+                self.current_action_ids.add(id)
+            wx.EVT_MENU(self, item_id, event_answer)
+
+
         #events
         wx.EVT_MENU(self, idCONNECT, self.onConnectRequest)
         wx.EVT_MENU(self, idDISCONNECT, self.onDisconnectRequest)