core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed

This commit is contained in:
Goffi 2014-06-26 00:05:20 +02:00
commit 08be0324a6

View file

@ -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 @@ class MainWindow(wx.Frame, QuickApp):
#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 @@ class MainWindow(wx.Frame, QuickApp):
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 @@ class MainWindow(wx.Frame, QuickApp):
#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()