Mercurial > libervia-web
diff src/browser/sat_browser/base_widget.py @ 498:60be99de3808
browser_side: menus refactorization + handle levels > 2
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 25 Jul 2014 02:38:30 +0200 |
parents | 5d8632a7bfde |
children | 4aa627b059df |
line wrap: on
line diff
--- a/src/browser/sat_browser/base_widget.py Thu Jul 24 12:20:36 2014 +0200 +++ b/src/browser/sat_browser/base_widget.py Fri Jul 25 02:38:30 2014 +0200 @@ -169,15 +169,31 @@ ITEM_TPL = "<img src='media/icons/misc/%s.png' />" - def __init__(self, host, vertical=False): - base_menu.GenericMenuBar.__init__(self, host, vertical=vertical) - self.setStyleName('widgetHeader_buttonGroup') + def __init__(self, parent, host, vertical=False): + styles = {'menu_bar': 'widgetHeader_buttonGroup'} + base_menu.GenericMenuBar.__init__(self, host, vertical=vertical, styles=styles) + + # regroup all the dynamic menu categories in a sub-menu + item = WidgetSubMenuBar(host, vertical=True) + parent.addMenus(item) + if len(item.getCategories()) > 0: + self.addCategory('', '', 'plugins', item) @classmethod def getCategoryHTML(cls, type_, menu_name_i18n): return cls.ITEM_TPL % type_ +class WidgetSubMenuBar(base_menu.GenericMenuBar): + + def __init__(self, host, vertical=True): + base_menu.GenericMenuBar.__init__(self, host, vertical=vertical) + + @classmethod + def getCategoryHTML(cls, type_, menu_name_i18n): + return menu_name_i18n + + class WidgetHeader(AbsolutePanel, LiberviaDragWidget): def __init__(self, parent, host, title): @@ -185,8 +201,7 @@ self.add(title) button_group_wrapper = SimplePanel() button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper') - button_group = WidgetMenuBar(host) - parent.addCachedMenus(button_group) + button_group = WidgetMenuBar(parent, host) button_group.addItem('<img src="media/icons/misc/settings.png"/>', True, base_menu.MenuCmd(parent, 'onSetting')) button_group.addItem('<img src="media/icons/misc/close.png"/>', True, base_menu.MenuCmd(parent, 'onClose')) button_group_wrapper.setWidget(button_group) @@ -412,8 +427,8 @@ @return: True if the widget matches the entity""" raise NotImplementedError - def addCachedMenus(self, menu_bar): - """Add cached menus to the header. + def addMenus(self, menu_bar): + """Add menus to the header. This method can be overwritten by child classes. @param menu_bar (GenericMenuBar): menu bar of the widget's header