Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
772:dd07fc737d6c | 773:eac23b1aad90 |
---|---|
280 try: | 280 try: |
281 return self.menu_roller.checkShortcuts(input) | 281 return self.menu_roller.checkShortcuts(input) |
282 except AttributeError: | 282 except AttributeError: |
283 return input | 283 return input |
284 | 284 |
285 def _dynamicMenuCb(self, xmlui): | |
286 ui = XMLUI(self, xml_data = xmlui) | |
287 ui.show('popup') | |
288 | |
289 def _dynamicMenuEb(self, failure): | |
290 self.showDialog(_(u"Error while calling menu"), type="error") | |
291 | |
292 def _buildMenuRoller(self): | 285 def _buildMenuRoller(self): |
293 menu = sat_widgets.Menu(self.loop) | 286 menu = sat_widgets.Menu(self.loop) |
294 general = _("General") | 287 general = _("General") |
295 menu.addMenu(general, _("Connect"), self.onConnectRequest) | 288 menu.addMenu(general, _("Connect"), self.onConnectRequest) |
296 menu.addMenu(general, _("Disconnect"), self.onDisconnectRequest) | 289 menu.addMenu(general, _("Disconnect"), self.onDisconnectRequest) |
304 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j') | 297 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j') |
305 menu.addMenu(communication, _("Find Gateways"), self.onFindGatewaysRequest, 'meta g') | 298 menu.addMenu(communication, _("Find Gateways"), self.onFindGatewaysRequest, 'meta g') |
306 menu.addMenu(communication, _("Search directory"), self.onSearchDirectory) | 299 menu.addMenu(communication, _("Search directory"), self.onSearchDirectory) |
307 #additionals menus | 300 #additionals menus |
308 #FIXME: do this in a more generic way (in quickapp) | 301 #FIXME: do this in a more generic way (in quickapp) |
309 add_menus = self.bridge.getMenus() | 302 add_menus = self.bridge.getMenus('', Const.NO_SECURITY_LIMIT) |
310 def add_menu_cb(menu): | 303 def add_menu_cb(callback_id): |
311 category, name = menu | 304 self.launchAction(callback_id, None, profile_key = self.profile) |
312 self.bridge.asyncCallMenu(category, name, Const.MENU_NORMAL, self.profile, callback=self._dynamicMenuCb, errback=self._dynamicMenuEb) | 305 for id_, type_, path, path_i18n in add_menus: |
313 for new_menu in add_menus: | |
314 type_, category, name = new_menu | |
315 assert(type_=="NORMAL") #TODO: manage other types | 306 assert(type_=="NORMAL") #TODO: manage other types |
316 menu.addMenu(unicode(category), unicode(name), add_menu_cb) | 307 if len(path) != 2: |
308 raise NotImplementedError("Menu with a path != 2 are not implemented yet") | |
309 menu.addMenu(path_i18n[0], path_i18n[1], lambda menu: add_menu_cb(id_)) | |
317 | 310 |
318 menu_roller = sat_widgets.MenuRoller([(_('Main menu'),menu)]) | 311 menu_roller = sat_widgets.MenuRoller([(_('Main menu'),menu)]) |
319 return menu_roller | 312 return menu_roller |
320 | 313 |
321 def _buildMainWidget(self): | 314 def _buildMainWidget(self): |