Mercurial > libervia-web
annotate browser_side/panels.py @ 255:da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
- group and contact lists are sorted
- avoid adding empty group in the "Add group" panel
- allow to show/hide the contact panel from another class
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 09 Nov 2013 15:31:39 +0100 |
parents | c24715dcd2f6 |
children | 533d68585866 |
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 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
165 | 6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org> |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
22 import pyjd # this is dummy in pyjs |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from pyjamas.ui.SimplePanel import SimplePanel |
33 | 24 from pyjamas.ui.AbsolutePanel import AbsolutePanel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from pyjamas.ui.VerticalPanel import VerticalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
27 from pyjamas.ui.DialogBox import DialogBox |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from pyjamas.ui.HTMLPanel import HTMLPanel |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
29 from pyjamas.ui.Frame import Frame |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
30 from pyjamas.ui.TextArea import TextArea |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from pyjamas.ui.Label import Label |
83 | 32 from pyjamas.ui.Button import Button |
33 | 33 from pyjamas.ui.HTML import HTML |
83 | 34 from pyjamas.ui.Image import Image |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
35 from pyjamas.ui.PopupPanel import PopupPanel |
19 | 36 from pyjamas.ui.ClickListener import ClickHandler |
239
b911f2b43fd4
browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents:
235
diff
changeset
|
37 from pyjamas.ui.KeyboardListener import KEY_ENTER, KEY_UP, KEY_DOWN |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
38 from pyjamas.ui.Event import BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
39 from pyjamas.ui.MouseListener import MouseHandler |
33 | 40 from pyjamas.Timer import Timer |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 from pyjamas import DOM |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
42 from card_game import CardPanel |
127 | 43 from radiocol import RadioColPanel |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
44 from menu import Menu |
19 | 45 from jid import JID |
246
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
242
diff
changeset
|
46 from tools import html_sanitize, addURLToText, inlineRoot |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 from datetime import datetime |
19 | 48 from time import time |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
49 import dialog |
195 | 50 import base_widget |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
51 from richtext import RichTextEditor |
223
624a87377412
browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents:
218
diff
changeset
|
52 from plugin_xep_0085 import ChatStateMachine |
195 | 53 from pyjamas import Window |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
54 from __pyjamas__ import doc |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
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
|
56 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
57 class UniBoxPanel(HorizontalPanel): |
33 | 58 """Panel containing the UniBox""" |
59 | |
60 def __init__(self, host): | |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
61 HorizontalPanel.__init__(self) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
62 self.host = host |
33 | 63 self.setStyleName('uniBoxPanel') |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
64 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
65 self.button = Button ('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>') |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
66 self.button.setTitle('Open the rich text editor') |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
67 self.button.addStyleName('uniBoxButton') |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
68 self.add(self.button) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
69 |
33 | 70 self.unibox = UniBox(host) |
71 self.add(self.unibox) | |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
72 self.setCellWidth(self.unibox, '100%') |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
73 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
74 self.button.addClickListener(self.openRichTextEditor) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
75 self.unibox.addDoubleClickListener(self.openRichTextEditor) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
76 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
77 def openRichTextEditor(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
78 """Open the rich text editor.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
79 self.button.setVisible(False) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
80 self.unibox.setVisible(False) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
81 self.setCellWidth(self.unibox, '0px') |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
82 self.host.panel._contactsMove(self) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
83 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
84 def onCloseCallback(): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
85 self.host.panel._contactsMove(self.host.panel._hpanel) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
86 self.setCellWidth(self.unibox, '100%') |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
87 self.button.setVisible(True) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
88 self.unibox.setVisible(True) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
89 self.host.resize() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
90 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
91 RichTextEditor.getOrCreate(self.host, self, onCloseCallback) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
92 self.host.resize() |
33 | 93 |
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
|
94 |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
95 class UniBox(TextArea, MouseHandler): #AutoCompleteTextBox): |
33 | 96 """This text box is used as a main typing point, for message, microblog, etc""" |
97 | |
98 def __init__(self, host): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
99 TextArea.__init__(self) |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
100 #AutoCompleteTextBox.__init__(self) |
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
|
101 self.__size = (0, 0) |
33 | 102 self._popup = None |
103 self._timer = Timer(notify=self._timeCb) | |
104 self.host = host | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
105 self.setStyleName('uniBox') |
83 | 106 self.addKeyboardListener(self) |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
107 MouseHandler.__init__(self) |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
108 self.addMouseListener(self) |
193
f2ae8e170c49
browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
109 self._selected_cache = None |
f2ae8e170c49
browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
110 host.addSelectedListener(self.onSelectedChange) |
33 | 111 |
112 def addKey(self, key): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
113 return |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
114 #self.getCompletionItems().completions.append(key) |
33 | 115 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
116 def removeKey(self, key): |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
117 return |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
118 # TODO: investigate why AutoCompleteTextBox doesn't work here, |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
119 # maybe it can work on a TextBox but no TextArea. Remove addKey |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
120 # and removeKey methods if they don't serve anymore. |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
121 try: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
122 self.getCompletionItems().completions.remove(key) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
123 except KeyError: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
124 print "WARNING: trying to remove an unknown key" |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
125 |
33 | 126 def showWarning(self, target_data): |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
127 target_hook, _type, msg = target_data |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
128 if _type == "NONE": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
129 return |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
130 if not msg: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
131 print "WARNING: no msg set uniBox warning" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
132 return |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
133 if _type == "PUBLIC": |
33 | 134 style = "targetPublic" |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
135 elif _type == "GROUP": |
33 | 136 style = "targetGroup" |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
137 elif _type == "STATUS": |
33 | 138 msg = "This will be your new status message" |
139 style = "targetStatus" | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
140 elif _type == "ONE2ONE": |
33 | 141 style = "targetOne2One" |
142 else: | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
143 print "ERROR: unknown message type" |
33 | 144 return |
145 contents = HTML(msg) | |
146 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
147 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
33 | 148 self._popup.target_data = target_data |
149 self._popup.add(contents) | |
150 self._popup.setStyleName("warningPopup") | |
151 if style: | |
152 self._popup.addStyleName(style) | |
153 | |
154 left = 0 | |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
155 top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) |
33 | 156 self._popup.setPopupPosition(left, top) |
157 self._popup.show() | |
158 | |
159 def _timeCb(self, timer): | |
160 if self._popup: | |
161 self._popup.hide() | |
162 del self._popup | |
163 self._popup = None | |
164 | |
165 def _getTarget(self, txt): | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
166 """ Say who will receive the messsage |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
167 @return: a tuple (selected, target_type, target info) with: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
168 - target_hook: None if we use the selected widget, (msg, data) if we have a hook (e.g. "@@: " for a public blog), where msg is the parsed message (i.e. without the "hook key: "@@: bla" become ("bla", None)) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
169 - target_type: one of PUBLIC, GROUP, ONE2ONE, STATUS, MISC |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
170 - msg: HTML message which will appear in the privacy warning banner """ |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
171 target = self._selected_cache |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
172 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
173 def getSelectedOrStatus(): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
174 if target: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
175 _type, msg = target.getWarningData() |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
176 target_hook = None # we use the selected widget, not a hook |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
177 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
178 _type, msg = "STATUS", "This will be your new status message" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
179 target_hook = (txt, None) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
180 return (target_hook, _type, msg) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
181 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
182 if not txt.startswith('@'): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
183 target_hook, _type, msg = getSelectedOrStatus() |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
184 elif txt.startswith('@@: '): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
185 _type = "PUBLIC" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
186 msg = MicroblogPanel.warning_msg_public |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
187 target_hook = (txt[4:], None) |
33 | 188 elif txt.startswith('@'): |
189 _end = txt.find(': ') | |
190 if _end == -1: | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
191 target_hook, _type, msg = getSelectedOrStatus() |
33 | 192 else: |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
193 group = txt[1:_end] # only one target group is managed for the moment |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
194 if not group or not group in self.host.contact_panel.getGroups(): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
195 # the group doesn't exists, we ignore the key |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
196 group = None |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
197 target_hook, _type, msg = getSelectedOrStatus() |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
198 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
199 _type = "GROUP" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
200 msg = MicroblogPanel.warning_msg_group % group |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
201 target_hook = (txt[_end + 2:], group) |
33 | 202 else: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
203 print "ERROR: Unknown target" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
204 target_hook, _type, msg = getSelectedOrStatus() |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
205 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
206 return (target_hook, _type, msg) |
33 | 207 |
174
d97b0cba8b04
browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
208 def onBrowserEvent(self, event): |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
209 # XXX: woraroung a pyjamas bug: self.currentEvent is not set |
174
d97b0cba8b04
browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
210 # so the TextBox's cancelKey doens't work. This is a workaround |
d97b0cba8b04
browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
211 # FIXME: fix the bug upstream |
d97b0cba8b04
browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
212 self.currentEvent = event |
d97b0cba8b04
browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
213 TextArea.onBrowserEvent(self, event) |
d97b0cba8b04
browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
214 |
33 | 215 def onKeyPress(self, sender, keycode, modifiers): |
216 _txt = self.getText() | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
217 target = self._getTarget(_txt) |
33 | 218 if not self._popup: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
219 self.showWarning(target) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
220 elif target != self._popup.target_data: |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
221 self._timeCb(None) # we remove the popup |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
222 self.showWarning(target) |
33 | 223 |
224 self._timer.schedule(2000) | |
225 | |
239
b911f2b43fd4
browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents:
235
diff
changeset
|
226 def history_cb(text): |
b911f2b43fd4
browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents:
235
diff
changeset
|
227 self.setText(text) |
249
c24715dcd2f6
browser_side: set the "workaround" timers to 5 ms instead of 10:
souliane <souliane@mailoo.org>
parents:
246
diff
changeset
|
228 Timer(5, lambda: self.setCursorPos(len(text))) |
239
b911f2b43fd4
browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents:
235
diff
changeset
|
229 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
230 # if keycode == KEY_ENTER and not self.visible: |
83 | 231 if keycode == KEY_ENTER: |
33 | 232 if _txt: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
233 target_hook, _type, msg = target |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
234 if target_hook: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
235 parsed_txt, data = target_hook |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
236 if _type == "PUBLIC": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
237 self.host.bridge.call("sendMblog", None, "PUBLIC", None, parsed_txt) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
238 elif _type == "GROUP": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
239 self.host.bridge.call("sendMblog", None, "GROUP", data, parsed_txt) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
240 elif _type == "STATUS": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
241 self.host.bridge.call('setStatus', None, parsed_txt) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
242 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
243 print "ERROR: Unknown target hook type" |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
244 else: # we send the message to the selected target |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
245 self._selected_cache.onTextEntered(_txt) |
239
b911f2b43fd4
browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents:
235
diff
changeset
|
246 self.host._updateInputHistory(_txt) |
33 | 247 self.setText('') |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
248 self._timeCb(None) # we remove the popup |
174
d97b0cba8b04
browser side: fix the line jump in unibox after entering something (work around a pyjamas bug)
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
249 sender.cancelKey() |
239
b911f2b43fd4
browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents:
235
diff
changeset
|
250 elif keycode == KEY_UP: |
b911f2b43fd4
browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents:
235
diff
changeset
|
251 self.host._updateInputHistory(_txt, -1, history_cb) |
b911f2b43fd4
browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents:
235
diff
changeset
|
252 elif keycode == KEY_DOWN: |
b911f2b43fd4
browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents:
235
diff
changeset
|
253 self.host._updateInputHistory(_txt, +1, history_cb) |
214
7b26be266ab1
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
213
diff
changeset
|
254 else: |
7b26be266ab1
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
213
diff
changeset
|
255 self.__onComposing() |
7b26be266ab1
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
213
diff
changeset
|
256 |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
257 def getTargetAndData(self): |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
258 """For external use, to get information about the (hypothetical) message |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
259 that would be sent if we press Enter right now in the unibox. |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
260 @return a tuple (target, data) with: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
261 - data: what would be the content of the message (body) |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
262 - target: JID, group with the prefix "@" or the public entity "@@" |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
263 """ |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
264 _txt = self.getText() |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
265 target_hook, _type, _msg = self._getTarget(_txt) |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
266 if target_hook: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
267 data, target = target_hook |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
268 if target is None: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
269 return target_hook |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
270 return (data, "@%s" % (target if target != "" else "@")) |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
271 if isinstance(self._selected_cache, MicroblogPanel): |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
272 groups = self._selected_cache.accepted_groups |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
273 target = "@%s" % (groups[0] if len(groups) > 0 else "@") |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
274 if len(groups) > 1: |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
275 Window.alert("Sole the first group of the selected panel is taken in consideration: '%s'" % groups[0]) |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
276 elif isinstance(self._selected_cache, ChatPanel): |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
277 target = self._selected_cache.target |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
278 return (_txt, target) |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
230
diff
changeset
|
279 |
214
7b26be266ab1
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
213
diff
changeset
|
280 def __onComposing(self): |
7b26be266ab1
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
213
diff
changeset
|
281 """Callback when the user is composing a text.""" |
7b26be266ab1
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
213
diff
changeset
|
282 if hasattr(self._selected_cache, "target"): |
223
624a87377412
browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents:
218
diff
changeset
|
283 self._selected_cache.state_machine._onEvent("composing") |
33 | 284 |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
285 def onMouseUp(self, sender, x, y): |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
286 size = (self.getOffsetWidth(), self.getOffsetHeight()) |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
287 if size != self.__size: |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
288 self.__size = size |
193
f2ae8e170c49
browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
289 self.host.resize() |
f2ae8e170c49
browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
290 |
f2ae8e170c49
browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
291 def onSelectedChange(self, selected): |
f2ae8e170c49
browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
292 self._selected_cache = selected |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
293 |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
294 """def complete(self): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
295 |
33 | 296 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
297 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
298 return AutoCompleteTextBox.complete(self)""" |
33 | 299 |
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
|
300 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
301 class MicroblogItem(): |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
302 # XXX: should be moved in a separated module |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
303 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
304 def __init__(self, data): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
305 self.id = data['id'] |
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
|
306 self.type = data.get('type', 'main_item') |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
307 self.content = data['content'] |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
308 self.author = data['author'] |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
309 self.timestamp = float(data.get('timestamp', 0)) # XXX: int doesn't work here |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
310 self.comments = data.get('comments', False) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
311 if self.comments: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
312 try: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
313 self.comments_hash = (data['comments_service'], data['comments_node']) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
314 self.comments_service = data['comments_service'] |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
315 self.comments_node = data['comments_node'] |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
316 except KeyError: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
317 print "Warning: can't manage comment [%s], some keys are missing in microblog data (%s)" % (data["comments"], data.keys()) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
318 self.comments = False |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
319 if set(("service", "node")).issubset(data.keys()): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
320 self.service = data["service"] |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
321 self.node = data["node"] |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
322 self.hash = (self.service, self.node) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
323 |
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
|
324 |
199
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
325 class MicroblogEntry(SimplePanel, ClickHandler): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 |
199
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
327 def __init__(self, blog_panel, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 SimplePanel.__init__(self) |
199
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
329 self._blog_panel = blog_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 |
119 | 331 self.author = mblog_entry.author |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
332 self.timestamp = mblog_entry.timestamp |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
333 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
334 self.comments = mblog_entry.comments |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 |
119 | 336 self.panel = HTMLPanel(""" |
120
054b7b3424a3
browser side: microblog's entry header with pseudo and timestamp
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
337 <div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div> |
119 | 338 <div class="mb_entry_avatar" id='id_avatar'></div> |
114
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
339 <div class="mb_entry_dialog"> |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
340 <p class="bubble">%(body)s</p> |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
341 </div> |
119 | 342 """ % {"author": html_sanitize(self.author), |
114
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
343 "timestamp": _datetime, |
217
f7ec248192de
browser_side: display clickable URLs in chat text
souliane <souliane@mailoo.org>
parents:
214
diff
changeset
|
344 "body": addURLToText(html_sanitize(mblog_entry.content)) |
114
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
345 }) |
199
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
346 self.avatar = Image(blog_panel.host.getAvatar(self.author)) |
119 | 347 self.panel.add(self.avatar, "id_avatar") |
348 self.panel.setStyleName('mb_entry') | |
349 self.add(self.panel) | |
199
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
350 ClickHandler.__init__(self) |
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
351 self.addClickListener(self) |
119 | 352 |
353 def updateAvatar(self, new_avatar): | |
354 """Change the avatar of the entry | |
355 @param new_avatar: path to the new image""" | |
356 self.avatar.setUrl(new_avatar) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
357 |
199
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
358 def onClick(self, sender): |
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
359 print "microblog entry selected (author=%s)" % self.author |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
360 self._blog_panel.setSelectedEntry(self if self.comments else None) |
119 | 361 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 |
195 | 363 class MicroblogPanel(base_widget.LiberviaWidget): |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
364 warning_msg_public = "This message will be PUBLIC and everybody will be able to see it, even people you don't know" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
365 warning_msg_group = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
367 def __init__(self, host, accepted_groups): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 """Panel used to show microblog |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
369 @param accepted_groups: groups displayed in this panel, if empty, show all microblogs from all contacts |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
370 """ |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
371 base_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups), selectable=True) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
372 self.setAcceptedGroup(accepted_groups) |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
373 self.entries = {} |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
374 self.comments = {} |
199
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
375 self.selected_entry = None |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 self.vpanel = VerticalPanel() |
83 | 377 self.vpanel.setStyleName('microblogPanel') |
34 | 378 self.setWidget(self.vpanel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 |
195 | 380 @classmethod |
381 def registerClass(cls): | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
382 base_widget.LiberviaWidget.addDropKey("GROUP", cls.createPanel) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
383 base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", cls.createMetaPanel) |
195 | 384 |
385 @classmethod | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
386 def createPanel(cls, host, item): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
387 """Generic panel creation for one, several or all groups (meta). |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
388 @parem host: the SatWebFrontend instance |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
389 @param item: single group as a string, list of groups |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
390 (as an array) or None (for the meta group = "all groups") |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
391 @return: the created MicroblogPanel |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
392 """ |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
393 _items = item if isinstance(item, list) else ([] if item is None else [item]) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
394 _type = 'ALL' if _items == [] else 'GROUP' |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
395 # XXX: pyjamas doesn't support use of cls directly |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
396 _new_panel = MicroblogPanel(host, _items) |
195 | 397 host.FillMicroblogPanel(_new_panel) |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
398 host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, _type, _items, 10) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
399 host.setSelected(_new_panel) |
195 | 400 return _new_panel |
401 | |
402 @classmethod | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
403 def createMetaPanel(cls, host, item): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
404 """Needed for the drop keys to not be mixed between meta panel and panel for "Contacts" group""" |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
405 return MicroblogPanel.createPanel(host, None) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
406 |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
407 @property |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
408 def accepted_groups(self): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
409 return self._accepted_groups |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
410 |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
411 def matchEntity(self, entity): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
412 """ |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
413 @param entity: single group as a string, list of groups |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
414 (as an array) or None (for the meta group = "all groups") |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
415 @return: True if self matches the given entity |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
416 """ |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
417 entity = entity if isinstance(entity, list) else ([] if entity is None else [entity]) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
418 entity.sort() # sort() do not return the sorted list: do it here, not on the "return" line |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
419 return self.accepted_groups == entity |
195 | 420 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
421 def getWarningData(self): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
422 if self.selected_entry: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
423 if not self.selected_entry.comments: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
424 print ("ERROR: an item without comment is selected") |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
425 return ("NONE", None) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
426 return ("PUBLIC", "This is a <span class='warningTarget'>comment</span> and keep the initial post visibility, so it is potentialy public") |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
427 |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
428 elif not self._accepted_groups: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
429 # we have a meta MicroblogPanel, we publish publicly |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
430 return ("PUBLIC", self.warning_msg_public) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
431 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
432 # we only accept one group at the moment |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
433 # FIXME: manage several groups |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
434 return ("GROUP", self.warning_msg_group % self._accepted_groups[0]) |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
435 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
436 def onTextEntered(self, text): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
437 if self.selected_entry: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
438 # we are entering a comment |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
439 comments_node = self.selected_entry.comments |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
440 if not comments_node: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
441 raise Exception("ERROR: comments node is empty") |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
442 self.host.bridge.call("sendMblogComment", None, comments_node, text) |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
443 elif not self._accepted_groups: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
444 # we are entering a public microblog |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
445 self.host.bridge.call("sendMblog", None, "PUBLIC", None, text) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
446 else: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
447 # we are entering a microblog restricted to a group |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
448 # FIXME: manage several groups |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
449 self.host.bridge.call("sendMblog", None, "GROUP", self._accepted_groups[0], text) |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
450 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
451 def accept_all(self): |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
452 return not self._accepted_groups # we accept every microblog only if we are not filtering by groups |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
453 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
454 def getEntries(self): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
455 """Ask all the entries for the currenly accepted groups, |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
456 and fill the panel""" |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
457 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
458 def massiveInsert(self, mblogs): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
459 """Insert several microblogs at once |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
460 @param mblogs: dictionary of microblogs, as the result of getMassiveLastGroupBlogs |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
461 """ |
242
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
462 print "Massive insertion of %d microblogs" % len(mblogs) |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
463 for publisher in mblogs: |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
464 print "adding blogs for [%s]" % publisher |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
465 for mblog in mblogs[publisher]: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
466 if not "content" in mblog: |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
467 print ("WARNING: No content found in microblog [%s]", mblog) |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
468 continue |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
469 mblog_item = MicroblogItem(mblog) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
470 self.addEntry(mblog_item) |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
471 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
472 def mblogsInsert(self, mblogs): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
473 """ Insert several microblogs at once |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
474 @param mblogs: list of microblogs |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
475 """ |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
476 for mblog in mblogs: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
477 if not "content" in mblog: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
478 print ("WARNING: No content found in microblog [%s]", mblog) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
479 continue |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
480 mblog_item = MicroblogItem(mblog) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
481 self.addEntry(mblog_item) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
482 |
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
|
483 def _chronoInsert(self, vpanel, entry, reverse=True): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
484 """ Insert an entry in chronological order |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
485 @param vpanel: VerticalPanel instance |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
486 @param entry: MicroblogEntry |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
487 @param reverse: more recent entry on top if True, chronological order else""" |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
488 # we look for the right index to insert our entry: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
489 # if reversed, we insert the entry above the first entry |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
490 # in the past |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
491 idx = 0 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
492 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
493 for child in vpanel.children: |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
494 if not isinstance(child, MicroblogEntry): |
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
|
495 idx += 1 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
496 continue |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
497 if reverse: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
498 if child.timestamp < entry.timestamp: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
499 break |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
500 else: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
501 if child.timestamp > entry.timestamp: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
502 break |
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
|
503 idx += 1 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
504 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
505 vpanel.insert(entry, idx) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
506 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
507 def addEntry(self, mblog_item): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
508 """Add an entry to the panel |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
509 @param mblog_item: MicroblogItem instance |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
510 """ |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
511 if mblog_item.type == "comment": |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
512 if not mblog_item.hash in self.comments: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
513 # The comments node is not known in this panel |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
514 return |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
515 _entry = MicroblogEntry(self, mblog_item) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
516 parent = self.comments[mblog_item.hash] |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
517 parent_idx = self.vpanel.getWidgetIndex(parent) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
518 # we find or create the panel where the comment must be inserted |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
519 try: |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
520 sub_panel = self.vpanel.getWidget(parent_idx + 1) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
521 except IndexError: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
522 sub_panel = None |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
523 if not sub_panel or not isinstance(sub_panel, VerticalPanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
524 sub_panel = VerticalPanel() |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
525 sub_panel.setStyleName('microblogPanel') |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
526 sub_panel.addStyleName('subPanel') |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
527 self.vpanel.insert(sub_panel, parent_idx + 1) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
528 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
529 # we want comments to be inserted in chronological order |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
530 self._chronoInsert(sub_panel, _entry, reverse=False) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
531 return |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
532 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
533 if mblog_item.id in self.entries: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
534 return |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
535 _entry = MicroblogEntry(self, mblog_item) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
536 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
537 self.entries[mblog_item.id] = _entry |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
538 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
539 self._chronoInsert(self.vpanel, _entry) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
540 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
541 if mblog_item.comments: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
542 # entry has comments, we keep the comment node as a reference |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
543 self.comments[mblog_item.comments_hash] = _entry |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
544 self.host.bridge.call('getMblogComments', self.mblogsInsert, mblog_item.comments_service, mblog_item.comments_node) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
545 |
199
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
546 def setSelectedEntry(self, entry): |
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
547 if self.selected_entry == entry: |
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
548 entry = None |
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
549 if self.selected_entry: |
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
550 self.selected_entry.removeStyleName('selected_entry') |
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
551 if entry: |
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
552 entry.addStyleName('selected_entry') |
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
553 self.selected_entry = entry |
39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
554 |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
555 def updateValue(self, type_, jid, value): |
119 | 556 """Update a jid value in entries |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
557 @param type_: one of 'avatar', 'nick' |
119 | 558 @param jid: jid concerned |
559 @param value: new value""" | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
560 def updateVPanel(vpanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
561 for child in vpanel.children: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
562 if isinstance(child, MicroblogEntry) and child.author == jid: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
563 child.updateAvatar(value) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
564 elif isinstance(child, VerticalPanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
565 updateVPanel(child) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
566 if type_ == 'avatar': |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
567 updateVPanel(self.vpanel) |
119 | 568 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
569 def setAcceptedGroup(self, group): |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
570 """Add one or more group(s) which can be displayed in this panel. |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
571 Prevent from duplicate values and keep the list sorted. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
572 @param group: string of the group, or list of string |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
573 """ |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
574 if not hasattr(self, "_accepted_groups"): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
575 self._accepted_groups = [] |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
576 groups = group if isinstance(group, list) else [group] |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
577 for _group in groups: |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
578 if _group not in self._accepted_groups: |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
579 self._accepted_groups.append(_group) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
580 self._accepted_groups.sort() |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
581 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
582 def isJidAccepted(self, jid): |
163
b887186e8fc8
browser side: get entity's microblogs for newly added contacts
Goffi <goffi@goffi.org>
parents:
148
diff
changeset
|
583 """Tell if a jid is actepted and shown in this panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
584 @param jid: jid |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
585 @return: True if the jid is accepted""" |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
586 if self.accept_all(): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
587 return True |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
588 for group in self._accepted_groups: |
27
d89982865c57
browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
589 if self.host.contact_panel.isContactInGroup(group, jid): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
590 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
591 return False |
19 | 592 |
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
|
593 |
20 | 594 class StatusPanel(HTMLPanel, ClickHandler): |
595 def __init__(self, host, status=''): | |
596 self.host = host | |
597 self.status = status or ' ' | |
19 | 598 HTMLPanel.__init__(self, self.__getContent()) |
20 | 599 self.setStyleName('statusPanel') |
600 ClickHandler.__init__(self) | |
601 self.addClickListener(self) | |
19 | 602 |
603 def __getContent(self): | |
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
|
604 return "<span class='status'>%(status)s</span>" % {'status': html_sanitize(self.status)} |
19 | 605 |
606 def changeStatus(self, new_status): | |
20 | 607 self.status = new_status or ' ' |
19 | 608 self.setHTML(self.__getContent()) |
609 | |
62 | 610 def onClick(self, sender): |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
611 # As status is the default target of uniBar, we don't want to select anything if click on it |
192
cf5c83e7d515
browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents:
191
diff
changeset
|
612 self.host.setSelected(None) |
20 | 613 |
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
|
614 |
19 | 615 class ChatText(HTMLPanel): |
616 | |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
617 def __init__(self, timestamp, nick, mymess, msg, xhtml = None): |
19 | 618 _date = datetime.fromtimestamp(float(timestamp or time())) |
619 _msg_class = ["chat_text_msg"] | |
620 if mymess: | |
621 _msg_class.append("chat_text_mymess") | |
622 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
|
623 {"timestamp": _date.strftime("%H:%M"), |
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
|
624 "nick": "[%s]" % html_sanitize(nick), |
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
|
625 "msg_class": ' '.join(_msg_class), |
246
d7c41c84d062
browser side: use of inlineRoot to display XHTML chat text
Goffi <goffi@goffi.org>
parents:
242
diff
changeset
|
626 "msg": addURLToText(html_sanitize(msg)) if not xhtml else 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
|
627 ) |
19 | 628 self.setStyleName('chatText') |
33 | 629 |
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
|
630 |
33 | 631 class Occupant(HTML): |
632 """Occupant of a MUC room""" | |
633 | |
634 def __init__(self, nick): | |
635 self.nick = nick | |
35 | 636 HTML.__init__(self, "<div class='occupant'>%s</div>" % html_sanitize(nick)) |
637 | |
638 def __str__(self): | |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
639 return self.nick |
33 | 640 |
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
|
641 |
33 | 642 class OccupantsList(AbsolutePanel): |
643 """Panel user to show occupants of a room""" | |
644 | |
645 def __init__(self): | |
646 AbsolutePanel.__init__(self) | |
35 | 647 self.occupants_list = {} |
33 | 648 self.setStyleName('occupantsList') |
649 | |
650 def addOccupant(self, nick): | |
35 | 651 _occupant = Occupant(nick) |
652 self.occupants_list[nick] = _occupant | |
653 self.add(_occupant) | |
33 | 654 |
35 | 655 def removeOccupant(self, nick): |
656 try: | |
657 self.remove(self.occupants_list[nick]) | |
658 except KeyError: | |
659 print "ERROR: trying to remove an unexisting nick" | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
660 |
35 | 661 def clear(self): |
662 self.occupants_list.clear() | |
663 AbsolutePanel.clear(self) | |
664 | |
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
|
665 |
195 | 666 class ChatPanel(base_widget.LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
667 |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
668 def __init__(self, host, target, type_='one2one'): |
19 | 669 """Panel used for conversation (one 2 one or group chat) |
670 @param host: SatWebFrontend instance | |
671 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) | |
672 @param type: one2one for simple conversation, group for MUC""" | |
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
|
673 base_widget.LiberviaWidget.__init__(self, host, target.bare, selectable=True) |
34 | 674 self.vpanel = VerticalPanel() |
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
|
675 self.vpanel.setSize('100%', '100%') |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
676 self.type = type_ |
33 | 677 self.nick = None |
19 | 678 if not target: |
679 print "ERROR: Empty target !" | |
680 return | |
681 self.target = target | |
84 | 682 self.__body = AbsolutePanel() |
683 self.__body.setStyleName('chatPanel_body') | |
33 | 684 chat_area = HorizontalPanel() |
685 chat_area.setStyleName('chatArea') | |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
686 if type_ == 'group': |
33 | 687 self.occupants_list = OccupantsList() |
688 chat_area.add(self.occupants_list) | |
84 | 689 self.__body.add(chat_area) |
33 | 690 self.content = AbsolutePanel() |
691 self.content.setStyleName('chatContent') | |
195 | 692 self.content_scroll = base_widget.ScrollPanelWrapper(self.content) |
34 | 693 chat_area.add(self.content_scroll) |
694 chat_area.setCellWidth(self.content_scroll, '100%') | |
84 | 695 self.vpanel.add(self.__body) |
696 self.addStyleName('chatPanel') | |
34 | 697 self.setWidget(self.vpanel) |
223
624a87377412
browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents:
218
diff
changeset
|
698 self.state_machine = ChatStateMachine(self.host, str(self.target)) |
19 | 699 |
84 | 700 """def doDetachChildren(self): |
38
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
701 #We need to force the use of a panel subclass method here, |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
702 #for the same reason as doAttachChildren |
195 | 703 base_widget.ScrollPanelWrapper.doDetachChildren(self) |
38
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
704 |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
705 def doAttachChildren(self): |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
706 #We need to force the use of a panel subclass method here, else |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
707 #the event will not propagate to children |
195 | 708 base_widget.ScrollPanelWrapper.doAttachChildren(self)""" |
709 | |
710 @classmethod | |
711 def registerClass(cls): | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
712 base_widget.LiberviaWidget.addDropKey("CONTACT", cls.createPanel) |
195 | 713 |
714 @classmethod | |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
715 def createPanel(cls, host, item): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
716 _contact = item if isinstance(item, JID) else JID(item) |
195 | 717 host.contact_panel.setContactMessageWaiting(_contact.bare, False) |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
718 _new_panel = ChatPanel(host, _contact) # XXX: pyjamas doesn't seems to support creating with cls directly |
195 | 719 _new_panel.historyPrint() |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
720 host.setSelected(_new_panel) |
195 | 721 return _new_panel |
38
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
722 |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
723 def refresh(self): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
724 """Refresh the display of this widget.""" |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
725 self.host.contact_panel.setContactMessageWaiting(self.target.bare, False) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
726 self.content_scroll.scrollToBottom() |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
727 |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
728 def matchEntity(self, entity): |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
729 """ |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
730 @param entity: target jid as a string or JID instance |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
731 @return: True if self matches the given entity |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
732 """ |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
733 entity = entity if isinstance(entity, JID) else JID(entity) |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
734 try: |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
735 return self.target.bare == entity.bare |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
736 except AttributeError as e: |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
737 e.include_traceback() |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
738 return False |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
739 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
740 def getWarningData(self): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
741 if self.type not in ["one2one", "group"]: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
742 raise Exception("Unmanaged type !") |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
743 if self.type == "one2one": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
744 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % self.target |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
745 elif self.type == "group": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
746 msg = "This message will be sent to all the participants of the multi-user room <span class='warningTarget'>%s</span>" % self.target |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
747 return ("ONE2ONE" if self.type == "one2one" else "GROUP", msg) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
748 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
749 def onTextEntered(self, text): |
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
|
750 mess_type = "groupchat" if self.type == 'group' else "chat" |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
751 self.host.bridge.call('sendMessage', None, str(self.target), text, '', mess_type) |
223
624a87377412
browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents:
218
diff
changeset
|
752 self.state_machine._onEvent("active") |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
753 |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
754 def onQuit(self): |
195 | 755 base_widget.LiberviaWidget.onQuit(self) |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
756 if self.type == 'group': |
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
757 self.host.bridge.call('mucLeave', None, self.target.bare) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
758 |
19 | 759 def setUserNick(self, nick): |
760 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
761 self.nick = nick | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
762 |
33 | 763 def setPresents(self, nicks): |
764 """Set the users presents in this room | |
765 @param occupants: list of nicks (string)""" | |
35 | 766 self.occupants_list.clear() |
33 | 767 for nick in nicks: |
768 self.occupants_list.addOccupant(nick) | |
769 | |
35 | 770 def userJoined(self, nick, data): |
771 self.occupants_list.addOccupant(nick) | |
772 self.printInfo("=> %s has joined the room" % nick) | |
773 | |
774 def userLeft(self, nick, data): | |
775 self.occupants_list.removeOccupant(nick) | |
776 self.printInfo("<= %s has left the room" % nick) | |
777 | |
19 | 778 def historyPrint(self, size=20): |
779 """Print the initial history""" | |
780 def getHistoryCB(history): | |
213
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
781 # display day change |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
782 day_format = "%A, %d %b %Y" |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
783 previous_day = datetime.now().strftime(day_format) |
123 | 784 for line in history: |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
785 timestamp, from_jid, to_jid, message, mess_type, extra = line |
213
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
786 message_day = datetime.fromtimestamp(float(timestamp or time())).strftime(day_format) |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
787 if previous_day != message_day: |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
788 self.printInfo("* " + message_day) |
8bbac49765d6
browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
789 previous_day = message_day |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
790 self.printMessage(from_jid, message, extra, timestamp) |
123 | 791 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
792 |
35 | 793 def printInfo(self, msg, type='normal'): |
794 """Print general info | |
795 @param msg: message to print | |
796 @type: one of: | |
797 normal: general info like "toto has joined the room" | |
798 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
799 """ | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
800 _wid = Label(msg) |
35 | 801 if type == 'normal': |
802 _wid.setStyleName('chatTextInfo') | |
803 elif type == 'me': | |
804 _wid.setStyleName('chatTextMe') | |
805 else: | |
806 _wid.setStyleName('chatTextInfo') | |
807 self.content.add(_wid) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
808 |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
809 def printMessage(self, from_jid, msg, extra, timestamp=None): |
19 | 810 """Print message in chat window. Must be implemented by child class""" |
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
|
811 _jid = JID(from_jid) |
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
|
812 nick = _jid.node if self.type == 'one2one' else _jid.resource |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
813 mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare # mymess = True if message comes from local user |
35 | 814 if msg.startswith('/me '): |
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
|
815 self.printInfo('* %s %s' % (nick, msg[4:]), type='me') |
35 | 816 return |
235
b304cdf13a3b
browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents:
232
diff
changeset
|
817 self.content.add(ChatText(timestamp, nick, mymess, msg, extra.get('xhtml'))) |
34 | 818 self.content_scroll.scrollToBottom() |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
819 |
36 | 820 def startGame(self, game_type, referee, players): |
821 """Configure the chat window to start a game""" | |
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
|
822 if game_type == "Tarot": |
167
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
823 if hasattr(self, "tarot_panel"): |
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
824 return |
36 | 825 self.tarot_panel = CardPanel(self, referee, players, self.nick) |
92
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
826 self.vpanel.insert(self.tarot_panel, 0) |
36 | 827 self.vpanel.setCellHeight(self.tarot_panel, self.tarot_panel.getHeight()) |
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
|
828 elif game_type == "RadioCol": |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
829 # XXX: We can have double panel if we join quickly enough to have the group chat start signal |
167
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
830 # on invitation + the one triggered on room join |
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
831 if hasattr(self, "radiocol_panel"): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
832 return |
127 | 833 self.radiocol_panel = RadioColPanel(self, referee, self.nick) |
834 self.vpanel.insert(self.radiocol_panel, 0) | |
835 self.vpanel.setCellHeight(self.radiocol_panel, self.radiocol_panel.getHeight()) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
836 |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
837 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
838 """Return class managing the game type""" |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
839 # TODO: check that the game is launched, and manage errors |
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
|
840 if game_type == "Tarot": |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
841 return self.tarot_panel |
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
|
842 elif game_type == "RadioCol": |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
843 return self.radiocol_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
844 |
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
|
845 |
195 | 846 class WebPanel(base_widget.LiberviaWidget): |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
847 """ (mini)browser like widget """ |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
848 |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
849 def __init__(self, host, url=None): |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
850 """ |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
851 @param host: SatWebFrontend instance |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
852 """ |
195 | 853 base_widget.LiberviaWidget.__init__(self, host) |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
854 self._vpanel = VerticalPanel() |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
855 self._vpanel.setSize('100%', '100%') |
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
|
856 self._url = dialog.ExtTextBox(enter_cb=self.onUrlClick) |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
857 self._url.setText(url or "") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
858 self._url.setWidth('100%') |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
859 hpanel = HorizontalPanel() |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
860 hpanel.add(self._url) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
861 btn = Button("Go", self.onUrlClick) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
862 hpanel.setCellWidth(self._url, "100%") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
863 #self.setCellWidth(btn, "10%") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
864 hpanel.add(self._url) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
865 hpanel.add(btn) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
866 self._vpanel.add(hpanel) |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
867 self._vpanel.setCellHeight(hpanel, '20px') |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
868 self._frame = Frame(url or "") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
869 self._frame.setSize('100%', '100%') |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
870 DOM.setStyleAttribute(self._frame.getElement(), "position", "relative") |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
871 self._vpanel.add(self._frame) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
872 self.setWidget(self._vpanel) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
873 |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
874 def onUrlClick(self, sender): |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
875 self._frame.setUrl(self._url.getText()) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
876 |
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
|
877 |
33 | 878 class MainPanel(AbsolutePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
879 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
880 def __init__(self, host): |
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
|
881 self.host = host |
33 | 882 AbsolutePanel.__init__(self) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
883 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
884 # menu |
218
4e6467efd6bf
browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents:
217
diff
changeset
|
885 self.menu = Menu(host) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
886 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
887 # unibox |
33 | 888 unibox_panel = UniBoxPanel(host) |
889 self.host.setUniBox(unibox_panel.unibox) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
890 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
891 # status bar |
27
d89982865c57
browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
892 status = host.status_panel |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
893 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
894 # contacts |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
895 self._contacts = HorizontalPanel() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
896 self._contacts.addStyleName('globalLeftArea') |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
897 self.contacts_switch = Button(u'«', self._contactsSwitch) |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
898 self.contacts_switch.addStyleName('contactsSwitch') |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
899 self._contacts.add(self.contacts_switch) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
900 self._contacts.add(self.host.contact_panel) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
901 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
902 # tabs |
195 | 903 self.tab_panel = base_widget.MainTabPanel(host) |
904 self.discuss_panel = base_widget.WidgetsPanel(self.host, locked=True) | |
23 | 905 self.tab_panel.add(self.discuss_panel, "Discussions") |
906 self.tab_panel.selectTab(0) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
907 |
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
|
908 header = AbsolutePanel() |
218
4e6467efd6bf
browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents:
217
diff
changeset
|
909 header.add(self.menu) |
109
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
910 header.add(unibox_panel) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
911 header.add(status) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
912 header.setStyleName('header') |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
913 self.add(header) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
914 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
915 self._hpanel = HorizontalPanel() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
916 self._hpanel.add(self._contacts) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
917 self._hpanel.add(self.tab_panel) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
918 self.add(self._hpanel) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
919 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
920 self.setWidth("100%") |
33 | 921 Window.addWindowResizeListener(self) |
922 | |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
923 def _contactsSwitch(self, btn=None): |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
924 """ (Un)hide contacts panel """ |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
925 if btn is None: |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
249
diff
changeset
|
926 btn = self.contacts_switch |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
927 cpanel = self.host.contact_panel |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
928 cpanel.setVisible(not cpanel.getVisible()) |
206
4d7054542751
browser side: contactBox doesn't use left margin anymore (avoid scrollbar issues) + some cosmetic changes to contact panel switch button
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
929 btn.setText(u"«" if cpanel.getVisible() else u"»") |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
930 self.host.resize() |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
931 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
932 def _contactsMove(self, parent): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
933 """Move the contacts container (containing the contact list and |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
934 the "hide/show" button) to another parent, but always as the |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
935 first child position (insert at index 0). |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
936 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
937 if self._contacts.getParent(): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
938 if self._contacts.getParent() == parent: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
939 return |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
940 self._contacts.removeFromParent() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
941 parent.insert(self._contacts, 0) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
942 |
33 | 943 def onWindowResized(self, width, height): |
944 _elts = doc().getElementsByClassName('gwt-TabBar') | |
945 if not _elts.length: | |
946 tab_bar_h = 0 | |
947 else: | |
948 tab_bar_h = _elts.item(0).offsetHeight | |
949 ideal_height = Window.getClientHeight() - tab_bar_h | |
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
|
950 self.setHeight("%s%s" % (ideal_height, "px")) |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
951 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
952 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
953 class PopupMenuPanel(PopupPanel): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
954 """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
|
955 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
|
956 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
|
957 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
|
958 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
959 def __init__(self, entries, hide=None, callback=None, vertical=True, item_style="popupMenuItem", menu_style=None, **kwargs): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
960 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
961 @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
|
962 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
|
963 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
|
964 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
|
965 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
|
966 @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
|
967 returns True if that item should be hidden from the context menu. |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
968 @param callback: function with 2 args: widget, key as string |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
969 @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
|
970 @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
|
971 @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
|
972 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
973 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
|
974 self._entries = entries |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
975 self._hide = hide |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
976 self._callback = callback |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
977 self.vertical = vertical |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
978 self.item_style = item_style |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
979 self.menu_style = menu_style |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
980 self._senders = {} |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
981 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
982 def _show(self, sender): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
983 """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
|
984 @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
|
985 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
986 menu = VerticalPanel() if self.vertical is True else HorizontalPanel() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
987 menu.setStyleName("recipientTypeMenu") |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
988 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
989 def button_cb(item): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
990 """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
|
991 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
|
992 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
|
993 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
|
994 @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
|
995 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
996 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
|
997 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
|
998 self.hide(autoClosed=True) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
999 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1000 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
|
1001 entry = self._entries[_key] |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1002 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
|
1003 continue |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1004 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
|
1005 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
|
1006 item.key = _key |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1007 item.setStyleName(self.item_style) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1008 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
|
1009 menu.add(item) |
242
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
1010 if len(menu.getChildren()) == 0: |
a25aa882e09a
browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents:
241
diff
changeset
|
1011 return |
241
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1012 self.add(menu) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1013 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
|
1014 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
|
1015 y = sender.getAbsoluteTop() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1016 else: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1017 x = sender.getAbsoluteLeft() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1018 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
|
1019 self.setPopupPosition(x, y) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1020 self.show() |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1021 if self.menu_style: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1022 sender.addStyleDependentName(self.menu_style) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1023 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1024 def _onHide(popup): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1025 if hasattr(self, "menu_style") and self.menu_style is not None: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1026 sender.removeStyleDependentName(self.menu_style) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1027 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
|
1028 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1029 self.onHideImpl = _onHide |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1030 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1031 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
|
1032 """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
|
1033 @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
|
1034 @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
|
1035 """ |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1036 self._senders.setdefault(sender, []) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1037 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
|
1038 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1039 if button == BUTTON_RIGHT: |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1040 # 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
|
1041 # 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
|
1042 # 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
|
1043 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
|
1044 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1045 def _onBrowserEvent(event): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1046 button = DOM.eventGetButton(event) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1047 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
|
1048 self._show(sender) |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1049 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
|
1050 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1051 sender.onBrowserEvent = _onBrowserEvent |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1052 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1053 def registerMiddleClickSender(self, sender): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1054 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
|
1055 |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1056 def registerRightClickSender(self, sender): |
86055ccf69c3
browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents:
239
diff
changeset
|
1057 self.registerClickSender(sender, BUTTON_RIGHT) |