Mercurial > libervia-web
annotate src/browser/sat_browser/base_widget.py @ 656:4dbd99de3aaa frontends_multi_profiles
browser_side: only display "+" button when the tab bar contains only 1 tab, and display it over the contact list to not use vertical space
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 27 Feb 2015 13:00:04 +0100 |
parents | 6d3142b782c3 |
children | 849ffb24d5bf |
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 |
340 | 5 # Copyright (C) 2011, 2012, 2013, 2014 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 |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
232
diff
changeset
|
20 import pyjd # this is dummy in pyjs |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
432
diff
changeset
|
21 from sat.core.log import getLogger |
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
432
diff
changeset
|
22 log = getLogger(__name__) |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
23 import base_menu |
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 |
c2abadf31afb
browser side (menu): minor improvments:
Goffi <goffi@goffi.org>
parents:
617
diff
changeset
|
56 sub_menu = WidgetSubMenuBar(host, vertical=True) |
c2abadf31afb
browser side (menu): minor improvments:
Goffi <goffi@goffi.org>
parents:
617
diff
changeset
|
57 try: |
606
7af8f4ab3675
browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents:
598
diff
changeset
|
58 parent.addMenus(sub_menu) |
632
c2abadf31afb
browser side (menu): minor improvments:
Goffi <goffi@goffi.org>
parents:
617
diff
changeset
|
59 except (AttributeError, TypeError): # FIXME: pyjamas can throw a TypeError depending on compilation options |
c2abadf31afb
browser side (menu): minor improvments:
Goffi <goffi@goffi.org>
parents:
617
diff
changeset
|
60 pass |
c2abadf31afb
browser side (menu): minor improvments:
Goffi <goffi@goffi.org>
parents:
617
diff
changeset
|
61 else: |
606
7af8f4ab3675
browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents:
598
diff
changeset
|
62 if len(sub_menu.getCategories()) > 0: |
7af8f4ab3675
browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents:
598
diff
changeset
|
63 self.addCategory('', '', 'plugins', sub_menu) |
494
5d8632a7bfde
browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
64 |
5d8632a7bfde
browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
65 @classmethod |
502
4aa627b059df
browser_side: categories of the menus can be "flattened":
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
66 def getCategoryHTML(cls, menu_name_i18n, type_): |
494
5d8632a7bfde
browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
67 return cls.ITEM_TPL % type_ |
5d8632a7bfde
browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
68 |
5d8632a7bfde
browser_side: refactorisation of menus and LiberviaWidget's header
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
69 |
498
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
494
diff
changeset
|
70 class WidgetSubMenuBar(base_menu.GenericMenuBar): |
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
494
diff
changeset
|
71 |
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
494
diff
changeset
|
72 def __init__(self, host, vertical=True): |
617
5baca9d46c34
browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents:
610
diff
changeset
|
73 """ |
5baca9d46c34
browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents:
610
diff
changeset
|
74 |
5baca9d46c34
browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents:
610
diff
changeset
|
75 @param host (SatWebFrontend) |
5baca9d46c34
browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents:
610
diff
changeset
|
76 @param vertical (bool): if True, set the menu vertically |
5baca9d46c34
browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents:
610
diff
changeset
|
77 """ |
502
4aa627b059df
browser_side: categories of the menus can be "flattened":
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
78 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical, flat_level=1) |
498
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
494
diff
changeset
|
79 |
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
494
diff
changeset
|
80 @classmethod |
502
4aa627b059df
browser_side: categories of the menus can be "flattened":
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
81 def getCategoryHTML(cls, menu_name_i18n, type_): |
498
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
494
diff
changeset
|
82 return menu_name_i18n |