Mercurial > libervia-web
diff src/browser/sat_browser/base_menu.py @ 510:db3436c85fb1
browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 21 Aug 2014 16:44:39 +0200 |
parents | 35ccb3ff8245 |
children | 85699d18921f |
line wrap: on
line diff
--- a/src/browser/sat_browser/base_menu.py Thu Aug 21 16:18:51 2014 +0200 +++ b/src/browser/sat_browser/base_menu.py Thu Aug 21 16:44:39 2014 +0200 @@ -39,13 +39,14 @@ class MenuCmd: """Return an object with an "execute" method that can be set to a menu item callback""" - def __init__(self, object_, handler): + def __init__(self, object_, handler, data=None): self._object = object_ self._handler = handler + self._data = data def execute(self): handler = getattr(self._object, self._handler) - handler() + handler(self._data) if self._data else handler() class PluginMenuCmd: @@ -123,14 +124,15 @@ return cat.getCategories(target_path[-1:]) if cat else None return [child for child in self.children if child.menu] - def addMenuItem(self, path, path_i18n, types, callback=None): + def addMenuItem(self, path, path_i18n, types, callback=None, asHTML=False): """Recursively add a new node, which could be a category or a leaf node. @param path (list[str], str): path to the item @param path_i18n (list[str], str): internationalized path to the item @param types (list[str], str): types of the item and its parents - @param menu_cmd (MenuCmd, PluginMenuCmd or GenericMenuBar): instance to - execute as a leaf's callback or to popup as a category sub-menu. + @param callback (MenuCmd, PluginMenuCmd or GenericMenuBar): instance to + execute as a leaf's callback or to popup as a category sub-menu + @param asHTML (boolean): True to display the UI item as HTML """ log.info("addMenuItem: %s %s %s %s" % (path, path_i18n, types, callback)) @@ -149,7 +151,7 @@ path.append(None) # dummy name for a leaf node parent = self._getOrCreateCategory(path[:-1], path_i18n[:-1], types[:-1], True) - return parent.addItem(path_i18n[-1], callback) + return parent.addItem(path_i18n[-1], asHTML=asHTML, popup=callback) def addCategory(self, path, path_i18n, types, menu_bar=None): """Recursively add a new category. @@ -289,8 +291,8 @@ """ return [cat.item for cat in self.node.getCategories(parent_path)] - def addMenuItem(self, path, path_i18n, types, menu_cmd): - return self.node.addMenuItem(path, path_i18n, types, menu_cmd).item + def addMenuItem(self, path, path_i18n, types, menu_cmd, asHTML=False): + return self.node.addMenuItem(path, path_i18n, types, menu_cmd, asHTML).item def addCategory(self, path, path_i18n, types, menu_bar): return self.node.addCategory(path, path_i18n, types, menu_bar).item