Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
675:941e53b3af5c | 676:849ffb24d5bf |
---|---|
23 logging.configure() | 23 logging.configure() |
24 from sat.core.log import getLogger | 24 from sat.core.log import getLogger |
25 log = getLogger(__name__) | 25 log = getLogger(__name__) |
26 ### | 26 ### |
27 | 27 |
28 from sat.core.i18n import D_ | |
29 | |
28 from sat_frontends.quick_frontend.quick_app import QuickApp | 30 from sat_frontends.quick_frontend.quick_app import QuickApp |
29 from sat_frontends.quick_frontend import quick_widgets | 31 from sat_frontends.quick_frontend import quick_widgets |
32 from sat_frontends.quick_frontend import quick_menus | |
30 | 33 |
31 from sat_frontends.tools.misc import InputHistory | 34 from sat_frontends.tools.misc import InputHistory |
32 from sat_frontends.tools import strings | 35 from sat_frontends.tools import strings |
33 from sat_frontends.tools import jid | 36 from sat_frontends.tools import jid |
34 from sat_frontends.tools import host_listener | 37 from sat_frontends.tools import host_listener |
71 # Set to true to not create a new LiberviaWidget when a similar one | 74 # Set to true to not create a new LiberviaWidget when a similar one |
72 # already exist (i.e. a chat panel with the same target). Instead | 75 # already exist (i.e. a chat panel with the same target). Instead |
73 # the existing widget will be eventually removed from its parent | 76 # the existing widget will be eventually removed from its parent |
74 # and added to new libervia_widget.WidgetsPanel, or replaced to the expected | 77 # and added to new libervia_widget.WidgetsPanel, or replaced to the expected |
75 # position if the previous and the new parent are the same. | 78 # position if the previous and the new parent are the same. |
76 REUSE_EXISTING_LIBERVIA_WIDGETS = True | 79 # REUSE_EXISTING_LIBERVIA_WIDGETS = True # FIXME |
77 | 80 |
78 | 81 |
79 class SatWebFrontend(InputHistory, QuickApp): | 82 class SatWebFrontend(InputHistory, QuickApp): |
80 def onModuleLoad(self): | 83 def onModuleLoad(self): |
81 log.info("============ onModuleLoad ==============") | 84 log.info("============ onModuleLoad ==============") |
248 panel.addWidget(wid) | 251 panel.addWidget(wid) |
249 | 252 |
250 def displayNotification(self, title, body): | 253 def displayNotification(self, title, body): |
251 self.notification.notify(title, body) | 254 self.notification.notify(title, body) |
252 | 255 |
253 def gotMenus(self, menus): | 256 def gotMenus(self, backend_menus): |
254 """Put the menus data in cache and build the main menu bar | 257 """Put the menus data in cache and build the main menu bar |
255 | 258 |
256 @param menus (list[tuple]): menu data | 259 @param backend_menus (list[tuple]): menu data from backend |
257 """ | 260 """ |
258 self.callListeners('gotMenus', menus) # FIXME: to be done another way or moved to quick_app | 261 main_menu = self.panel.menu # most of global menu callbacks are in main_menu |
259 self.menus = {} | 262 |
260 for id_, type_, path, path_i18n in menus: | 263 # Categories (with icons) |
261 self.menus.setdefault(type_, []).append((id_, path, path_i18n)) | 264 self.menus.addCategory(C.MENU_GLOBAL, [D_(u"General")], extra={'icon': 'home'}) |
262 self.panel.menu.createMenus() | 265 self.menus.addCategory(C.MENU_GLOBAL, [D_(u"Contacts")], extra={'icon': 'social'}) |
266 self.menus.addCategory(C.MENU_GLOBAL, [D_(u"Groups")], extra={'icon': 'social'}) | |
267 self.menus.addCategory(C.MENU_GLOBAL, [D_(u"Games")], extra={'icon': 'games'}) | |
268 | |
269 # menus to have before backend menus | |
270 self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Groups"), D_(u"Discussion")), callback=main_menu.onJoinRoom) | |
271 | |
272 # menus added by the backend/plugins (include other types than C.MENU_GLOBAL) | |
273 self.menus.addMenus(backend_menus, top_extra={'icon': 'plugins'}) | |
274 | |
275 # menus to have under backend menus | |
276 self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Contacts"), D_(u"Manage groups")), callback=main_menu.onManageContactGroups) | |
277 | |
278 # separator and right hand menus | |
279 self.menus.addMenuItem(C.MENU_GLOBAL, [], quick_menus.MenuSeparator()) | |
280 | |
281 self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Help"), D_("Social contract")), top_extra={'icon': 'help'}, callback=main_menu.onSocialContract) | |
282 self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Help"), D_("About")), callback=main_menu.onAbout) | |
283 self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Settings"), D_("Account")), top_extra={'icon': 'settings'}, callback=main_menu.onAccount) | |
284 self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Settings"), D_("Parameters")), callback=main_menu.onParameters) | |
285 # XXX: temporary, will change when a full profile will be managed in SàT | |
286 self.menus.addMenu(C.MENU_GLOBAL, (D_(u"Settings"), D_("Upload avatar")), callback=main_menu.onAvatarUpload) | |
287 | |
288 # we call listener to have menu added by local classes/plugins | |
289 self.callListeners('gotMenus') # FIXME: to be done another way or moved to quick_app | |
290 | |
291 # and finally the menus which must appear at the bottom | |
292 self.menus.addMenu(C.MENU_GLOBAL, (D_(u"General"), D_(u"Disconnect")), callback=main_menu.onDisconnect) | |
293 | |
294 # we can now display all the menus | |
295 main_menu.update(C.MENU_GLOBAL) | |
263 | 296 |
264 def _isRegisteredCB(self, result): | 297 def _isRegisteredCB(self, result): |
265 registered, warning = result | 298 registered, warning = result |
266 if not registered: | 299 if not registered: |
267 self._register_box = register.RegisterBox(self.logged) | 300 self._register_box = register.RegisterBox(self.logged) |
410 def _actionEb(self, err_data): | 443 def _actionEb(self, err_data): |
411 err_code, err_obj = err_data | 444 err_code, err_obj = err_data |
412 dialog.InfoDialog("Error", | 445 dialog.InfoDialog("Error", |
413 unicode(err_obj), Width="400px").center() | 446 unicode(err_obj), Width="400px").center() |
414 | 447 |
415 def launchAction(self, callback_id, data): | 448 def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE): |
416 """ Launch a dynamic action | 449 """ Launch a dynamic action |
417 @param callback_id: id of the action to launch | 450 @param callback_id: id of the action to launch |
418 @param data: data needed only for certain actions | 451 @param data: data needed only for certain actions |
419 | 452 |
420 """ | 453 """ |
421 if data is None: | 454 if data is None: |
422 data = {} | 455 data = {} |
423 self.bridge.launchAction(callback_id, data, profile=C.PROF_KEY_NONE, callback=self._actionCb, errback=self._actionEb) | 456 self.bridge.launchAction(callback_id, data, profile=profile, callback=self._actionCb, errback=self._actionEb) |
424 | 457 |
425 def _getContactsCB(self, contacts_data): | 458 def _getContactsCB(self, contacts_data): |
426 for contact_ in contacts_data: | 459 for contact_ in contacts_data: |
427 jid, attributes, groups = contact_ | 460 jid, attributes, groups = contact_ |
428 self._newContactCb(jid, attributes, groups) | 461 self._newContactCb(jid, attributes, groups) |