# HG changeset patch # User Goffi # Date 1426671562 -3600 # Node ID 584d45bb36d9b0ab608dad26dfdf9afa42008bd5 # Parent ba87b940f07a7d851dfdd46e3435fef5249f771a quick_frontends(menus): added MenuContainer.replace method + addMenuHook helper method in QuickMenusManager diff -r ba87b940f07a -r 584d45bb36d9 frontends/src/quick_frontend/quick_menus.py --- a/frontends/src/quick_frontend/quick_menus.py Tue Mar 17 19:33:05 2015 +0100 +++ b/frontends/src/quick_frontend/quick_menus.py Wed Mar 18 10:39:22 2015 +0100 @@ -219,7 +219,16 @@ yield child def append(self, item): + """add an item at the end of current ones + + @param item: instance of MenuBase (must be unique in container) + """ assert isinstance(item, MenuItem) or isinstance(item, MenuContainer) + assert item.canonical not in self._items + self._items[item.canonical] = item + + def replace(self, item): + """add an item at the end of current ones or replace an existing one""" self._items[item.canonical] = item @@ -391,6 +400,23 @@ else: self.addMenu(type_, path, path_i18n, id_=id_, extra=extra, top_extra=top_extra) + def addMenuHook(self, type_, path, path_i18n=None, extra=None, top_extra=None, callback=None): + """Helper method to add a menu hook + + Menu hooks are local menus which override menu given by backend + @param type_(unicode): same as in [sat.core.sat_main.SAT.importMenu] + @param path(list[unicode]): same as in [sat.core.sat_main.SAT.importMenu] + @param path_i18n(list[unicode], None): translated menu path (same lenght as path), or None to get deferred translation + @param extra(dict[unicode, unicode], None): same as in [addMenus] + @param top_extra: same as in [_createCategories] + @param callback(callable): local callback (mutually exclusive with id_) + """ + if path_i18n is None: + path_i18n = self._getPathI18n(path) + menu_item = MenuHook(type_, path[-1], path_i18n[-1], callback=callback, extra=extra) + self.addMenuItem(type_, path[:-1], menu_item, path_i18n[:-1], top_extra) + log.info(u"Menu hook set on {path} ({type_})".format(path=path, type_=type_)) + def addCategory(self, type_, path, path_i18n=None, extra=None, top_extra=None): """Create a category with all parents, and set extra on the last one