comparison 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
comparison
equal deleted inserted replaced
509:35ccb3ff8245 510:db3436c85fb1
37 37
38 38
39 class MenuCmd: 39 class MenuCmd:
40 """Return an object with an "execute" method that can be set to a menu item callback""" 40 """Return an object with an "execute" method that can be set to a menu item callback"""
41 41
42 def __init__(self, object_, handler): 42 def __init__(self, object_, handler, data=None):
43 self._object = object_ 43 self._object = object_
44 self._handler = handler 44 self._handler = handler
45 self._data = data
45 46
46 def execute(self): 47 def execute(self):
47 handler = getattr(self._object, self._handler) 48 handler = getattr(self._object, self._handler)
48 handler() 49 handler(self._data) if self._data else handler()
49 50
50 51
51 class PluginMenuCmd: 52 class PluginMenuCmd:
52 """Like MenuCmd, but instead of executing a method, it will command the bridge to launch an action""" 53 """Like MenuCmd, but instead of executing a method, it will command the bridge to launch an action"""
53 54
121 assert(isinstance(target_path, list)) 122 assert(isinstance(target_path, list))
122 cat = self._getOrCreateCategory(target_path[:-1]) 123 cat = self._getOrCreateCategory(target_path[:-1])
123 return cat.getCategories(target_path[-1:]) if cat else None 124 return cat.getCategories(target_path[-1:]) if cat else None
124 return [child for child in self.children if child.menu] 125 return [child for child in self.children if child.menu]
125 126
126 def addMenuItem(self, path, path_i18n, types, callback=None): 127 def addMenuItem(self, path, path_i18n, types, callback=None, asHTML=False):
127 """Recursively add a new node, which could be a category or a leaf node. 128 """Recursively add a new node, which could be a category or a leaf node.
128 129
129 @param path (list[str], str): path to the item 130 @param path (list[str], str): path to the item
130 @param path_i18n (list[str], str): internationalized path to the item 131 @param path_i18n (list[str], str): internationalized path to the item
131 @param types (list[str], str): types of the item and its parents 132 @param types (list[str], str): types of the item and its parents
132 @param menu_cmd (MenuCmd, PluginMenuCmd or GenericMenuBar): instance to 133 @param callback (MenuCmd, PluginMenuCmd or GenericMenuBar): instance to
133 execute as a leaf's callback or to popup as a category sub-menu. 134 execute as a leaf's callback or to popup as a category sub-menu
135 @param asHTML (boolean): True to display the UI item as HTML
134 """ 136 """
135 log.info("addMenuItem: %s %s %s %s" % (path, path_i18n, types, callback)) 137 log.info("addMenuItem: %s %s %s %s" % (path, path_i18n, types, callback))
136 138
137 leaf_node = hasattr(callback, "execute") 139 leaf_node = hasattr(callback, "execute")
138 category = isinstance(callback, GenericMenuBar) 140 category = isinstance(callback, GenericMenuBar)
147 149
148 if len(path) == len(path_i18n) - 1: 150 if len(path) == len(path_i18n) - 1:
149 path.append(None) # dummy name for a leaf node 151 path.append(None) # dummy name for a leaf node
150 152
151 parent = self._getOrCreateCategory(path[:-1], path_i18n[:-1], types[:-1], True) 153 parent = self._getOrCreateCategory(path[:-1], path_i18n[:-1], types[:-1], True)
152 return parent.addItem(path_i18n[-1], callback) 154 return parent.addItem(path_i18n[-1], asHTML=asHTML, popup=callback)
153 155
154 def addCategory(self, path, path_i18n, types, menu_bar=None): 156 def addCategory(self, path, path_i18n, types, menu_bar=None):
155 """Recursively add a new category. 157 """Recursively add a new category.
156 158
157 @param path (list[str], str): path to the category 159 @param path (list[str], str): path to the category
287 289
288 @return: list[CategoryItem] 290 @return: list[CategoryItem]
289 """ 291 """
290 return [cat.item for cat in self.node.getCategories(parent_path)] 292 return [cat.item for cat in self.node.getCategories(parent_path)]
291 293
292 def addMenuItem(self, path, path_i18n, types, menu_cmd): 294 def addMenuItem(self, path, path_i18n, types, menu_cmd, asHTML=False):
293 return self.node.addMenuItem(path, path_i18n, types, menu_cmd).item 295 return self.node.addMenuItem(path, path_i18n, types, menu_cmd, asHTML).item
294 296
295 def addCategory(self, path, path_i18n, types, menu_bar): 297 def addCategory(self, path, path_i18n, types, menu_bar):
296 return self.node.addCategory(path, path_i18n, types, menu_bar).item 298 return self.node.addCategory(path, path_i18n, types, menu_bar).item
297 299
298 def addItem(self, item, asHTML=None, popup=None): 300 def addItem(self, item, asHTML=None, popup=None):