comparison 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
comparison
equal deleted inserted replaced
507:b7988fdd4329 508:1d41cc5b57b1
27 import pyjd # this is dummy in pyjs 27 import pyjd # this is dummy in pyjs
28 from sat.core.log import getLogger 28 from sat.core.log import getLogger
29 log = getLogger(__name__) 29 log = getLogger(__name__)
30 30
31 from pyjamas.ui.MenuBar import MenuBar 31 from pyjamas.ui.MenuBar import MenuBar
32 from pyjamas.ui.UIObject import UIObject
32 from pyjamas.ui.MenuItem import MenuItem 33 from pyjamas.ui.MenuItem import MenuItem
33 from pyjamas import Window 34 from pyjamas import Window
35
36 import re
34 37
35 38
36 class MenuCmd: 39 class MenuCmd:
37 """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"""
38 41
206 self.host = host 209 self.host = host
207 self.styles = {'separator': 'menuSeparator', 'flattened-category': 'menuFlattenedCategory'} 210 self.styles = {'separator': 'menuSeparator', 'flattened-category': 'menuFlattenedCategory'}
208 if styles: 211 if styles:
209 self.styles.update(styles) 212 self.styles.update(styles)
210 if 'menu_bar' in self.styles: 213 if 'menu_bar' in self.styles:
211 # XXX: pyjamas set the style to object string representation! 214 self.setStyleName(self.styles['menu_bar'])
212 # FIXME: fix the bug upstream
213 first = 'gwt-MenuBar'
214 second = first + '-' + ('vertical' if self.vertical else 'horizontal')
215 self.setStyleName(' '.join([first, second, self.styles['menu_bar']]))
216 self.node = MenuNode(menu=self, flat_level=flat_level) 215 self.node = MenuNode(menu=self, flat_level=flat_level)
217 216
218 @classmethod 217 @classmethod
219 def getCategoryHTML(cls, menu_name_i18n, type_): 218 def getCategoryHTML(cls, menu_name_i18n, type_):
220 """Build the html to be used for displaying a category item. 219 """Build the html to be used for displaying a category item.
223 @param menu_name_i18n (str): internationalized category name 222 @param menu_name_i18n (str): internationalized category name
224 @param type_ (str): category type 223 @param type_ (str): category type
225 @return: str 224 @return: str
226 """ 225 """
227 return menu_name_i18n 226 return menu_name_i18n
227
228 def setStyleName(self, style):
229 # XXX: pyjamas set the style to object string representation!
230 # FIXME: fix the bug upstream
231 menu_style = ['gwt-MenuBar']
232 menu_style.append(menu_style[0] + '-' + ('vertical' if self.vertical else 'horizontal'))
233 for classname in style.split(' '):
234 if classname not in menu_style:
235 menu_style.append(classname)
236 UIObject.setStyleName(self, ' '.join(menu_style))
237
238 def addStyleName(self, style):
239 # XXX: same kind of problem then with setStyleName
240 # FIXME: fix the bug upstream
241 if not re.search('(^| )%s( |$)' % style, self.getStyleName()):
242 UIObject.setStyleName(self, self.getStyleName() + ' ' + style)
243
244 def removeStyleName(self, style):
245 # XXX: same kind of problem then with setStyleName
246 # FIXME: fix the bug upstream
247 style = re.sub('(^| )%s( |$)' % style, ' ', self.getStyleName()).strip()
248 UIObject.setStyleName(self, style)
228 249
229 def doItemAction(self, item, fireCommand): 250 def doItemAction(self, item, fireCommand):
230 """Overwrites the default behavior for the popup menu to fit in the screen""" 251 """Overwrites the default behavior for the popup menu to fit in the screen"""
231 MenuBar.doItemAction(self, item, fireCommand) 252 MenuBar.doItemAction(self, item, fireCommand)
232 if not self.popup: 253 if not self.popup: