comparison 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
comparison
equal deleted inserted replaced
497:516b06787c1a 498:60be99de3808
167 167
168 class WidgetMenuBar(base_menu.GenericMenuBar): 168 class WidgetMenuBar(base_menu.GenericMenuBar):
169 169
170 ITEM_TPL = "<img src='media/icons/misc/%s.png' />" 170 ITEM_TPL = "<img src='media/icons/misc/%s.png' />"
171 171
172 def __init__(self, host, vertical=False): 172 def __init__(self, parent, host, vertical=False):
173 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical) 173 styles = {'menu_bar': 'widgetHeader_buttonGroup'}
174 self.setStyleName('widgetHeader_buttonGroup') 174 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical, styles=styles)
175
176 # regroup all the dynamic menu categories in a sub-menu
177 item = WidgetSubMenuBar(host, vertical=True)
178 parent.addMenus(item)
179 if len(item.getCategories()) > 0:
180 self.addCategory('', '', 'plugins', item)
175 181
176 @classmethod 182 @classmethod
177 def getCategoryHTML(cls, type_, menu_name_i18n): 183 def getCategoryHTML(cls, type_, menu_name_i18n):
178 return cls.ITEM_TPL % type_ 184 return cls.ITEM_TPL % type_
185
186
187 class WidgetSubMenuBar(base_menu.GenericMenuBar):
188
189 def __init__(self, host, vertical=True):
190 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical)
191
192 @classmethod
193 def getCategoryHTML(cls, type_, menu_name_i18n):
194 return menu_name_i18n
179 195
180 196
181 class WidgetHeader(AbsolutePanel, LiberviaDragWidget): 197 class WidgetHeader(AbsolutePanel, LiberviaDragWidget):
182 198
183 def __init__(self, parent, host, title): 199 def __init__(self, parent, host, title):
184 AbsolutePanel.__init__(self) 200 AbsolutePanel.__init__(self)
185 self.add(title) 201 self.add(title)
186 button_group_wrapper = SimplePanel() 202 button_group_wrapper = SimplePanel()
187 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper') 203 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper')
188 button_group = WidgetMenuBar(host) 204 button_group = WidgetMenuBar(parent, host)
189 parent.addCachedMenus(button_group)
190 button_group.addItem('<img src="media/icons/misc/settings.png"/>', True, base_menu.MenuCmd(parent, 'onSetting')) 205 button_group.addItem('<img src="media/icons/misc/settings.png"/>', True, base_menu.MenuCmd(parent, 'onSetting'))
191 button_group.addItem('<img src="media/icons/misc/close.png"/>', True, base_menu.MenuCmd(parent, 'onClose')) 206 button_group.addItem('<img src="media/icons/misc/close.png"/>', True, base_menu.MenuCmd(parent, 'onClose'))
192 button_group_wrapper.setWidget(button_group) 207 button_group_wrapper.setWidget(button_group)
193 self.add(button_group_wrapper) 208 self.add(button_group_wrapper)
194 self.addStyleName('widgetHeader') 209 self.addStyleName('widgetHeader')
410 425
411 This method should be overwritten by child classes. 426 This method should be overwritten by child classes.
412 @return: True if the widget matches the entity""" 427 @return: True if the widget matches the entity"""
413 raise NotImplementedError 428 raise NotImplementedError
414 429
415 def addCachedMenus(self, menu_bar): 430 def addMenus(self, menu_bar):
416 """Add cached menus to the header. 431 """Add menus to the header.
417 432
418 This method can be overwritten by child classes. 433 This method can be overwritten by child classes.
419 @param menu_bar (GenericMenuBar): menu bar of the widget's header 434 @param menu_bar (GenericMenuBar): menu bar of the widget's header
420 """ 435 """
421 pass 436 pass