Mercurial > libervia-web
diff src/browser/libervia_main.py @ 676:849ffb24d5bf frontends_multi_profiles
browser side: menus refactorisation:
- use of the new quick_frontends.quick_menus module, resulting in a big code simplification in Libervia
- menu are added in there respective modules: main menus are done directely in libervia_main, while tarot and radiocol menus are done in game_tarot and game_radiocol
- launchAction has the same signature as in QuickApp
- base_menu: there are now 2 classes to launch an action: MenuCmd which manage quick_menus classes, and SimpleCmd to launch a generic callback
- base_menu: MenuNode has been removed as logic is now in quick_menus
- base_menu: GenericMenuBar.update method can be called to fully (re)build the menus
- base_widget: removed WidgetSubMenuBar which is no more useful (GenericMenuBar do the same thing)
- plugin_menu_context is used in LiberviaWidget and other classes with menus to indicate which menu types must be used
- otr menus hooks are temporarily removed, will be fixed soon
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 17 Mar 2015 20:42:02 +0100 |
parents | 941e53b3af5c |
children | a90cc8fc9605 |
line wrap: on
line diff
--- a/src/browser/libervia_main.py Tue Mar 17 20:28:41 2015 +0100 +++ b/src/browser/libervia_main.py Tue Mar 17 20:42:02 2015 +0100 @@ -25,8 +25,11 @@ log = getLogger(__name__) ### +from sat.core.i18n import D_ + from sat_frontends.quick_frontend.quick_app import QuickApp from sat_frontends.quick_frontend import quick_widgets +from sat_frontends.quick_frontend import quick_menus from sat_frontends.tools.misc import InputHistory from sat_frontends.tools import strings @@ -73,7 +76,7 @@ # the existing widget will be eventually removed from its parent # and added to new libervia_widget.WidgetsPanel, or replaced to the expected # position if the previous and the new parent are the same. -REUSE_EXISTING_LIBERVIA_WIDGETS = True +# REUSE_EXISTING_LIBERVIA_WIDGETS = True # FIXME class SatWebFrontend(InputHistory, QuickApp): @@ -250,16 +253,46 @@ def displayNotification(self, title, body): self.notification.notify(title, body) - def gotMenus(self, menus): + def gotMenus(self, backend_menus): """Put the menus data in cache and build the main menu bar - @param menus (list[tuple]): menu data + @param backend_menus (list[tuple]): menu data from backend """ - self.callListeners('gotMenus', menus) # FIXME: to be done another way or moved to quick_app - self.menus = {} - for id_, type_, path, path_i18n in menus: - self.menus.setdefault(type_, []).append((id_, path, path_i18n)) - self.panel.menu.createMenus() + main_menu = self.panel.menu # most of global menu callbacks are in main_menu + + # Categories (with icons) + self.menus.addCategory(C.MENU_GLOBAL, [D_(u"General")], extra={'icon': 'home'}) + self.menus.addCategory(C.MENU_GLOBAL, [D_(u"Contacts")], extra={'icon': 'social'}) + self.menus.addCategory(C.MENU_GLOBAL, [D_(u"Groups")], extra={'icon': 'social'}) + self.menus.addCategory(C.MENU_GLOBAL, [D_(u"Games")], extra={'icon': 'games'}) + + # menus to have before backend menus + self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Groups"), D_(u"Discussion")), callback=main_menu.onJoinRoom) + + # menus added by the backend/plugins (include other types than C.MENU_GLOBAL) + self.menus.addMenus(backend_menus, top_extra={'icon': 'plugins'}) + + # menus to have under backend menus + self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Contacts"), D_(u"Manage groups")), callback=main_menu.onManageContactGroups) + + # separator and right hand menus + self.menus.addMenuItem(C.MENU_GLOBAL, [], quick_menus.MenuSeparator()) + + self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Help"), D_("Social contract")), top_extra={'icon': 'help'}, callback=main_menu.onSocialContract) + self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Help"), D_("About")), callback=main_menu.onAbout) + self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Settings"), D_("Account")), top_extra={'icon': 'settings'}, callback=main_menu.onAccount) + self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Settings"), D_("Parameters")), callback=main_menu.onParameters) + # XXX: temporary, will change when a full profile will be managed in SàT + self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Settings"), D_("Upload avatar")), callback=main_menu.onAvatarUpload) + + # we call listener to have menu added by local classes/plugins + self.callListeners('gotMenus') # FIXME: to be done another way or moved to quick_app + + # and finally the menus which must appear at the bottom + self.menus.addMenu(C.MENU_GLOBAL, (D_(u"General"), D_(u"Disconnect")), callback=main_menu.onDisconnect) + + # we can now display all the menus + main_menu.update(C.MENU_GLOBAL) def _isRegisteredCB(self, result): registered, warning = result @@ -412,7 +445,7 @@ dialog.InfoDialog("Error", unicode(err_obj), Width="400px").center() - def launchAction(self, callback_id, data): + def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE): """ Launch a dynamic action @param callback_id: id of the action to launch @param data: data needed only for certain actions @@ -420,7 +453,7 @@ """ if data is None: data = {} - self.bridge.launchAction(callback_id, data, profile=C.PROF_KEY_NONE, callback=self._actionCb, errback=self._actionEb) + self.bridge.launchAction(callback_id, data, profile=profile, callback=self._actionCb, errback=self._actionEb) def _getContactsCB(self, contacts_data): for contact_ in contacts_data: