comparison browser/sat_browser/base_widget.py @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/browser/sat_browser/base_widget.py@f2170536ba23
children 2af117bfe6cc
comparison
equal deleted inserted replaced
1123:63a4b8fe9782 1124:28e3eb3bb217
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Libervia: a Salut à Toi frontend
5 # Copyright (C) 2011-2018 Jérôme Poisson <goffi@goffi.org>
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
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/>.
19
20 from sat.core.log import getLogger
21 log = getLogger(__name__)
22 import base_menu
23 from sat_frontends.quick_frontend import quick_menus
24
25
26 ### Exceptions ###
27
28
29 class NoLiberviaWidgetException(Exception):
30 """A Libervia widget was expected"""
31 pass
32
33
34 ### Menus ###
35
36
37 class WidgetMenuBar(base_menu.GenericMenuBar):
38
39 ITEM_TPL = "<img src='media/icons/misc/%s.png' />"
40
41 def __init__(self, parent, host, vertical=False, styles=None):
42 """
43
44 @param parent (Widget): LiberviaWidget, or instance of another class
45 implementing the method addMenus
46 @param host (SatWebFrontend)
47 @param vertical (bool): if True, set the menu vertically
48 @param styles (dict): optional styles dict
49 """
50 menu_styles = {'menu_bar': 'widgetHeader_buttonGroup'}
51 if styles:
52 menu_styles.update(styles)
53 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical, styles=menu_styles)
54
55 # regroup all the dynamic menu categories in a sub-menu
56 for menu_context in parent.plugin_menu_context:
57 main_cont = host.menus.getMainContainer(menu_context)
58 if len(main_cont)>0: # we don't add the icon if the menu is empty
59 sub_menu = base_menu.GenericMenuBar(host, vertical=True, flat_level=1)
60 sub_menu.update(menu_context, parent)
61 menu_category = quick_menus.MenuCategory("plugins", extra={'icon':'plugins'})
62 self.addCategory(menu_category, sub_menu)
63
64 @classmethod
65 def getCategoryHTML(cls, category):
66 """Build the html to be used for displaying a category item.
67
68 @param category (quick_menus.MenuCategory): category to add
69 @return unicode: HTML to display
70 """
71 return cls.ITEM_TPL % category.icon