Mercurial > libervia-web
diff src/browser/sat_browser/base_menu.py @ 508:1d41cc5b57b1
browser_side: fixes using addStyleName and removeStyleName on a GenericMenuBar
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 21 Aug 2014 11:21:47 +0200 |
parents | 4aa627b059df |
children | 35ccb3ff8245 |
line wrap: on
line diff
--- a/src/browser/sat_browser/base_menu.py Wed Aug 20 23:04:15 2014 +0200 +++ b/src/browser/sat_browser/base_menu.py Thu Aug 21 11:21:47 2014 +0200 @@ -29,9 +29,12 @@ log = getLogger(__name__) from pyjamas.ui.MenuBar import MenuBar +from pyjamas.ui.UIObject import UIObject from pyjamas.ui.MenuItem import MenuItem from pyjamas import Window +import re + class MenuCmd: """Return an object with an "execute" method that can be set to a menu item callback""" @@ -208,11 +211,7 @@ if styles: self.styles.update(styles) if 'menu_bar' in self.styles: - # XXX: pyjamas set the style to object string representation! - # FIXME: fix the bug upstream - first = 'gwt-MenuBar' - second = first + '-' + ('vertical' if self.vertical else 'horizontal') - self.setStyleName(' '.join([first, second, self.styles['menu_bar']])) + self.setStyleName(self.styles['menu_bar']) self.node = MenuNode(menu=self, flat_level=flat_level) @classmethod @@ -226,6 +225,28 @@ """ return menu_name_i18n + def setStyleName(self, style): + # XXX: pyjamas set the style to object string representation! + # FIXME: fix the bug upstream + menu_style = ['gwt-MenuBar'] + menu_style.append(menu_style[0] + '-' + ('vertical' if self.vertical else 'horizontal')) + for classname in style.split(' '): + if classname not in menu_style: + menu_style.append(classname) + UIObject.setStyleName(self, ' '.join(menu_style)) + + def addStyleName(self, style): + # XXX: same kind of problem then with setStyleName + # FIXME: fix the bug upstream + if not re.search('(^| )%s( |$)' % style, self.getStyleName()): + UIObject.setStyleName(self, self.getStyleName() + ' ' + style) + + def removeStyleName(self, style): + # XXX: same kind of problem then with setStyleName + # FIXME: fix the bug upstream + style = re.sub('(^| )%s( |$)' % style, ' ', self.getStyleName()).strip() + UIObject.setStyleName(self, style) + def doItemAction(self, item, fireCommand): """Overwrites the default behavior for the popup menu to fit in the screen""" MenuBar.doItemAction(self, item, fireCommand)