comparison src/browser/sat_browser/libervia_widget.py @ 676:849ffb24d5bf frontends_multi_profiles

browser side: menus refactorisation: - use of the new quick_frontends.quick_menus module, resulting in a big code simplification in Libervia - menu are added in there respective modules: main menus are done directely in libervia_main, while tarot and radiocol menus are done in game_tarot and game_radiocol - launchAction has the same signature as in QuickApp - base_menu: there are now 2 classes to launch an action: MenuCmd which manage quick_menus classes, and SimpleCmd to launch a generic callback - base_menu: MenuNode has been removed as logic is now in quick_menus - base_menu: GenericMenuBar.update method can be called to fully (re)build the menus - base_widget: removed WidgetSubMenuBar which is no more useful (GenericMenuBar do the same thing) - plugin_menu_context is used in LiberviaWidget and other classes with menus to indicate which menu types must be used - otr menus hooks are temporarily removed, will be fixed soon
author Goffi <goffi@goffi.org>
date Tue, 17 Mar 2015 20:42:02 +0100
parents 423182fea41c
children 9877607c719a
comparison
equal deleted inserted replaced
675:941e53b3af5c 676:849ffb24d5bf
344 button_group_wrapper.add(info) 344 button_group_wrapper.add(info)
345 else: 345 else:
346 button_group_wrapper = SimplePanel() 346 button_group_wrapper = SimplePanel()
347 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper') 347 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper')
348 button_group = base_widget.WidgetMenuBar(parent, host) 348 button_group = base_widget.WidgetMenuBar(parent, host)
349 button_group.addItem('<img src="media/icons/misc/settings.png"/>', True, base_menu.MenuCmd(parent, 'onSetting')) 349 button_group.addItem('<img src="media/icons/misc/settings.png"/>', True, base_menu.SimpleCmd(parent.onSetting))
350 button_group.addItem('<img src="media/icons/misc/close.png"/>', True, base_menu.MenuCmd(parent, 'onClose')) 350 button_group.addItem('<img src="media/icons/misc/close.png"/>', True, base_menu.SimpleCmd(parent.onClose))
351 button_group_wrapper.add(button_group) 351 button_group_wrapper.add(button_group)
352 self.add(button_group_wrapper) 352 self.add(button_group_wrapper)
353 self.addStyleName('widgetHeader') 353 self.addStyleName('widgetHeader')
354 LiberviaDragWidget.__init__(self, "", "WIDGET", parent) 354 LiberviaDragWidget.__init__(self, "", "WIDGET", parent)
355 355
356 356
357 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler): 357 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler):
358 """Libervia's widget which can replace itself with a dropped widget on DnD""" 358 """Libervia's widget which can replace itself with a dropped widget on DnD"""
359 359
360 def __init__(self, host, title='', info=None, selectable=False): 360 def __init__(self, host, title='', info=None, selectable=False, plugin_menu_context=None):
361 """Init the widget 361 """Init the widget
362 362
363 @param host (SatWebFrontend): SatWebFrontend instance 363 @param host (SatWebFrontend): SatWebFrontend instance
364 @param title (unicode): title shown in the header of the widget 364 @param title (unicode): title shown in the header of the widget
365 @param info (unicode): info shown in the header of the widget 365 @param info (unicode): info shown in the header of the widget
366 @param selectable (bool): True is widget can be selected by user 366 @param selectable (bool): True is widget can be selected by user
367 @param plugin_menu_context (iterable): contexts of menus to have (list of C.MENU_* constant)
367 """ 368 """
368 VerticalPanel.__init__(self) 369 VerticalPanel.__init__(self)
369 DropCell.__init__(self, host) 370 DropCell.__init__(self, host)
370 ClickHandler.__init__(self) 371 ClickHandler.__init__(self)
371 self._selectable = selectable 372 self._selectable = selectable
373 self._plugin_menu_context = [] if plugin_menu_context is None else plugin_menu_context
372 self._title_id = HTMLPanel.createUniqueId() 374 self._title_id = HTMLPanel.createUniqueId()
373 self._setting_button_id = HTMLPanel.createUniqueId() 375 self._setting_button_id = HTMLPanel.createUniqueId()
374 self._close_button_id = HTMLPanel.createUniqueId() 376 self._close_button_id = HTMLPanel.createUniqueId()
375 self._title = Label(title) 377 self._title = Label(title)
376 self._title.setStyleName('widgetHeader_title') 378 self._title.setStyleName('widgetHeader_title')
393 # self.host.uni_box.onWidgetClosed(sender) 395 # self.host.uni_box.onWidgetClosed(sender)
394 396
395 # self.addCloseListener(onClose) 397 # self.addCloseListener(onClose)
396 # self.host.registerWidget(self) # FIXME 398 # self.host.registerWidget(self) # FIXME
397 399
400 @property
401 def plugin_menu_context(self):
402 return self._plugin_menu_context
403
398 def getDebugName(self): 404 def getDebugName(self):
399 return "%s (%s)" % (self, self._title.getText()) 405 return "%s (%s)" % (self, self._title.getText())
400 406
401 def getParent(self, class_=None, expect=True): 407 def getParent(self, class_=None, expect=True):
402 """Return the closest ancestor of the specified class. 408 """Return the closest ancestor of the specified class.
569 575
570 def doAttachChildren(self): 576 def doAttachChildren(self):
571 # We need to force the use of a panel subclass method here, else 577 # We need to force the use of a panel subclass method here, else
572 # the event will not propagate to children 578 # the event will not propagate to children
573 VerticalPanel.doAttachChildren(self) 579 VerticalPanel.doAttachChildren(self)
574
575 def addMenus(self, menu_bar):
576 """Add menus to the header.
577
578 This method can be overwritten by child classes.
579 @param menu_bar (GenericMenuBar): menu bar of the widget's header
580 """
581 pass
582 580
583 581
584 # XXX: WidgetsPanel and MainTabPanel are both here to avoir cyclic import 582 # XXX: WidgetsPanel and MainTabPanel are both here to avoir cyclic import
585 583
586 584