comparison src/browser/sat_browser/base_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 6d3142b782c3
children 9877607c719a
comparison
equal deleted inserted replaced
675:941e53b3af5c 676:849ffb24d5bf
15 # GNU Affero General Public License for more details. 15 # GNU Affero General Public License for more details.
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 import pyjd # this is dummy in pyjs
21 from sat.core.log import getLogger 20 from sat.core.log import getLogger
22 log = getLogger(__name__) 21 log = getLogger(__name__)
23 import base_menu 22 import base_menu
23 from sat_frontends.quick_frontend import quick_menus
24 24
25 25
26 ### Exceptions ### 26 ### Exceptions ###
27 27
28 28
51 if styles: 51 if styles:
52 menu_styles.update(styles) 52 menu_styles.update(styles)
53 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical, styles=menu_styles) 53 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical, styles=menu_styles)
54 54
55 # regroup all the dynamic menu categories in a sub-menu 55 # regroup all the dynamic menu categories in a sub-menu
56 sub_menu = WidgetSubMenuBar(host, vertical=True) 56 for menu_context in parent.plugin_menu_context:
57 try: 57 main_cont = host.menus.getMainContainer(menu_context)
58 parent.addMenus(sub_menu) 58 if len(main_cont)>0: # we don't add the icon if the menu is empty
59 except (AttributeError, TypeError): # FIXME: pyjamas can throw a TypeError depending on compilation options 59 sub_menu = base_menu.GenericMenuBar(host, vertical=True, flat_level=1)
60 pass 60 sub_menu.update(menu_context, parent)
61 else: 61 menu_category = quick_menus.MenuCategory("plugins", extra={'icon':'plugins'})
62 if len(sub_menu.getCategories()) > 0: 62 self.addCategory(menu_category, sub_menu)
63 self.addCategory('', '', 'plugins', sub_menu)
64 63
65 @classmethod 64 @classmethod
66 def getCategoryHTML(cls, menu_name_i18n, type_): 65 def getCategoryHTML(cls, category):
67 return cls.ITEM_TPL % type_ 66 return cls.ITEM_TPL % category.icon
68
69
70 class WidgetSubMenuBar(base_menu.GenericMenuBar):
71
72 def __init__(self, host, vertical=True):
73 """
74
75 @param host (SatWebFrontend)
76 @param vertical (bool): if True, set the menu vertically
77 """
78 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical, flat_level=1)
79
80 @classmethod
81 def getCategoryHTML(cls, menu_name_i18n, type_):
82 return menu_name_i18n