# HG changeset patch # User souliane # Date 1408612907 -7200 # Node ID 1d41cc5b57b1f0785e9d2ebb37ff363ba6a693a1 # Parent b7988fdd4329e7228a4f20a9ef592c8c957b4577 browser_side: fixes using addStyleName and removeStyleName on a GenericMenuBar diff -r b7988fdd4329 -r 1d41cc5b57b1 src/browser/sat_browser/base_menu.py --- 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)