Mercurial > libervia-web
annotate browser_side/panels.py @ 195:dd27072d8ae0
browser side: widgets refactoring:
- moved base widgets in a base_widget module
- widgets class now register themselves their Drag/Drop type
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 04 Mar 2013 23:01:57 +0100 |
parents | 6198be95a39c |
children | 39311c7dad77 |
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 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 import pyjd # this is dummy in pyjs |
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 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from pyjamas.ui.HTMLPanel import HTMLPanel |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
28 from pyjamas.ui.Frame import Frame |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
29 from pyjamas.ui.TextArea import TextArea |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from pyjamas.ui.Label import Label |
83 | 31 from pyjamas.ui.Button import Button |
33 | 32 from pyjamas.ui.HTML import HTML |
83 | 33 from pyjamas.ui.Image import Image |
19 | 34 from pyjamas.ui.ClickListener import ClickHandler |
33 | 35 from pyjamas.ui.KeyboardListener import KEY_ENTER |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
36 from pyjamas.ui.MouseListener import MouseHandler |
33 | 37 from pyjamas.Timer import Timer |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 from pyjamas import DOM |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
39 from card_game import CardPanel |
127 | 40 from radiocol import RadioColPanel |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
41 from menu import Menu |
19 | 42 from jid import JID |
33 | 43 from tools import html_sanitize |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 from datetime import datetime |
19 | 45 from time import time |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
46 import dialog |
195 | 47 import base_widget |
48 from pyjamas import Window | |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
49 from __pyjamas__ import doc |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
33 | 51 class UniBoxPanel(SimplePanel): |
52 """Panel containing the UniBox""" | |
53 | |
54 def __init__(self, host): | |
55 SimplePanel.__init__(self) | |
56 self.setStyleName('uniBoxPanel') | |
57 self.unibox = UniBox(host) | |
58 self.unibox.setWidth('100%') | |
59 self.add(self.unibox) | |
60 | |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
61 class UniBox(TextArea, MouseHandler): #AutoCompleteTextBox): |
33 | 62 """This text box is used as a main typing point, for message, microblog, etc""" |
63 | |
64 def __init__(self, host): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
65 TextArea.__init__(self) |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
66 #AutoCompleteTextBox.__init__(self) |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
67 self.__size = (0,0) |
33 | 68 self._popup = None |
69 self._timer = Timer(notify=self._timeCb) | |
70 self.host = host | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
71 self.setStyleName('uniBox') |
83 | 72 self.addKeyboardListener(self) |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
73 MouseHandler.__init__(self) |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
74 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
|
75 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
|
76 host.addSelectedListener(self.onSelectedChange) |
33 | 77 |
78 def addKey(self, key): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
79 return |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
80 #self.getCompletionItems().completions.append(key) |
33 | 81 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
82 def removeKey(self, key): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
83 try: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
84 self.getCompletionItems().completions.remove(key) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
85 except KeyError: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
86 print "WARNING: trying to remove an unknown key" |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
87 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
88 |
33 | 89 def showWarning(self, target_data): |
90 type, target = target_data | |
91 if type == "PUBLIC": | |
92 msg = "This message will be PUBLIC and everybody will be able to see it, even people you don't know" | |
93 style = "targetPublic" | |
94 elif type == "GROUP": | |
95 msg = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" % (target or '') | |
96 style = "targetGroup" | |
97 elif type == "STATUS": | |
98 msg = "This will be your new status message" | |
99 style = "targetStatus" | |
100 elif type == "ONE2ONE": | |
101 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % target | |
102 style = "targetOne2One" | |
103 else: | |
104 print "WARNING: undetermined target for this message" | |
105 return | |
106 contents = HTML(msg) | |
107 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
108 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
33 | 109 self._popup.target_data = target_data |
110 self._popup.add(contents) | |
111 self._popup.setStyleName("warningPopup") | |
112 if style: | |
113 self._popup.addStyleName(style) | |
114 | |
115 left = 0 | |
116 top = 0 #max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) | |
117 self._popup.setPopupPosition(left, top) | |
118 self._popup.setPopupPosition(left, top) | |
119 self._popup.show() | |
120 | |
121 def _timeCb(self, timer): | |
122 if self._popup: | |
123 self._popup.hide() | |
124 del self._popup | |
125 self._popup = None | |
126 | |
127 def _getTarget(self, txt): | |
128 """Say who will receive the messsage | |
129 Return a tuple (target_type, target info)""" | |
130 type = None | |
131 target = None | |
132 if txt.startswith('@@: '): | |
133 type = "PUBLIC" | |
134 elif txt.startswith('@'): | |
135 type = "GROUP" | |
136 _end = txt.find(': ') | |
137 if _end == -1: | |
138 type = "STATUS" | |
139 else: | |
140 target = txt[1:_end] #only one target group is managed for the moment | |
141 if not target in self.host.contact_panel.getGroups(): | |
142 target = None | |
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
|
143 elif self._selected_cache == None: |
33 | 144 type = "STATUS" |
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
|
145 elif isinstance(self._selected_cache, ChatPanel): |
33 | 146 type = "ONE2ONE" |
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
|
147 target = str(self._selected_cache.target) |
33 | 148 else: |
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
|
149 print "Unknown selected host:",self._selected_cache |
33 | 150 type = "UNKNOWN" |
151 return (type, target) | |
152 | |
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
|
153 def 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
|
154 #XXX: woraroung a pyjamas bug: self.currentEvent is not set |
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
|
155 # 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
|
156 # 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
|
157 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
|
158 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
|
159 |
33 | 160 def onKeyPress(self, sender, keycode, modifiers): |
161 _txt = self.getText() | |
162 if not self._popup: | |
163 self.showWarning(self._getTarget(_txt)) | |
164 else: | |
165 _target = self._getTarget(_txt) | |
166 if _target != self._popup.target_data: | |
167 self._timeCb(None) #we remove the popup | |
168 self.showWarning(_target) | |
169 | |
170 self._timer.schedule(2000) | |
171 | |
83 | 172 #if keycode == KEY_ENTER and not self.visible: |
173 if keycode == KEY_ENTER: | |
33 | 174 if _txt: |
175 if _txt.startswith('@'): | |
176 self.host.bridge.call('sendMblog', None, self.getText()) | |
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
|
177 elif self._selected_cache == None: |
33 | 178 self.host.bridge.call('setStatus', None, _txt) |
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
|
179 elif isinstance(self._selected_cache, ChatPanel): |
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
|
180 _chat = self._selected_cache |
33 | 181 mess_type = "groupchat" if _chat.type=='group' else "chat" |
182 self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', mess_type) | |
183 self.setText('') | |
184 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
|
185 sender.cancelKey() |
33 | 186 |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
187 def onMouseUp(self, sender, x, y): |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
188 size = (self.getOffsetWidth(), self.getOffsetHeight()) |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
189 if size != self.__size: |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
190 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
|
191 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
|
192 |
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
|
193 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
|
194 self._selected_cache = selected |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
195 |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
196 """def complete(self): |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
197 |
33 | 198 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
199 #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
|
200 return AutoCompleteTextBox.complete(self)""" |
33 | 201 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
202 class MicroblogItem(): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
203 #XXX: should be moved in a separated module |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
204 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
205 def __init__(self, data): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
206 self.id = data['id'] |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
207 self.content = data['content'] |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
208 self.author = data['author'] |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
209 self.timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
210 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 class MicroblogEntry(SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 |
119 | 213 def __init__(self, host, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
119 | 216 self.author = mblog_entry.author |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
217 self.timestamp = mblog_entry.timestamp |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
218 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 |
119 | 220 self.panel = HTMLPanel(""" |
120
054b7b3424a3
browser side: microblog's entry header with pseudo and timestamp
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
221 <div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div> |
119 | 222 <div class="mb_entry_avatar" id='id_avatar'></div> |
114
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
223 <div class="mb_entry_dialog"> |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
224 <p class="bubble">%(body)s</p> |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
225 </div> |
119 | 226 """ % {"author": html_sanitize(self.author), |
114
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
227 "timestamp": _datetime, |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
228 "body": html_sanitize(mblog_entry.content) |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
229 }) |
119 | 230 self.avatar = Image(host.getAvatar(self.author)) |
231 self.panel.add(self.avatar, "id_avatar") | |
232 self.panel.setStyleName('mb_entry') | |
233 self.add(self.panel) | |
234 | |
235 def updateAvatar(self, new_avatar): | |
236 """Change the avatar of the entry | |
237 @param new_avatar: path to the new image""" | |
238 self.avatar.setUrl(new_avatar) | |
239 | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 |
195 | 241 class MicroblogPanel(base_widget.LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
243 def __init__(self, host, accepted_groups): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 """Panel used to show microblog |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
245 @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
|
246 """ |
195 | 247 base_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups)) |
248 #base_widget.ScrollPanelWrapper.__init__(self) | |
83 | 249 #DropCell.__init__(self) |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
250 self.accepted_groups = accepted_groups |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
251 self.entries = {} |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 self.vpanel = VerticalPanel() |
83 | 253 self.vpanel.setStyleName('microblogPanel') |
34 | 254 self.setWidget(self.vpanel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 |
195 | 256 @classmethod |
257 def registerClass(cls): | |
258 base_widget.LiberviaWidget.addDropKey("GROUP", cls.onDropCreateGroup) | |
259 base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", cls.onDropCreateMeta) | |
260 | |
261 @classmethod | |
262 def onDropCreateGroup(cls, host, item): | |
263 _new_panel = MicroblogPanel(host, [item]) #XXX: pyjamas doesn't support use of cls directly | |
264 _new_panel.setAcceptedGroup(item) | |
265 host.FillMicroblogPanel(_new_panel) | |
266 host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, 'GROUP', [item], 10) | |
267 return _new_panel | |
268 | |
269 @classmethod | |
270 def onDropCreateMeta(cls, host, item): | |
271 _new_panel = MicroblogPanel(host, []) #XXX: pyjamas doesn't support use of cls directly | |
272 host.FillMicroblogPanel(_new_panel) | |
273 host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, 'ALL', [], 10) | |
274 return _new_panel | |
275 | |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
276 def accept_all(self): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
277 return not self.accepted_groups #we accept every microblog only if we are not filtering by groups |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
278 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
279 def getEntries(self): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
280 """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
|
281 and fill the panel""" |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
282 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
283 def massiveInsert(self, mblogs): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
284 """Insert several microblogs at once |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
285 @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
|
286 """ |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
287 print "Massive insertion of microblogs" |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
288 for publisher in mblogs: |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
289 print "adding blogs for [%s]" % publisher |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
290 for mblog in mblogs[publisher]: |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
291 if not mblog.has_key('content'): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
292 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
|
293 continue |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
294 mblog_entry = MicroblogItem(mblog) |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
295 self.addEntry(mblog_entry) |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
296 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
297 def addEntry(self, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 """Add an entry to the panel |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
299 @param mblog_entry: MicroblogItem instance |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
300 """ |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
301 if mblog_entry.id in self.entries: |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
302 return |
119 | 303 _entry = MicroblogEntry(self.host, mblog_entry) |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
304 self.entries[mblog_entry.id] = _entry |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
305 |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
306 # we look for the right index to insert our entry: |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
307 # we insert the entry above the first entry |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
308 # in the past |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
309 idx = 0 |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
310 for child in self.vpanel.children: |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
311 if not isinstance(child, MicroblogEntry): |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
312 break |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
313 if child.timestamp < mblog_entry.timestamp: |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
314 break |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
315 idx+=1 |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
316 self.vpanel.insert(_entry,idx) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 |
119 | 318 def updateValue(self, type, jid, value): |
319 """Update a jid value in entries | |
320 @param type: one of 'avatar', 'nick' | |
321 @param jid: jid concerned | |
322 @param value: new value""" | |
323 if type=='avatar': | |
324 for entry in self.entries.values(): | |
325 if entry.author == jid: | |
326 entry.updateAvatar(value) | |
327 | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 def setAcceptedGroup(self, group): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 """Set the group which can be displayed in this panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 @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
|
331 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 if isinstance(group, list): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 self.accepted_groups.extend(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 else: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 self.accepted_groups.append(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 def isJidAccepted(self, jid): |
163
b887186e8fc8
browser side: get entity's microblogs for newly added contacts
Goffi <goffi@goffi.org>
parents:
148
diff
changeset
|
338 """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
|
339 @param jid: jid |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 @return: True if the jid is accepted""" |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
341 if self.accept_all(): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 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
|
344 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
|
345 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 return False |
19 | 347 |
20 | 348 class StatusPanel(HTMLPanel, ClickHandler): |
349 def __init__(self, host, status=''): | |
350 self.host = host | |
351 self.status = status or ' ' | |
19 | 352 HTMLPanel.__init__(self, self.__getContent()) |
20 | 353 self.setStyleName('statusPanel') |
354 ClickHandler.__init__(self) | |
355 self.addClickListener(self) | |
19 | 356 |
357 def __getContent(self): | |
51 | 358 return "<span class='status'>%(status)s</span>" % {'status':html_sanitize(self.status)} |
19 | 359 |
360 def changeStatus(self, new_status): | |
20 | 361 self.status = new_status or ' ' |
19 | 362 self.setHTML(self.__getContent()) |
363 | |
62 | 364 def onClick(self, sender): |
20 | 365 #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
|
366 self.host.setSelected(None) |
20 | 367 |
19 | 368 class ChatText(HTMLPanel): |
369 | |
370 def __init__(self, timestamp, nick, mymess, msg): | |
371 _date = datetime.fromtimestamp(float(timestamp or time())) | |
372 _msg_class = ["chat_text_msg"] | |
373 if mymess: | |
374 _msg_class.append("chat_text_mymess") | |
375 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>" % | |
376 {"timestamp": _date.strftime("%H:%M"), | |
51 | 377 "nick": "[%s]" % html_sanitize(nick), |
19 | 378 "msg_class": ' '.join(_msg_class), |
51 | 379 "msg": html_sanitize(msg)} |
19 | 380 ) |
381 self.setStyleName('chatText') | |
33 | 382 |
383 class Occupant(HTML): | |
384 """Occupant of a MUC room""" | |
385 | |
386 def __init__(self, nick): | |
387 self.nick = nick | |
35 | 388 HTML.__init__(self, "<div class='occupant'>%s</div>" % html_sanitize(nick)) |
389 | |
390 def __str__(self): | |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
391 return self.nick |
33 | 392 |
393 class OccupantsList(AbsolutePanel): | |
394 """Panel user to show occupants of a room""" | |
395 | |
396 def __init__(self): | |
397 AbsolutePanel.__init__(self) | |
35 | 398 self.occupants_list = {} |
33 | 399 self.setStyleName('occupantsList') |
400 | |
401 def addOccupant(self, nick): | |
35 | 402 _occupant = Occupant(nick) |
403 self.occupants_list[nick] = _occupant | |
404 self.add(_occupant) | |
33 | 405 |
35 | 406 def removeOccupant(self, nick): |
407 try: | |
408 self.remove(self.occupants_list[nick]) | |
409 except KeyError: | |
410 print "ERROR: trying to remove an unexisting nick" | |
411 | |
412 def clear(self): | |
413 self.occupants_list.clear() | |
414 AbsolutePanel.clear(self) | |
415 | |
195 | 416 class ChatPanel(base_widget.LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
418 def __init__(self, host, target, type_='one2one'): |
19 | 419 """Panel used for conversation (one 2 one or group chat) |
420 @param host: SatWebFrontend instance | |
421 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) | |
422 @param type: one2one for simple conversation, group for MUC""" | |
195 | 423 base_widget.LiberviaWidget.__init__(self, host, target.bare, selectable = True) |
34 | 424 self.vpanel = VerticalPanel() |
425 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
|
426 self.type = type_ |
33 | 427 self.nick = None |
19 | 428 if not target: |
429 print "ERROR: Empty target !" | |
430 return | |
431 self.target = target | |
84 | 432 self.__body = AbsolutePanel() |
433 self.__body.setStyleName('chatPanel_body') | |
33 | 434 chat_area = HorizontalPanel() |
435 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
|
436 if type_ == 'group': |
33 | 437 self.occupants_list = OccupantsList() |
438 chat_area.add(self.occupants_list) | |
84 | 439 self.__body.add(chat_area) |
33 | 440 self.content = AbsolutePanel() |
441 self.content.setStyleName('chatContent') | |
195 | 442 self.content_scroll = base_widget.ScrollPanelWrapper(self.content) |
34 | 443 chat_area.add(self.content_scroll) |
444 chat_area.setCellWidth(self.content_scroll, '100%') | |
84 | 445 self.vpanel.add(self.__body) |
446 self.addStyleName('chatPanel') | |
34 | 447 self.setWidget(self.vpanel) |
19 | 448 |
84 | 449 """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
|
450 #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
|
451 #for the same reason as doAttachChildren |
195 | 452 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
|
453 |
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
|
454 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
|
455 #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
|
456 #the event will not propagate to children |
195 | 457 base_widget.ScrollPanelWrapper.doAttachChildren(self)""" |
458 | |
459 @classmethod | |
460 def registerClass(cls): | |
461 base_widget.LiberviaWidget.addDropKey("CONTACT", cls.onDropCreate) | |
462 | |
463 @classmethod | |
464 def onDropCreate(cls, host, item): | |
465 _contact = JID(item) | |
466 host.contact_panel.setContactMessageWaiting(_contact.bare, False) | |
467 _new_panel = ChatPanel(host, _contact) #XXX: pyjamas doesn't seems to support creating with cls directly | |
468 _new_panel.historyPrint() | |
469 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
|
470 |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
471 def onQuit(self): |
195 | 472 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
|
473 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
|
474 self.host.bridge.call('mucLeave', None, self.target.bare) |
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
475 |
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
476 |
19 | 477 def setUserNick(self, nick): |
478 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
479 self.nick = nick | |
33 | 480 |
481 def setPresents(self, nicks): | |
482 """Set the users presents in this room | |
483 @param occupants: list of nicks (string)""" | |
35 | 484 self.occupants_list.clear() |
33 | 485 for nick in nicks: |
486 self.occupants_list.addOccupant(nick) | |
487 | |
35 | 488 def userJoined(self, nick, data): |
489 self.occupants_list.addOccupant(nick) | |
490 self.printInfo("=> %s has joined the room" % nick) | |
491 | |
492 def userLeft(self, nick, data): | |
493 self.occupants_list.removeOccupant(nick) | |
494 self.printInfo("<= %s has left the room" % nick) | |
495 | |
19 | 496 def historyPrint(self, size=20): |
497 """Print the initial history""" | |
498 def getHistoryCB(history): | |
123 | 499 for line in history: |
137 | 500 timestamp, from_jid, to_jid, message, mess_type = line |
123 | 501 self.printMessage(from_jid, message, timestamp) |
502 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True) | |
35 | 503 |
504 def printInfo(self, msg, type='normal'): | |
505 """Print general info | |
506 @param msg: message to print | |
507 @type: one of: | |
508 normal: general info like "toto has joined the room" | |
509 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
510 """ | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
511 _wid = Label(msg) |
35 | 512 if type == 'normal': |
513 _wid.setStyleName('chatTextInfo') | |
514 elif type == 'me': | |
515 _wid.setStyleName('chatTextMe') | |
516 else: | |
517 _wid.setStyleName('chatTextInfo') | |
518 self.content.add(_wid) | |
519 | |
520 | |
19 | 521 def printMessage(self, from_jid, msg, timestamp=None): |
522 """Print message in chat window. Must be implemented by child class""" | |
523 _jid=JID(from_jid) | |
33 | 524 nick = _jid.node if self.type=='one2one' else _jid.resource |
525 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 | 526 if msg.startswith('/me '): |
19 | 527 self.printInfo('* %s %s' % (nick, msg[4:]),type='me') |
35 | 528 return |
19 | 529 self.content.add(ChatText(timestamp, nick, mymess, msg)) |
34 | 530 self.content_scroll.scrollToBottom() |
36 | 531 |
532 def startGame(self, game_type, referee, players): | |
533 """Configure the chat window to start a game""" | |
534 if game_type=="Tarot": | |
167
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
535 if hasattr(self, "tarot_panel"): |
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
536 return |
36 | 537 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
|
538 self.vpanel.insert(self.tarot_panel, 0) |
36 | 539 self.vpanel.setCellHeight(self.tarot_panel, self.tarot_panel.getHeight()) |
127 | 540 elif game_type=="RadioCol": |
167
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
541 #XXX: We can have double panel if we join quickly enough to have the group chat start signal |
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
542 # 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
|
543 if hasattr(self, "radiocol_panel"): |
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
544 return |
127 | 545 self.radiocol_panel = RadioColPanel(self, referee, self.nick) |
546 self.vpanel.insert(self.radiocol_panel, 0) | |
547 self.vpanel.setCellHeight(self.radiocol_panel, self.radiocol_panel.getHeight()) | |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
548 |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
549 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
550 """Return class managing the game type""" |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
551 #TODO: check that the game is launched, and manage errors |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
552 if game_type=="Tarot": |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
553 return self.tarot_panel |
128 | 554 elif game_type=="RadioCol": |
555 return self.radiocol_panel | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
556 |
195 | 557 class WebPanel(base_widget.LiberviaWidget): |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
558 """ (mini)browser like widget """ |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
559 |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
560 def __init__(self, host, url=None): |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
561 """ |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
562 @param host: SatWebFrontend instance |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
563 """ |
195 | 564 base_widget.LiberviaWidget.__init__(self, host) |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
565 self._vpanel = VerticalPanel() |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
566 self._vpanel.setSize('100%', '100%') |
191
8213e22c1120
browser side: WebPanel now react on [ENTER] press on URL textBox
Goffi <goffi@goffi.org>
parents:
190
diff
changeset
|
567 self._url = dialog.ExtTextBox(enter_cb = self.onUrlClick) |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
568 self._url.setText(url or "") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
569 self._url.setWidth('100%') |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
570 hpanel = HorizontalPanel() |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
571 hpanel.add(self._url) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
572 btn = Button("Go", self.onUrlClick) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
573 hpanel.setCellWidth(self._url, "100%") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
574 #self.setCellWidth(btn, "10%") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
575 hpanel.add(self._url) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
576 hpanel.add(btn) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
577 self._vpanel.add(hpanel) |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
578 self._vpanel.setCellHeight(hpanel, '20px') |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
579 self._frame = Frame(url or "") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
580 self._frame.setSize('100%', '100%') |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
581 DOM.setStyleAttribute(self._frame.getElement(), "position", "relative") |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
582 self._vpanel.add(self._frame) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
583 self.setWidget(self._vpanel) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
584 |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
585 def onUrlClick(self, sender): |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
586 self._frame.setUrl(self._url.getText()) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
587 |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
588 class ContactTabPanel(HorizontalPanel): |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
589 """ TabPanel with a contacts list which can be hidden """ |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
590 |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
591 def __init__(self, host, locked = False): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
592 self.host=host |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
593 HorizontalPanel.__init__(self) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
594 self._left = VerticalPanel() |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
595 contacts_switch = Button('<<', self._contactsSwitch) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
596 contacts_switch.addStyleName('contactsSwitch') |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
597 self._left.add(contacts_switch) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
598 self._left.add(self.host.contact_panel) |
195 | 599 self._right = base_widget.WidgetsPanel(host) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
600 self._right.setWidth('100%') |
34 | 601 self._right.setHeight('100%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
602 self.add(self._left) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
603 self.add(self._right) |
83 | 604 self.setCellWidth(self._right, "100%") |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
605 |
83 | 606 def addWidget(self, wid): |
607 """Add a widget to the WidgetsPanel""" | |
608 print "main addWidget", wid | |
609 self._right.addWidget(wid) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
610 |
33 | 611 class MainPanel(AbsolutePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
612 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
613 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
614 self.host=host |
33 | 615 AbsolutePanel.__init__(self) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
616 |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
617 #menu |
23 | 618 menu = Menu(host) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
619 |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
620 #unibox |
33 | 621 unibox_panel = UniBoxPanel(host) |
622 self.host.setUniBox(unibox_panel.unibox) | |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
623 |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
624 #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
|
625 status = host.status_panel |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
626 |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
627 #contacts |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
628 _contacts = VerticalPanel() |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
629 contacts_switch = Button('<<', self._contactsSwitch) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
630 contacts_switch.addStyleName('contactsSwitch') |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
631 _contacts.add(contacts_switch) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
632 _contacts.add(self.host.contact_panel) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
633 |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
634 #tabs |
195 | 635 self.tab_panel = base_widget.MainTabPanel(host) |
636 self.discuss_panel = base_widget.WidgetsPanel(self.host, locked=True) | |
23 | 637 self.tab_panel.add(self.discuss_panel, "Discussions") |
638 self.tab_panel.selectTab(0) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
639 |
109
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
640 header=AbsolutePanel() |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
641 header.add(menu) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
642 header.add(unibox_panel) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
643 header.add(status) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
644 header.setStyleName('header') |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
645 self.add(header) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
646 |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
647 _hpanel = HorizontalPanel() |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
648 _hpanel.add(_contacts) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
649 _hpanel.add(self.tab_panel) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
650 self.add(_hpanel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
651 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
652 self.setWidth("100%") |
33 | 653 Window.addWindowResizeListener(self) |
654 | |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
655 def _contactsSwitch(self, btn): |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
656 """ (Un)hide contacts panel """ |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
657 cpanel = self.host.contact_panel |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
658 cpanel.setVisible(not cpanel.getVisible()) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
659 btn.setText("<<" if cpanel.getVisible() else ">>") |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
660 self.host.resize() |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
661 |
33 | 662 def onWindowResized(self, width, height): |
663 _elts = doc().getElementsByClassName('gwt-TabBar') | |
664 if not _elts.length: | |
665 tab_bar_h = 0 | |
666 else: | |
667 tab_bar_h = _elts.item(0).offsetHeight | |
668 ideal_height = Window.getClientHeight() - tab_bar_h | |
669 self.setHeight("%s%s" % (ideal_height, "px")); | |
670 |