Mercurial > libervia-web
annotate src/browser/sat_browser/base_panel.py @ 939:1375b96f4309
pages (common/blog): check posted data type for comments
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 27 Apr 2017 01:15:54 +0200 |
parents | f8a7a046ff9c |
children | fd4eae654182 |
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:
323
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
818 | 5 # Copyright (C) 2011-2016 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:
323
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:
323
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:
323
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:
323
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:
323
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:
323
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:
323
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:
323
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:
323
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:
323
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:
433
diff
changeset
|
20 from sat.core.log import getLogger |
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
21 log = getLogger(__name__) |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
439
diff
changeset
|
22 from sat.core.i18n import _ |
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
439
diff
changeset
|
23 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from pyjamas.ui.VerticalPanel import VerticalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
26 from pyjamas.ui.ScrollPanel import ScrollPanel |
83 | 27 from pyjamas.ui.Button import Button |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
28 from pyjamas.ui.SimplePanel import SimplePanel |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
29 from pyjamas.ui.PopupPanel import PopupPanel |
264
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
30 from pyjamas.ui.StackPanel import StackPanel |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
31 from pyjamas.ui.TextArea import TextArea |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
32 from pyjamas.ui.Event import BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from pyjamas import DOM |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
34 |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
206
diff
changeset
|
35 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
36 ### Menus ### |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
37 |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
206
diff
changeset
|
38 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
39 class PopupMenuPanel(PopupPanel): |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
40 """Popup menu (contextual menu) with common callbacks for all the items. |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
41 |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
42 This implementation of a popup menu allow you to assign two special methods which |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
43 are common to all the items, in order to hide certain items and define their callbacks. |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
44 callbacks. The menu can be bound to any button of the mouse (left, middle, right). |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
45 """ |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
46 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
47 def __init__(self, entries, hide=None, callback=None, vertical=True, style=None, **kwargs): |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
48 """ |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
49 @param entries (dict{unicode: dict{unicode: unicode}: |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
50 - menu item keys |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
51 - values: dict{unicode: unicode}: |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
52 - item data lile "title", "desc"... |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
53 - value |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
54 @param hide (callable): function of signature Widget, unicode: bool |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
55 which takes the sender and the item key, and returns True if that |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
56 item has to be hidden from the context menu. |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
57 @param callback (callbable): function of signature Widget, unicode: None |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
58 which takes the sender and the item key. |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
59 @param vertical (bool): set the direction vertical or horizontal |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
60 @param item_style (unicode): alternative CSS class for the menu items |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
61 @param menu_style (unicode): supplementary CSS class for the sender widget |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
62 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
63 PopupPanel.__init__(self, autoHide=True, **kwargs) |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
64 self.entries = entries |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
65 self.hideMenu = hide |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
66 self.callback = callback |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
67 self.vertical = vertical |
600
32dbbc941123
browser_side: fixes the contact group manager
souliane <souliane@mailoo.org>
parents:
589
diff
changeset
|
68 self.style = {"selected": None, "menu": "itemKeyMenu", "item": "popupMenuItem"} |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
69 if isinstance(style, dict): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
70 self.style.update(style) |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
71 self.senders = {} |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
72 |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
73 def showMenu(self, sender): |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
74 """Popup the menu on the screen, where it fits to the sender's position. |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
75 |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
76 @param sender (Widget): the widget that has been clicked |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
77 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
78 menu = VerticalPanel() if self.vertical is True else HorizontalPanel() |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
79 menu.setStyleName(self.style["menu"]) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
80 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
81 def button_cb(item): |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
82 # XXX: you can not put that method in the loop and rely on key |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
83 if self.callback is not None: |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
84 self.callback(sender=sender, key=item.key) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
85 self.hide(autoClosed=True) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
86 |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
87 for key, entry in self.entries.iteritems(): |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
88 if self.hideMenu is not None and self.hideMenu(sender=sender, key=key) is True: |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
89 continue |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
90 title = entry.get("title", key) |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
91 item = Button(title, button_cb, StyleName=self.style["item"]) |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
92 item.key = key # XXX: copy the key because we loop on it and it will change |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
93 item.setTitle(entry.get("desc", title)) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
94 menu.add(item) |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
95 |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
96 if menu.getWidgetCount() == 0: |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
97 return # no item to display means no menu at all |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
98 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
99 self.add(menu) |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
100 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
101 if self.vertical is True: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
102 x = sender.getAbsoluteLeft() + sender.getOffsetWidth() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
103 y = sender.getAbsoluteTop() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
104 else: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
105 x = sender.getAbsoluteLeft() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
106 y = sender.getAbsoluteTop() + sender.getOffsetHeight() |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
107 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
108 self.setPopupPosition(x, y) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
109 self.show() |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
110 |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
111 if self.style["selected"]: |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
112 sender.addStyleDependentName(self.style["selected"]) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
113 |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
114 def onHide(popup): |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
115 if self.style["selected"]: |
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
116 sender.removeStyleDependentName(self.style["selected"]) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
117 return PopupPanel.onHideImpl(self, popup) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
118 |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
119 self.onHideImpl = onHide |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
120 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
121 def registerClickSender(self, sender, button=BUTTON_LEFT): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
122 """Bind the menu to the specified sender. |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
123 |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
124 @param sender (Widget): bind the menu to this widget |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
125 @param (int): BUTTON_LEFT, BUTTON_MIDDLE or BUTTON_RIGHT |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
126 """ |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
127 self.senders.setdefault(sender, []) |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
128 self.senders[sender].append(button) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
129 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
130 if button == BUTTON_RIGHT: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
131 # WARNING: to disable the context menu is a bit tricky... |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
132 # The following seems to work on Firefox 24.0, but: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
133 # TODO: find a cleaner way to disable the context menu |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
134 sender.getElement().setAttribute("oncontextmenu", "return false") |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
135 |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
136 def onBrowserEvent(event): |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
137 button = DOM.eventGetButton(event) |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
138 if DOM.eventGetType(event) == "mousedown" and button in self.senders[sender]: |
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
139 self.showMenu(sender) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
140 return sender.__class__.onBrowserEvent(sender, event) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
141 |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
142 sender.onBrowserEvent = onBrowserEvent |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
143 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
144 def registerMiddleClickSender(self, sender): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
145 self.registerClickSender(sender, BUTTON_MIDDLE) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
146 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
147 def registerRightClickSender(self, sender): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
148 self.registerClickSender(sender, BUTTON_RIGHT) |
264
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
149 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
150 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
151 ### Generic panels ### |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
152 |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
153 |
264
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
154 class ToggleStackPanel(StackPanel): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
155 """This is a pyjamas.ui.StackPanel with modified behavior. All sub-panels ca be |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
156 visible at the same time, clicking a sub-panel header will not display it and hide |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
157 the others but only toggle its own visibility. The argument 'visibleStack' is ignored. |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
158 Note that the argument 'visible' has been added to listener's 'onStackChanged' method. |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
159 """ |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
160 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
161 def __init__(self, **kwargs): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
162 StackPanel.__init__(self, **kwargs) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
163 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
164 def onBrowserEvent(self, event): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
165 if DOM.eventGetType(event) == "click": |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
166 index = self.getDividerIndex(DOM.eventGetTarget(event)) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
167 if index != -1: |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
168 self.toggleStack(index) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
169 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
170 def add(self, widget, stackText="", asHTML=False, visible=False): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
171 StackPanel.add(self, widget, stackText, asHTML) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
172 self.setStackVisible(self.getWidgetCount() - 1, visible) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
173 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
174 def toggleStack(self, index): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
175 if index >= self.getWidgetCount(): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
176 return |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
177 visible = not self.getWidget(index).getVisible() |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
178 self.setStackVisible(index, visible) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
179 for listener in self.stackListeners: |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
180 listener.onStackChanged(self, index, visible) |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
181 |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
182 |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
183 class TitlePanel(ToggleStackPanel): |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
184 """A toggle panel to set the message title""" |
739
4545d48dee60
browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents:
735
diff
changeset
|
185 |
4545d48dee60
browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents:
735
diff
changeset
|
186 TITLE = _("Title") |
4545d48dee60
browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents:
735
diff
changeset
|
187 |
4545d48dee60
browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents:
735
diff
changeset
|
188 def __init__(self, text=None): |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
189 ToggleStackPanel.__init__(self, Width="100%") |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
190 self.text_area = TextArea() |
739
4545d48dee60
browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents:
735
diff
changeset
|
191 self.add(self.text_area, self.TITLE) |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
192 self.addStackChangeListener(self) |
739
4545d48dee60
browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents:
735
diff
changeset
|
193 if text: |
4545d48dee60
browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents:
735
diff
changeset
|
194 self.setText(text) |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
195 |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
196 def onStackChanged(self, sender, index, visible=None): |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
197 if visible is None: |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
198 visible = sender.getWidget(index).getVisible() |
739
4545d48dee60
browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents:
735
diff
changeset
|
199 text = self.getText() |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
200 suffix = "" if (visible or not text) else (": %s" % text) |
739
4545d48dee60
browser_side: improve ListPanel and TitlePanel
souliane <souliane@mailoo.org>
parents:
735
diff
changeset
|
201 sender.setStackText(index, self.TITLE + suffix) |
346
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
202 |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
203 def getText(self): |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
204 return self.text_area.getText() |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
205 |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
206 def setText(self, text): |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
207 self.text_area.setText(text) |
347
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
208 |
f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
souliane <souliane@mailoo.org>
parents:
346
diff
changeset
|
209 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
210 class ScrollPanelWrapper(SimplePanel): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
211 """Scroll Panel like component, wich use the full available space |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
212 to work around percent size issue, it use some of the ideas found |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
213 here: http://code.google.com/p/google-web-toolkit/issues/detail?id=316 |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
214 specially in code given at comment #46, thanks to Stefan Bachert""" |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
215 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
216 def __init__(self, *args, **kwargs): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
217 SimplePanel.__init__(self) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
218 self.spanel = ScrollPanel(*args, **kwargs) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
219 SimplePanel.setWidget(self, self.spanel) |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
220 DOM.setStyleAttribute(self.getElement(), "position", "relative") |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
221 DOM.setStyleAttribute(self.getElement(), "top", "0px") |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
222 DOM.setStyleAttribute(self.getElement(), "left", "0px") |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
223 DOM.setStyleAttribute(self.getElement(), "width", "100%") |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
224 DOM.setStyleAttribute(self.getElement(), "height", "100%") |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
225 DOM.setStyleAttribute(self.spanel.getElement(), "position", "absolute") |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
226 DOM.setStyleAttribute(self.spanel.getElement(), "width", "100%") |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
227 DOM.setStyleAttribute(self.spanel.getElement(), "height", "100%") |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
228 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
229 def setWidget(self, widget): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
230 self.spanel.setWidget(widget) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
231 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
232 def setScrollPosition(self, position): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
233 self.spanel.setScrollPosition(position) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
234 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
235 def scrollToBottom(self): |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
236 self.setScrollPosition(self.spanel.getElement().scrollHeight) |