Mercurial > libervia-backend
diff frontends/src/primitivus/primitivus @ 773:eac23b1aad90
core: dynamics menus refactoring:
- menu now use generic callback system, with extra data
- asyncMenuCall is removed in favor of launchAction
- menu_id (== callback_id) is used to identify menu instead of category/name/type tuple
- i18n is managed throught deferred translation, and returned with _i18n suffix
e.g.: menu (D_('File'), D_('Open')): (u'File', u'Open') is menu_path, (u'Fichier', u'Ouvrir') is french menu_path_i18n.
- type actually can have the following values:
- NORMAL: classical menu
- JID_CONTEXT: contextual menu, used with any jid
- ROSTER_JID_CONTEXT: like JID_CONTEXT, but restricted to jids in roster.
- ROSTER_GROUP_CONTEXT: contextual menu, use with groups
- security_limit is used, in the same way as for parameters
- when using importMenu, callback can be an actual callback, or one already registered with registerCallback
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 29 Dec 2013 17:10:14 +0100 |
parents | bfabeedbf32e |
children | f89173f44850 |
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus Sun Dec 29 17:10:10 2013 +0100 +++ b/frontends/src/primitivus/primitivus Sun Dec 29 17:10:14 2013 +0100 @@ -282,13 +282,6 @@ except AttributeError: return input - def _dynamicMenuCb(self, xmlui): - ui = XMLUI(self, xml_data = xmlui) - ui.show('popup') - - def _dynamicMenuEb(self, failure): - self.showDialog(_(u"Error while calling menu"), type="error") - def _buildMenuRoller(self): menu = sat_widgets.Menu(self.loop) general = _("General") @@ -306,14 +299,14 @@ menu.addMenu(communication, _("Search directory"), self.onSearchDirectory) #additionals menus #FIXME: do this in a more generic way (in quickapp) - add_menus = self.bridge.getMenus() - def add_menu_cb(menu): - category, name = menu - self.bridge.asyncCallMenu(category, name, Const.MENU_NORMAL, self.profile, callback=self._dynamicMenuCb, errback=self._dynamicMenuEb) - for new_menu in add_menus: - type_, category, name = new_menu + add_menus = self.bridge.getMenus('', Const.NO_SECURITY_LIMIT) + def add_menu_cb(callback_id): + self.launchAction(callback_id, None, profile_key = self.profile) + for id_, type_, path, path_i18n in add_menus: assert(type_=="NORMAL") #TODO: manage other types - menu.addMenu(unicode(category), unicode(name), add_menu_cb) + if len(path) != 2: + raise NotImplementedError("Menu with a path != 2 are not implemented yet") + menu.addMenu(path_i18n[0], path_i18n[1], lambda menu: add_menu_cb(id_)) menu_roller = sat_widgets.MenuRoller([(_('Main menu'),menu)]) return menu_roller