Mercurial > libervia-web
annotate src/browser/sat_browser/base_panels.py @ 573:12823bcbd05b
browser_side: display MUC occupants presences
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 17 Oct 2014 13:26:33 +0200 |
parents | c97fe4059f71 |
children | e1a773a64fb6 |
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 |
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:
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 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
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:
433
diff
changeset
|
21 from sat.core.log import getLogger |
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
22 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
|
23 from sat.core.i18n import _ |
467 | 24 from sat_frontends.tools import strings |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
439
diff
changeset
|
25 |
33 | 26 from pyjamas.ui.AbsolutePanel import AbsolutePanel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from pyjamas.ui.VerticalPanel import VerticalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from pyjamas.ui.HTMLPanel import HTMLPanel |
83 | 30 from pyjamas.ui.Button import Button |
33 | 31 from pyjamas.ui.HTML import HTML |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
32 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
|
33 from pyjamas.ui.PopupPanel import PopupPanel |
264
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
34 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
|
35 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
|
36 from pyjamas.ui.Event import BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT |
412
9977de10b7da
browser_side: editors do not listen for <escape> + display WYSIWIG in upper case
souliane <souliane@mailoo.org>
parents:
407
diff
changeset
|
37 from pyjamas.ui.KeyboardListener import KEY_ENTER, KEY_SHIFT, KeyboardHandler |
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
|
38 from pyjamas.ui.FocusListener import FocusHandler |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
39 from pyjamas.ui.ClickListener import ClickHandler |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 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
|
41 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 from datetime import datetime |
19 | 43 from time import time |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
279
diff
changeset
|
44 |
467 | 45 import html_tools |
433
bbdbee25123a
import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents:
412
diff
changeset
|
46 from constants import Const as C |
20 | 47 |
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
|
48 |
19 | 49 class ChatText(HTMLPanel): |
50 | |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
51 def __init__(self, timestamp, nick, mymess, msg, xhtml=None): |
19 | 52 _date = datetime.fromtimestamp(float(timestamp or time())) |
53 _msg_class = ["chat_text_msg"] | |
54 if mymess: | |
55 _msg_class.append("chat_text_mymess") | |
56 HTMLPanel.__init__(self, "<span class='chat_text_timestamp'>%(timestamp)s</span> <span class='chat_text_nick'>%(nick)s</span> <span class='%(msg_class)s'>%(msg)s</span>" % | |
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
|
57 {"timestamp": _date.strftime("%H:%M"), |
468
830b50593597
browser_side: fixes issues from the refactoring
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
58 "nick": "[%s]" % html_tools.html_sanitize(nick), |
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
|
59 "msg_class": ' '.join(_msg_class), |
468
830b50593597
browser_side: fixes issues from the refactoring
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
60 "msg": strings.addURLToText(html_tools.html_sanitize(msg)) if not xhtml else html_tools.inlineRoot(xhtml)} # FIXME: images and external links must be removed according to preferences |
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
|
61 ) |
19 | 62 self.setStyleName('chatText') |
33 | 63 |
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
|
64 |
33 | 65 class Occupant(HTML): |
66 """Occupant of a MUC room""" | |
67 | |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
68 def __init__(self, nick, state=None, special=""): |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
69 """ |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
70 @param nick: the user nickname |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
71 @param state: the user chate state (XEP-0085) |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
72 @param special: a string of symbols (e.g: for activities) |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
73 """ |
573
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
74 HTML.__init__(self, StyleName="occupant") |
33 | 75 self.nick = nick |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
76 self._state = state |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
77 self.special = special |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
78 self._refresh() |
35 | 79 |
80 def __str__(self): | |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
81 return self.nick |
33 | 82 |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
83 def setState(self, state): |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
84 self._state = state |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
85 self._refresh() |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
405
diff
changeset
|
86 |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
87 def addSpecial(self, special): |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
88 """@param special: unicode""" |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
89 if special not in self.special: |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
90 self.special += special |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
91 self._refresh() |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
92 |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
93 def removeSpecials(self, special): |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
94 """@param special: unicode or list""" |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
95 if not isinstance(special, list): |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
96 special = [special] |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
97 for symbol in special: |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
98 self.special = self.special.replace(symbol, "") |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
99 self._refresh() |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
100 |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
101 def _refresh(self): |
433
bbdbee25123a
import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents:
412
diff
changeset
|
102 state = (' %s' % C.MUC_USER_STATES[self._state]) if self._state else '' |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
103 special = "" if len(self.special) == 0 else " %s" % self.special |
573
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
104 self.setHTML("%s%s%s" % (html_tools.html_sanitize(self.nick), special, state)) |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
105 |
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
|
106 |
33 | 107 class OccupantsList(AbsolutePanel): |
108 """Panel user to show occupants of a room""" | |
109 | |
110 def __init__(self): | |
111 AbsolutePanel.__init__(self) | |
35 | 112 self.occupants_list = {} |
33 | 113 self.setStyleName('occupantsList') |
114 | |
115 def addOccupant(self, nick): | |
35 | 116 _occupant = Occupant(nick) |
117 self.occupants_list[nick] = _occupant | |
118 self.add(_occupant) | |
33 | 119 |
35 | 120 def removeOccupant(self, nick): |
121 try: | |
122 self.remove(self.occupants_list[nick]) | |
123 except KeyError: | |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
124 log.error("trying to remove an unexisting nick") |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
125 |
573
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
126 def getOccupantBox(self, nick): |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
127 """Get the widget element of the given nick. |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
128 |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
129 @return: Occupant |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
130 """ |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
131 return self.occupants_list[nick] |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
491
diff
changeset
|
132 |
35 | 133 def clear(self): |
134 self.occupants_list.clear() | |
135 AbsolutePanel.clear(self) | |
136 | |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
137 def updateSpecials(self, occupants=[], html=""): |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
138 """Set the specified html "symbol" to the listed occupants, |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
139 and eventually remove it from the others (if they got it). |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
140 This is used for example to visualize who is playing a game. |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
141 @param occupants: list of the occupants that need the symbol |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
142 @param html: unicode symbol (actually one character or more) |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
143 or a list to assign different symbols of the same family. |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
144 """ |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
145 index = 0 |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
146 special = html |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
147 for occupant in self.occupants_list.keys(): |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
148 if occupant in occupants: |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
149 if isinstance(html, list): |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
150 special = html[index] |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
151 index = (index + 1) % len(html) |
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
152 self.occupants_list[occupant].addSpecial(special) |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
153 else: |
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
154 self.occupants_list[occupant].removeSpecials(html) |
273
11718798ab8a
browser_side: can identify muc members with symbols
souliane <souliane@mailoo.org>
parents:
269
diff
changeset
|
155 |
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
|
156 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
157 class PopupMenuPanel(PopupPanel): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
158 """This implementation of a popup menu (context menu) allow you to assign |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
159 two special methods which are common to all the items, in order to hide |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
160 certain items and also easily define their callbacks. The menu can be |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
161 bound to any of the mouse button (left, middle, right). |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
162 """ |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
163 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
|
164 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
165 @param entries: a dict of dicts, where each sub-dict is representing |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
166 one menu item: the sub-dict key can be used as the item text and |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
167 description, but optional "title" and "desc" entries would be used |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
168 if they exists. The sub-dicts may be extended later to do |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
169 more complicated stuff or overwrite the common methods. |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
170 @param hide: function with 2 args: widget, key as string and |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
171 returns True if that item should be hidden from the context menu. |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
172 @param callback: function with 2 args: sender, key as string |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
173 @param vertical: True or False, to set the direction |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
174 @param item_style: alternative CSS class for the menu items |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
175 @param menu_style: supplementary CSS class for the sender widget |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
176 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
177 PopupPanel.__init__(self, autoHide=True, **kwargs) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
178 self._entries = entries |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
179 self._hide = hide |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
180 self._callback = callback |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
181 self.vertical = vertical |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
182 self.style = {"selected": None, "menu": "recipientTypeMenu", "item": "popupMenuItem"} |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
183 if isinstance(style, dict): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
184 self.style.update(style) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
185 self._senders = {} |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
186 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
187 def _show(self, sender): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
188 """Popup the menu relative to this sender's position. |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
189 @param sender: the widget that has been clicked |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
190 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
191 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
|
192 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
|
193 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
194 def button_cb(item): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
195 """You can not put that method in the loop and rely |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
196 on _key, because it is overwritten by each step. |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
197 You can rely on item.key instead, which is copied |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
198 from _key after the item creation. |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
199 @param item: the menu item that has been clicked |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
200 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
201 if self._callback is not None: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
202 self._callback(sender=sender, key=item.key) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
203 self.hide(autoClosed=True) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
204 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
205 for _key in self._entries.keys(): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
206 entry = self._entries[_key] |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
207 if self._hide is not None and self._hide(sender=sender, key=_key) is True: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
208 continue |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
209 title = entry["title"] if "title" in entry.keys() else _key |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
210 item = Button(title, button_cb) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
211 item.key = _key |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
212 item.setStyleName(self.style["item"]) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
213 item.setTitle(entry["desc"] if "desc" in entry.keys() else title) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
214 menu.add(item) |
242
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
215 if len(menu.getChildren()) == 0: |
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
216 return |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
217 self.add(menu) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
218 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
|
219 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
|
220 y = sender.getAbsoluteTop() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
221 else: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
222 x = sender.getAbsoluteLeft() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
223 y = sender.getAbsoluteTop() + sender.getOffsetHeight() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
224 self.setPopupPosition(x, y) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
225 self.show() |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
226 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
|
227 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
|
228 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 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
|
233 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
234 self.onHideImpl = _onHide |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
235 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
236 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
|
237 """Bind the menu to the specified sender. |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
238 @param sender: the widget to which the menu should be bound |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
239 @param: BUTTON_LEFT, BUTTON_MIDDLE or BUTTON_RIGHT |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
240 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
241 self._senders.setdefault(sender, []) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
242 self._senders[sender].append(button) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
243 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
244 if button == BUTTON_RIGHT: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
245 # 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
|
246 # 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
|
247 # 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
|
248 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
|
249 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
250 def _onBrowserEvent(event): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
251 button = DOM.eventGetButton(event) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
252 if DOM.eventGetType(event) == "mousedown" and button in self._senders[sender]: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
253 self._show(sender) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
254 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
|
255 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
256 sender.onBrowserEvent = _onBrowserEvent |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
257 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
258 def registerMiddleClickSender(self, sender): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
259 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
|
260 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
261 def registerRightClickSender(self, sender): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
262 self.registerClickSender(sender, BUTTON_RIGHT) |
264
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
263 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
264 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
265 class ToggleStackPanel(StackPanel): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
266 """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
|
267 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
|
268 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
|
269 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
|
270 """ |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
271 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
272 def __init__(self, **kwargs): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
273 StackPanel.__init__(self, **kwargs) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
274 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
275 def onBrowserEvent(self, event): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
276 if DOM.eventGetType(event) == "click": |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
277 index = self.getDividerIndex(DOM.eventGetTarget(event)) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
278 if index != -1: |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
279 self.toggleStack(index) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
280 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
281 def add(self, widget, stackText="", asHTML=False, visible=False): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
282 StackPanel.add(self, widget, stackText, asHTML) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
283 self.setStackVisible(self.getWidgetCount() - 1, visible) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
284 |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
285 def toggleStack(self, index): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
286 if index >= self.getWidgetCount(): |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
287 return |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
288 visible = not self.getWidget(index).getVisible() |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
289 self.setStackVisible(index, visible) |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
290 for listener in self.stackListeners: |
2a93f8e6f989
browser_side: added class ToggleStackPanel
souliane <souliane@mailoo.org>
parents:
261
diff
changeset
|
291 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
|
292 |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
293 |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
294 class TitlePanel(ToggleStackPanel): |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
295 """A toggle panel to set the message title""" |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
296 def __init__(self): |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
297 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
|
298 self.text_area = TextArea() |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
299 self.add(self.text_area, _("Title")) |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
300 self.addStackChangeListener(self) |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
301 |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
302 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
|
303 if visible is None: |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
304 visible = sender.getWidget(index).getVisible() |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
305 text = self.text_area.getText() |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
306 suffix = "" if (visible or not text) else (": %s" % text) |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
307 sender.setStackText(index, _("Title") + suffix) |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
308 |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
309 def getText(self): |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
310 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
|
311 |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
312 def setText(self, text): |
82f9e92379b0
browser_side: move TitlePanel from richtext.py to base_panels.py
souliane <souliane@mailoo.org>
parents:
342
diff
changeset
|
313 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
|
314 |
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
|
315 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
316 class BaseTextEditor(object): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
317 """Basic definition of a text editor. The method edit gets a boolean parameter which |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
318 should be set to True when you want to edit the text and False to only display it.""" |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
319 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
320 def __init__(self, content=None, strproc=None, modifiedCb=None, afterEditCb=None): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
321 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
322 Remark when inheriting this class: since the setContent method could be |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
323 overwritten by the child class, you should consider calling this __init__ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
324 after all the parameters affecting this setContent method have been set. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
325 @param content: dict with at least a 'text' key |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
326 @param strproc: method to be applied on strings to clean the content |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
327 @param modifiedCb: method to be called when the text has been modified. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
328 If this method returns: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
329 - True: the modification will be saved and afterEditCb called; |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
330 - False: the modification won't be saved and afterEditCb called; |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
331 - None: the modification won't be saved and afterEditCb not called. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
332 @param afterEditCb: method to be called when the edition is done |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
333 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
334 if content is None: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
335 content = {'text': ''} |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
336 assert('text' in content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
337 if strproc is None: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
338 def strproc(text): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
339 try: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
340 return text.strip() |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
341 except (TypeError, AttributeError): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
342 return text |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
343 self.strproc = strproc |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
344 self.__modifiedCb = modifiedCb |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
345 self._afterEditCb = afterEditCb |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
346 self.initialized = False |
362
019e1e706e74
browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents:
358
diff
changeset
|
347 self.edit_listeners = [] |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
348 self.setContent(content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
349 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
350 def setContent(self, content=None): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
351 """Set the editable content. The displayed content, which is set from the child class, could differ. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
352 @param content: dict with at least a 'text' key |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
353 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
354 if content is None: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
355 content = {'text': ''} |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
356 elif not isinstance(content, dict): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
357 content = {'text': content} |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
358 assert('text' in content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
359 self._original_content = {} |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
360 for key in content: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
361 self._original_content[key] = self.strproc(content[key]) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
362 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
363 def getContent(self): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
364 """Get the current edited or editable content. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
365 @return: dict with at least a 'text' key |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
366 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
367 raise NotImplementedError |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
368 |
395
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
369 def setOriginalContent(self, content): |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
370 """Use this method with care! Content initialization should normally be |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
371 done with self.setContent. This method exists to let you trick the editor, |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
372 e.g. for self.modified to return True also when nothing has been modified. |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
373 @param content: dict |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
374 """ |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
375 self._original_content = content |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
376 |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
377 def getOriginalContent(self): |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
378 """ |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
379 @return the original content before modification (dict) |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
380 """ |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
381 return self._original_content |
98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents:
370
diff
changeset
|
382 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
383 def modified(self, content=None): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
384 """Check if the content has been modified. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
385 Remark: we don't use the direct comparison because we want to ignore empty elements |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
386 @content: content to be check against the original content or None to use the current content |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
387 @return: True if the content has been modified. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
388 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
389 if content is None: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
390 content = self.getContent() |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
391 # the following method returns True if one non empty element exists in a but not in b |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
392 diff1 = lambda a, b: [a[key] for key in set(a.keys()).difference(b.keys()) if a[key]] != [] |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
393 # the following method returns True if the values for the common keys are not equals |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
394 diff2 = lambda a, b: [1 for key in set(a.keys()).intersection(b.keys()) if a[key] != b[key]] != [] |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
395 # finally the combination of both to return True if a difference is found |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
396 diff = lambda a, b: diff1(a, b) or diff1(b, a) or diff2(a, b) |
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
|
397 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
398 return diff(content, self._original_content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
399 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
400 def edit(self, edit, abort=False, sync=False): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
401 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
402 Remark: the editor must be visible before you call this method. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
403 @param edit: set to True to edit the content or False to only display it |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
404 @param abort: set to True to cancel the edition and loose the changes. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
405 If edit and abort are both True, self.abortEdition can be used to ask for a |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
406 confirmation. When edit is False and abort is True, abortion is actually done. |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
407 @param sync: set to True to cancel the edition after the content has been saved somewhere else |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
408 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
409 if edit: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
410 if not self.initialized: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
411 self.syncToEditor() # e.g.: use the selected target and unibox content |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
412 self.setFocus(True) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
413 if abort: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
414 content = self.getContent() |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
415 if not self.modified(content) or self.abortEdition(content): # e.g: ask for confirmation |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
416 self.edit(False, True, sync) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
417 return |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
418 if sync: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
419 self.syncFromEditor(content) # e.g.: save the content to unibox |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
420 return |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
421 else: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
422 if not self.initialized: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
423 return |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
424 content = self.getContent() |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
425 if abort: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
426 self._afterEditCb(content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
427 return |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
428 if self.__modifiedCb and self.modified(content): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
429 result = self.__modifiedCb(content) # e.g.: send a message or update something |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
430 if result is not None: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
431 if self._afterEditCb: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
432 self._afterEditCb(content) # e.g.: restore the display mode |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
433 if result is True: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
434 self.setContent(content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
435 elif self._afterEditCb: |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
436 self._afterEditCb(content) |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
437 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
438 self.initialized = True |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
439 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
440 def setFocus(self, focus): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
441 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
442 @param focus: set to True to focus the editor |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
443 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
444 raise NotImplementedError |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
445 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
446 def syncToEditor(self): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
447 pass |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
448 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
449 def syncFromEditor(self, content): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
450 pass |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
451 |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
452 def abortEdition(self, content): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
453 return True |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
454 |
362
019e1e706e74
browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents:
358
diff
changeset
|
455 def addEditListener(self, listener): |
019e1e706e74
browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents:
358
diff
changeset
|
456 """Add a method to be called whenever the text is edited. |
019e1e706e74
browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents:
358
diff
changeset
|
457 @param listener: method taking two arguments: sender, keycode""" |
019e1e706e74
browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents:
358
diff
changeset
|
458 self.edit_listeners.append(listener) |
019e1e706e74
browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents:
358
diff
changeset
|
459 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
460 |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
461 class SimpleTextEditor(BaseTextEditor, FocusHandler, KeyboardHandler, ClickHandler): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
462 """Base class for manage a simple text editor.""" |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
463 |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
464 def __init__(self, content=None, modifiedCb=None, afterEditCb=None, options=None): |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
465 """ |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
466 @param content |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
467 @param modifiedCb |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
468 @param afterEditCb |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
469 @param options: dict with the following value: |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
470 - no_xhtml: set to True to clean any xhtml content. |
467 | 471 - enhance_display: if True, the display text will be enhanced with strings.addURLToText |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
472 - listen_keyboard: set to True to terminate the edition with <enter> or <escape>. |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
473 - listen_focus: set to True to terminate the edition when the focus is lost. |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
474 - listen_click: set to True to start the edition when you click on the widget. |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
475 """ |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
476 self.options = {'no_xhtml': False, |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
477 'enhance_display': True, |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
478 'listen_keyboard': True, |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
479 'listen_focus': False, |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
480 'listen_click': False |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
481 } |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
482 if options: |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
483 self.options.update(options) |
403
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
484 self.__shift_down = False |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
485 if self.options['listen_focus']: |
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
|
486 FocusHandler.__init__(self) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
487 if self.options['listen_click']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
488 ClickHandler.__init__(self) |
362
019e1e706e74
browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents:
358
diff
changeset
|
489 KeyboardHandler.__init__(self) |
468
830b50593597
browser_side: fixes issues from the refactoring
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
490 strproc = lambda text: html_tools.html_sanitize(html_tools.html_strip(text)) if self.options['no_xhtml'] else html_tools.html_strip(text) |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
491 BaseTextEditor.__init__(self, content, strproc, modifiedCb, afterEditCb) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
492 self.textarea = self.display = None |
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
|
493 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
494 def setContent(self, content=None): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
495 BaseTextEditor.setContent(self, content) |
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
|
496 |
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
|
497 def getContent(self): |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
498 raise NotImplementedError |
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
|
499 |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
500 def edit(self, edit, abort=False, sync=False): |
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
501 BaseTextEditor.edit(self, edit) |
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
|
502 if edit: |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
503 if self.options['listen_focus'] and self not in self.textarea._focusListeners: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
504 self.textarea.addFocusListener(self) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
505 if self.options['listen_click']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
506 self.display.clearClickListener() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
507 if self not in self.textarea._keyboardListeners: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
508 self.textarea.addKeyboardListener(self) |
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
|
509 else: |
349
f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents:
347
diff
changeset
|
510 self.setDisplayContent() |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
511 if self.options['listen_focus']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
512 try: |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
513 self.textarea.removeFocusListener(self) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
514 except ValueError: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
515 pass |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
516 if self.options['listen_click'] and self not in self.display._clickListeners: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
517 self.display.addClickListener(self) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
518 try: |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
519 self.textarea.removeKeyboardListener(self) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
520 except ValueError: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
521 pass |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
522 |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
523 def setDisplayContent(self): |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
524 text = self._original_content['text'] |
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
525 if not self.options['no_xhtml']: |
467 | 526 text = strings.addURLToImage(text) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
527 if self.options['enhance_display']: |
467 | 528 text = strings.addURLToText(text) |
529 self.display.setHTML(html_tools.convertNewLinesToXHTML(text)) | |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
530 |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
531 def setFocus(self, focus): |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
532 raise NotImplementedError |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
533 |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
534 def onKeyDown(self, sender, keycode, modifiers): |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
535 for listener in self.edit_listeners: |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
536 listener(self.textarea, keycode) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
537 if not self.options['listen_keyboard']: |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
538 return |
403
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
539 if keycode == KEY_SHIFT or self.__shift_down: # allow input a new line with <shift> + <enter> |
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
540 self.__shift_down = True |
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
541 return |
412
9977de10b7da
browser_side: editors do not listen for <escape> + display WYSIWIG in upper case
souliane <souliane@mailoo.org>
parents:
407
diff
changeset
|
542 if keycode == KEY_ENTER: # finish the edition |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
543 self.textarea.setFocus(False) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
544 if not self.options['listen_focus']: |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
545 self.edit(False) |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
546 |
403
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
547 def onKeyUp(self, sender, keycode, modifiers): |
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
548 if keycode == KEY_SHIFT: |
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
549 self.__shift_down = False |
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
550 |
401
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
551 def onLostFocus(self, sender): |
ea03f898067f
browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents:
400
diff
changeset
|
552 """Finish the edition when focus is lost""" |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
553 if self.options['listen_focus']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
554 self.edit(False) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
555 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
556 def onClick(self, sender=None): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
557 """Start the edition when the widget is clicked""" |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
558 if self.options['listen_click']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
559 self.edit(True) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
560 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
561 def onBrowserEvent(self, event): |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
562 if self.options['listen_focus']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
563 FocusHandler.onBrowserEvent(self, event) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
564 if self.options['listen_click']: |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
565 ClickHandler.onBrowserEvent(self, event) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
566 KeyboardHandler.onBrowserEvent(self, event) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
567 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
568 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
569 class HTMLTextEditor(SimpleTextEditor, HTML, FocusHandler, KeyboardHandler): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
570 """Manage a simple text editor with the HTML 5 "contenteditable" property.""" |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
571 |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
572 def __init__(self, content=None, modifiedCb=None, afterEditCb=None, options=None): |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
573 HTML.__init__(self) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
574 SimpleTextEditor.__init__(self, content, modifiedCb, afterEditCb, options) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
575 self.textarea = self.display = self |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
576 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
577 def getContent(self): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
578 text = DOM.getInnerHTML(self.getElement()) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
579 return {'text': self.strproc(text) if text else ''} |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
580 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
581 def edit(self, edit, abort=False, sync=False): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
582 if edit: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
583 self.textarea.setHTML(self._original_content['text']) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
584 self.getElement().setAttribute('contenteditable', 'true' if edit else 'false') |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
585 SimpleTextEditor.edit(self, edit, abort, sync) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
586 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
587 def setFocus(self, focus): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
588 if focus: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
589 self.getElement().focus() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
590 else: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
591 self.getElement().blur() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
592 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
593 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
594 class LightTextEditor(SimpleTextEditor, SimplePanel, FocusHandler, KeyboardHandler): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
595 """Manage a simple text editor with a TextArea for editing, HTML for display.""" |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
596 |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
597 def __init__(self, content=None, modifiedCb=None, afterEditCb=None, options=None): |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
598 SimplePanel.__init__(self) |
404
c393e7dc9ae6
browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents:
403
diff
changeset
|
599 SimpleTextEditor.__init__(self, content, modifiedCb, afterEditCb, options) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
600 self.textarea = TextArea() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
601 self.display = HTML() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
602 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
603 def getContent(self): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
604 text = self.textarea.getText() |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
605 return {'text': self.strproc(text) if text else ''} |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
606 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
607 def edit(self, edit, abort=False, sync=False): |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
608 if edit: |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
609 self.textarea.setText(self._original_content['text']) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
610 self.setWidget(self.textarea if edit else self.display) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
611 SimpleTextEditor.edit(self, edit, abort, sync) |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
612 |
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
613 def setFocus(self, focus): |
491
c97fe4059f71
browser side: fixes NS_ERROR_FAILURE while opening microblog panels (bug from rev 442 - changeset 17259c2ff96f in MicroblogPanel.refresh)
souliane <souliane@mailoo.org>
parents:
468
diff
changeset
|
614 if focus and self.isAttached(): |
403
ec6f7581b453
browser_side: microblogs edition: <shift> + <enter> makes a new line, <esc> finishes the edition
souliane <souliane@mailoo.org>
parents:
402
diff
changeset
|
615 self.textarea.setCursorPos(len(self.textarea.getText())) |
402
d7e78cb78dfc
browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents:
401
diff
changeset
|
616 self.textarea.setFocus(focus) |