comparison frontends/src/quick_frontend/quick_menus.py @ 1366:584d45bb36d9 frontends_multi_profiles

quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager
author Goffi <goffi@goffi.org>
date Wed, 18 Mar 2015 10:39:22 +0100
parents 28f0b33ca17c
children 069ad98b360d
comparison
equal deleted inserted replaced
1365:ba87b940f07a 1366:584d45bb36d9
217 for child in self._items.itervalues(): 217 for child in self._items.itervalues():
218 if child.ACTIVE: 218 if child.ACTIVE:
219 yield child 219 yield child
220 220
221 def append(self, item): 221 def append(self, item):
222 """add an item at the end of current ones
223
224 @param item: instance of MenuBase (must be unique in container)
225 """
222 assert isinstance(item, MenuItem) or isinstance(item, MenuContainer) 226 assert isinstance(item, MenuItem) or isinstance(item, MenuContainer)
227 assert item.canonical not in self._items
228 self._items[item.canonical] = item
229
230 def replace(self, item):
231 """add an item at the end of current ones or replace an existing one"""
223 self._items[item.canonical] = item 232 self._items[item.canonical] = item
224 233
225 234
226 class MenuCategory(MenuContainer): 235 class MenuCategory(MenuContainer):
227 """A category which can hold other menus or categories""" 236 """A category which can hold other menus or categories"""
389 if callable(id_): 398 if callable(id_):
390 self.addMenu(type_, path, path_i18n, callback=id_, extra=extra, top_extra=top_extra) 399 self.addMenu(type_, path, path_i18n, callback=id_, extra=extra, top_extra=top_extra)
391 else: 400 else:
392 self.addMenu(type_, path, path_i18n, id_=id_, extra=extra, top_extra=top_extra) 401 self.addMenu(type_, path, path_i18n, id_=id_, extra=extra, top_extra=top_extra)
393 402
403 def addMenuHook(self, type_, path, path_i18n=None, extra=None, top_extra=None, callback=None):
404 """Helper method to add a menu hook
405
406 Menu hooks are local menus which override menu given by backend
407 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu]
408 @param path(list[unicode]): same as in [sat.core.sat_main.SAT.importMenu]
409 @param path_i18n(list[unicode], None): translated menu path (same lenght as path), or None to get deferred translation
410 @param extra(dict[unicode, unicode], None): same as in [addMenus]
411 @param top_extra: same as in [_createCategories]
412 @param callback(callable): local callback (mutually exclusive with id_)
413 """
414 if path_i18n is None:
415 path_i18n = self._getPathI18n(path)
416 menu_item = MenuHook(type_, path[-1], path_i18n[-1], callback=callback, extra=extra)
417 self.addMenuItem(type_, path[:-1], menu_item, path_i18n[:-1], top_extra)
418 log.info(u"Menu hook set on {path} ({type_})".format(path=path, type_=type_))
419
394 def addCategory(self, type_, path, path_i18n=None, extra=None, top_extra=None): 420 def addCategory(self, type_, path, path_i18n=None, extra=None, top_extra=None):
395 """Create a category with all parents, and set extra on the last one 421 """Create a category with all parents, and set extra on the last one
396 422
397 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] 423 @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu]
398 @param path(list[unicode]): same as in [sat.core.sat_main.SAT.importMenu] 424 @param path(list[unicode]): same as in [sat.core.sat_main.SAT.importMenu]