annotate browser/sat_browser/base_widget.py @ 1162:c62ffc3af3a9

Added tag 0.7.0a4 for changeset caa8747b1bb1
author Goffi <goffi@goffi.org>
date Fri, 01 Mar 2019 19:47:34 +0100
parents 2af117bfe6cc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
4 # Libervia: a Salut à Toi frontend
1144
2af117bfe6cc dates update
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
5 # Copyright (C) 2011-2019 Jérôme Poisson <goffi@goffi.org>
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
7 # This program is free software: you can redistribute it and/or modify
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
10 # (at your option) any later version.
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
12 # This program is distributed in the hope that it will be useful,
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
15 # GNU Affero General Public License for more details.
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
19
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 432
diff changeset
20 from sat.core.log import getLogger
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 432
diff changeset
21 log = getLogger(__name__)
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
22 import base_menu
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
23 from sat_frontends.quick_frontend import quick_menus
618
698bdb84f6a7 browser_side: always display the main tab bar with a "+" button to add a new tab
souliane <souliane@mailoo.org>
parents: 617
diff changeset
24
494
5d8632a7bfde browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents: 467
diff changeset
25
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
26 ### Exceptions ###
370
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
27
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 340
diff changeset
28
603
462d0458e679 browser_side: base_widget.DropCell raises an exception if the callback doesn't return a LiberviaWidget instance
souliane <souliane@mailoo.org>
parents: 598
diff changeset
29 class NoLiberviaWidgetException(Exception):
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
30 """A Libervia widget was expected"""
603
462d0458e679 browser_side: base_widget.DropCell raises an exception if the callback doesn't return a LiberviaWidget instance
souliane <souliane@mailoo.org>
parents: 598
diff changeset
31 pass
462d0458e679 browser_side: base_widget.DropCell raises an exception if the callback doesn't return a LiberviaWidget instance
souliane <souliane@mailoo.org>
parents: 598
diff changeset
32
462d0458e679 browser_side: base_widget.DropCell raises an exception if the callback doesn't return a LiberviaWidget instance
souliane <souliane@mailoo.org>
parents: 598
diff changeset
33
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 647
diff changeset
34 ### Menus ###
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
35
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 232
diff changeset
36
494
5d8632a7bfde browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents: 467
diff changeset
37 class WidgetMenuBar(base_menu.GenericMenuBar):
5d8632a7bfde browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents: 467
diff changeset
38
5d8632a7bfde browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents: 467
diff changeset
39 ITEM_TPL = "<img src='media/icons/misc/%s.png' />"
5d8632a7bfde browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents: 467
diff changeset
40
510
db3436c85fb1 browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents: 502
diff changeset
41 def __init__(self, parent, host, vertical=False, styles=None):
617
5baca9d46c34 browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents: 610
diff changeset
42 """
5baca9d46c34 browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents: 610
diff changeset
43
5baca9d46c34 browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents: 610
diff changeset
44 @param parent (Widget): LiberviaWidget, or instance of another class
5baca9d46c34 browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents: 610
diff changeset
45 implementing the method addMenus
5baca9d46c34 browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents: 610
diff changeset
46 @param host (SatWebFrontend)
5baca9d46c34 browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents: 610
diff changeset
47 @param vertical (bool): if True, set the menu vertically
5baca9d46c34 browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents: 610
diff changeset
48 @param styles (dict): optional styles dict
5baca9d46c34 browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents: 610
diff changeset
49 """
510
db3436c85fb1 browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents: 502
diff changeset
50 menu_styles = {'menu_bar': 'widgetHeader_buttonGroup'}
db3436c85fb1 browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents: 502
diff changeset
51 if styles:
db3436c85fb1 browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents: 502
diff changeset
52 menu_styles.update(styles)
db3436c85fb1 browser_side: the status menu is now based on GenericMenuBar instead of PopupMenuPanel
souliane <souliane@mailoo.org>
parents: 502
diff changeset
53 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical, styles=menu_styles)
498
60be99de3808 browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents: 494
diff changeset
54
632
c2abadf31afb browser side (menu): minor improvments:
Goffi <goffi@goffi.org>
parents: 617
diff changeset
55 # regroup all the dynamic menu categories in a sub-menu
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
56 for menu_context in parent.plugin_menu_context:
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
57 main_cont = host.menus.getMainContainer(menu_context)
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
58 if len(main_cont)>0: # we don't add the icon if the menu is empty
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
59 sub_menu = base_menu.GenericMenuBar(host, vertical=True, flat_level=1)
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
60 sub_menu.update(menu_context, parent)
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
61 menu_category = quick_menus.MenuCategory("plugins", extra={'icon':'plugins'})
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
62 self.addCategory(menu_category, sub_menu)
494
5d8632a7bfde browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents: 467
diff changeset
63
5d8632a7bfde browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents: 467
diff changeset
64 @classmethod
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
65 def getCategoryHTML(cls, category):
690
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 685
diff changeset
66 """Build the html to be used for displaying a category item.
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 685
diff changeset
67
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 685
diff changeset
68 @param category (quick_menus.MenuCategory): category to add
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 685
diff changeset
69 @return unicode: HTML to display
76a67d04c63e browser_side: improve comments for menus-related methods
souliane <souliane@mailoo.org>
parents: 685
diff changeset
70 """
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 648
diff changeset
71 return cls.ITEM_TPL % category.icon