Mercurial > libervia-web
changeset 632:c2abadf31afb frontends_multi_profiles
browser side (menu): minor improvments:
- use of new style class for MenuCmd and PluginMenuCmd (useless for pyjamas, but can be useful in the future)
- use of try/except instead of hasattr
- do not use "None" for WidgetMenuBar's __init__
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 23 Feb 2015 18:43:08 +0100 |
parents | e287a4b431c1 |
children | 617f7a5c5312 |
files | src/browser/sat_browser/base_menu.py src/browser/sat_browser/base_widget.py src/browser/sat_browser/panels.py |
diffstat | 3 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/browser/sat_browser/base_menu.py Mon Feb 23 18:20:04 2015 +0100 +++ b/src/browser/sat_browser/base_menu.py Mon Feb 23 18:43:08 2015 +0100 @@ -37,7 +37,7 @@ import re -class MenuCmd: +class MenuCmd(object): """Return an object with an "execute" method that can be set to a menu item callback""" def __init__(self, object_, handler=None, data=None): @@ -58,7 +58,7 @@ self.callback(self.data) if self.data else self.callback() -class PluginMenuCmd: +class PluginMenuCmd(object): """Like MenuCmd, but instead of executing a method, it will command the bridge to launch an action""" def __init__(self, host, action_id, menu_data=None):
--- a/src/browser/sat_browser/base_widget.py Mon Feb 23 18:20:04 2015 +0100 +++ b/src/browser/sat_browser/base_widget.py Mon Feb 23 18:43:08 2015 +0100 @@ -223,10 +223,13 @@ menu_styles.update(styles) base_menu.GenericMenuBar.__init__(self, host, vertical=vertical, styles=menu_styles) - if hasattr(parent, 'addMenus'): - # regroup all the dynamic menu categories in a sub-menu - sub_menu = WidgetSubMenuBar(host, vertical=True) + # regroup all the dynamic menu categories in a sub-menu + sub_menu = WidgetSubMenuBar(host, vertical=True) + try: parent.addMenus(sub_menu) + except (AttributeError, TypeError): # FIXME: pyjamas can throw a TypeError depending on compilation options + pass + else: if len(sub_menu.getCategories()) > 0: self.addCategory('', '', 'plugins', sub_menu)
--- a/src/browser/sat_browser/panels.py Mon Feb 23 18:20:04 2015 +0100 +++ b/src/browser/sat_browser/panels.py Mon Feb 23 18:43:08 2015 +0100 @@ -388,7 +388,7 @@ class PresenceStatusMenuBar(base_widget.WidgetMenuBar): def __init__(self, parent): styles = {'menu_bar': 'presence-button'} - base_widget.WidgetMenuBar.__init__(self, None, parent.host, styles=styles) + base_widget.WidgetMenuBar.__init__(self, parent, parent.host, styles=styles) self.button = self.addCategory(u"◉", u"◉", '') for presence, presence_i18n in C.PRESENCE.items(): html = u'<span class="%s">◉</span> %s' % (contact_list.buildPresenceStyle(presence), presence_i18n)