Mercurial > libervia-web
annotate browser_side/panels.py @ 210:3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
fix bug 15
fix bug 33
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 06 Sep 2013 15:40:33 +0200 |
parents | 4d7054542751 |
children | 8bbac49765d6 |
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 |
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
|
51 |
33 | 52 class UniBoxPanel(SimplePanel): |
53 """Panel containing the UniBox""" | |
54 | |
55 def __init__(self, host): | |
56 SimplePanel.__init__(self) | |
57 self.setStyleName('uniBoxPanel') | |
58 self.unibox = UniBox(host) | |
59 self.unibox.setWidth('100%') | |
60 self.add(self.unibox) | |
61 | |
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
|
62 |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
63 class UniBox(TextArea, MouseHandler): #AutoCompleteTextBox): |
33 | 64 """This text box is used as a main typing point, for message, microblog, etc""" |
65 | |
66 def __init__(self, host): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
67 TextArea.__init__(self) |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
68 #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
|
69 self.__size = (0, 0) |
33 | 70 self._popup = None |
71 self._timer = Timer(notify=self._timeCb) | |
72 self.host = host | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
73 self.setStyleName('uniBox') |
83 | 74 self.addKeyboardListener(self) |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
75 MouseHandler.__init__(self) |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
76 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
|
77 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
|
78 host.addSelectedListener(self.onSelectedChange) |
33 | 79 |
80 def addKey(self, key): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
81 return |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
82 #self.getCompletionItems().completions.append(key) |
33 | 83 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
84 def removeKey(self, key): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
85 try: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
86 self.getCompletionItems().completions.remove(key) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
87 except KeyError: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
88 print "WARNING: trying to remove an unknown key" |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
89 |
33 | 90 def showWarning(self, target_data): |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
91 target_hook, _type, msg = target_data |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
92 if _type == "NONE": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
93 return |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
94 if not msg: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
95 print "WARNING: no msg set uniBox warning" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
96 return |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
97 if _type == "PUBLIC": |
33 | 98 style = "targetPublic" |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
99 elif _type == "GROUP": |
33 | 100 style = "targetGroup" |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
101 elif _type == "STATUS": |
33 | 102 msg = "This will be your new status message" |
103 style = "targetStatus" | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
104 elif _type == "ONE2ONE": |
33 | 105 style = "targetOne2One" |
106 else: | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
107 print "ERROR: unknown message type" |
33 | 108 return |
109 contents = HTML(msg) | |
110 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
111 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
33 | 112 self._popup.target_data = target_data |
113 self._popup.add(contents) | |
114 self._popup.setStyleName("warningPopup") | |
115 if style: | |
116 self._popup.addStyleName(style) | |
117 | |
118 left = 0 | |
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
|
119 top = 0 #max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) |
33 | 120 self._popup.setPopupPosition(left, top) |
121 self._popup.show() | |
122 | |
123 def _timeCb(self, timer): | |
124 if self._popup: | |
125 self._popup.hide() | |
126 del self._popup | |
127 self._popup = None | |
128 | |
129 def _getTarget(self, txt): | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
130 """ Say who will receive the messsage |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
131 @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
|
132 - 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
|
133 - 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
|
134 - 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
|
135 target = self._selected_cache |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
136 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
137 def getSelectedOrStatus(): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
138 if target: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
139 _type, msg = target.getWarningData() |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
140 target_hook = None # we use the selected widget, not a hook |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
141 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
142 _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
|
143 target_hook = (txt, None) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
144 return (target_hook, _type, msg) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
145 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
146 if not txt.startswith('@'): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
147 target_hook, _type, msg = getSelectedOrStatus() |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
148 elif txt.startswith('@@: '): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
149 _type = "PUBLIC" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
150 msg = MicroblogPanel.warning_msg_public |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
151 target_hook = (txt[4:], None) |
33 | 152 elif txt.startswith('@'): |
153 _end = txt.find(': ') | |
154 if _end == -1: | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
155 target_hook, _type, msg = getSelectedOrStatus() |
33 | 156 else: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
157 group = txt[1:_end] #only one target group is managed for the moment |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
158 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
|
159 # 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
|
160 group = None |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
161 target_hook, _type, msg = getSelectedOrStatus() |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
162 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
163 _type = "GROUP" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
164 msg = MicroblogPanel.warning_msg_group % group |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
165 target_hook = (txt[_end+2:], group) |
33 | 166 else: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
167 print "ERROR: Unknown target" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
168 target_hook, _type, msg = getSelectedOrStatus() |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
169 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
170 return (target_hook, _type, msg) |
33 | 171 |
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
|
172 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
|
173 #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
|
174 # 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
|
175 # 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
|
176 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
|
177 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
|
178 |
33 | 179 def onKeyPress(self, sender, keycode, modifiers): |
180 _txt = self.getText() | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
181 target = self._getTarget(_txt) |
33 | 182 if not self._popup: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
183 self.showWarning(target) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
184 elif target != self._popup.target_data: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
185 self._timeCb(None) #we remove the popup |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
186 self.showWarning(target) |
33 | 187 |
188 self._timer.schedule(2000) | |
189 | |
83 | 190 #if keycode == KEY_ENTER and not self.visible: |
191 if keycode == KEY_ENTER: | |
33 | 192 if _txt: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
193 target_hook, _type, msg = target |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
194 if target_hook: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
195 parsed_txt, data = target_hook |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
196 if _type == "PUBLIC": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
197 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
|
198 elif _type == "GROUP": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
199 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
|
200 elif _type == "STATUS": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
201 self.host.bridge.call('setStatus', None, parsed_txt) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
202 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
203 print "ERROR: Unknown target hook type" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
204 else: #we send the message to the selected target |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
205 self._selected_cache.onTextEntered(_txt) |
33 | 206 self.setText('') |
207 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
|
208 sender.cancelKey() |
33 | 209 |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
210 def onMouseUp(self, sender, x, y): |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
211 size = (self.getOffsetWidth(), self.getOffsetHeight()) |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
212 if size != self.__size: |
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
213 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
|
214 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
|
215 |
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
|
216 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
|
217 self._selected_cache = selected |
186
72bb1d845b6a
browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
218 |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
219 """def complete(self): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
220 |
33 | 221 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
222 #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
|
223 return AutoCompleteTextBox.complete(self)""" |
33 | 224 |
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
|
225 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
226 class MicroblogItem(): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
227 #XXX: should be moved in a separated module |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
228 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
229 def __init__(self, data): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
230 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
|
231 self.type = data.get('type', 'main_item') |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
232 self.content = data['content'] |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
233 self.author = data['author'] |
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
|
234 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
|
235 self.comments = data.get('comments', False) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
236 if self.comments: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
237 try: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
238 self.comments_hash = (data['comments_service'], data['comments_node']) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
239 self.comments_service = data['comments_service'] |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
240 self.comments_node = data['comments_node'] |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
241 except KeyError: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
242 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
|
243 self.comments = False |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
244 if set(("service","node")).issubset(data.keys()): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
245 self.service = data["service"] |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
246 self.node = data["node"] |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
247 self.hash = (self.service, self.node) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
248 |
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
|
249 |
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
|
250 class MicroblogEntry(SimplePanel, ClickHandler): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 |
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
|
252 def __init__(self, blog_panel, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 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
|
254 self._blog_panel = blog_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 |
119 | 256 self.author = mblog_entry.author |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
257 self.timestamp = mblog_entry.timestamp |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
258 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
259 self.comments = mblog_entry.comments |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 |
119 | 261 self.panel = HTMLPanel(""" |
120
054b7b3424a3
browser side: microblog's entry header with pseudo and timestamp
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
262 <div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div> |
119 | 263 <div class="mb_entry_avatar" id='id_avatar'></div> |
114
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
264 <div class="mb_entry_dialog"> |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
265 <p class="bubble">%(body)s</p> |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
266 </div> |
119 | 267 """ % {"author": html_sanitize(self.author), |
114
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
268 "timestamp": _datetime, |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
269 "body": html_sanitize(mblog_entry.content) |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
270 }) |
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
|
271 self.avatar = Image(blog_panel.host.getAvatar(self.author)) |
119 | 272 self.panel.add(self.avatar, "id_avatar") |
273 self.panel.setStyleName('mb_entry') | |
274 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
|
275 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
|
276 self.addClickListener(self) |
119 | 277 |
278 def updateAvatar(self, new_avatar): | |
279 """Change the avatar of the entry | |
280 @param new_avatar: path to the new image""" | |
281 self.avatar.setUrl(new_avatar) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
282 |
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
|
283 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
|
284 print "microblog entry selected (author=%s)" % self.author |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
285 self._blog_panel.setSelectedEntry(self if self.comments else None) |
119 | 286 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 |
195 | 288 class MicroblogPanel(base_widget.LiberviaWidget): |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
289 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
|
290 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
|
291 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
292 def __init__(self, host, accepted_groups): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 """Panel used to show microblog |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
294 @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
|
295 """ |
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
|
296 base_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups), selectable = True) |
195 | 297 #base_widget.ScrollPanelWrapper.__init__(self) |
83 | 298 #DropCell.__init__(self) |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
299 self.accepted_groups = accepted_groups |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
300 self.entries = {} |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
301 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
|
302 self.selected_entry = None |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 self.vpanel = VerticalPanel() |
83 | 304 self.vpanel.setStyleName('microblogPanel') |
34 | 305 self.setWidget(self.vpanel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 |
195 | 307 @classmethod |
308 def registerClass(cls): | |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
199
diff
changeset
|
309 base_widget.LiberviaWidget.addDropKey("GROUP", cls.createGroup) |
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
199
diff
changeset
|
310 base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", cls.createMeta) |
195 | 311 |
312 @classmethod | |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
199
diff
changeset
|
313 def createGroup(cls, host, item): |
195 | 314 _new_panel = MicroblogPanel(host, [item]) #XXX: pyjamas doesn't support use of cls directly |
315 _new_panel.setAcceptedGroup(item) | |
316 host.FillMicroblogPanel(_new_panel) | |
317 host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, 'GROUP', [item], 10) | |
318 return _new_panel | |
319 | |
320 @classmethod | |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
199
diff
changeset
|
321 def createMeta(cls, host, item): |
195 | 322 _new_panel = MicroblogPanel(host, []) #XXX: pyjamas doesn't support use of cls directly |
323 host.FillMicroblogPanel(_new_panel) | |
324 host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, 'ALL', [], 10) | |
325 return _new_panel | |
326 | |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
327 def getWarningData(self): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
328 if self.selected_entry: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
329 if not self.selected_entry.comments: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
330 print ("ERROR: an item without comment is selected") |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
331 return ("NONE", None) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
332 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
|
333 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
334 elif not self.accepted_groups: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
335 # we have a meta MicroblogPanel, we publish publicly |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
336 return ("PUBLIC", self.warning_msg_public) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
337 else: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
338 # we only accept one group at the moment |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
339 # FIXME: manage several groups |
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
|
340 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
|
341 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
342 def onTextEntered(self, text): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
343 if self.selected_entry: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
344 # we are entering a comment |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
345 comments_node = self.selected_entry.comments |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
346 if not comments_node: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
347 raise Exception("ERROR: comments node is empty") |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
348 self.host.bridge.call("sendMblogComment", None, comments_node, text) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
349 elif not self.accepted_groups: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
350 # we are entering a public microblog |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
351 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
|
352 else: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
353 # 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
|
354 # FIXME: manage several groups |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
355 self.host.bridge.call("sendMblog", None, "GROUP", self.accepted_groups[0], text) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
356 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
357 def accept_all(self): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
358 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
|
359 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
360 def getEntries(self): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
361 """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
|
362 and fill the panel""" |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
363 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
364 def massiveInsert(self, mblogs): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
365 """Insert several microblogs at once |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
366 @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
|
367 """ |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
368 print "Massive insertion of microblogs" |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
369 for publisher in mblogs: |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
370 print "adding blogs for [%s]" % publisher |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
371 for mblog in mblogs[publisher]: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
372 if not "content" in mblog: |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
373 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
|
374 continue |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
375 mblog_item = MicroblogItem(mblog) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
376 self.addEntry(mblog_item) |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
377 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
378 def mblogsInsert(self, mblogs): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
379 """ Insert several microblogs at once |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
380 @param mblogs: list of microblogs |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
381 """ |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
382 for mblog in mblogs: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
383 if not "content" in mblog: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
384 print ("WARNING: No content found in microblog [%s]", mblog) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
385 continue |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
386 mblog_item = MicroblogItem(mblog) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
387 self.addEntry(mblog_item) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
388 |
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
|
389 def _chronoInsert(self, vpanel, entry, reverse=True): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
390 """ Insert an entry in chronological order |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
391 @param vpanel: VerticalPanel instance |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
392 @param entry: MicroblogEntry |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
393 @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
|
394 # we look for the right index to insert our entry: |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
395 # 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
|
396 # in the past |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
397 idx = 0 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
398 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
399 for child in vpanel.children: |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
400 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
|
401 idx += 1 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
402 continue |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
403 if reverse: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
404 if child.timestamp < entry.timestamp: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
405 break |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
406 else: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
407 if child.timestamp > entry.timestamp: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
408 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
|
409 idx += 1 |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
410 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
411 vpanel.insert(entry, idx) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
412 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
413 def addEntry(self, mblog_item): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
414 """Add an entry to the panel |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
415 @param mblog_item: MicroblogItem instance |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
416 """ |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
417 if mblog_item.type == "comment": |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
418 if not mblog_item.hash in self.comments: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
419 # The comments node is not known in this panel |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
420 return |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
421 _entry = MicroblogEntry(self, mblog_item) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
422 parent = self.comments[mblog_item.hash] |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
423 parent_idx = self.vpanel.getWidgetIndex(parent) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
424 # 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
|
425 try: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
426 sub_panel = self.vpanel.getWidget(parent_idx+1) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
427 except IndexError: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
428 sub_panel = None |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
429 if not sub_panel or not isinstance(sub_panel, VerticalPanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
430 sub_panel = VerticalPanel() |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
431 sub_panel.setStyleName('microblogPanel') |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
432 sub_panel.addStyleName('subPanel') |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
433 self.vpanel.insert(sub_panel, parent_idx+1) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
434 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
435 # we want comments to be inserted in chronological order |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
436 self._chronoInsert(sub_panel, _entry, reverse=False) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
437 return |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
438 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
439 if mblog_item.id in self.entries: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
440 return |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
441 _entry = MicroblogEntry(self, mblog_item) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
442 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
443 self.entries[mblog_item.id] = _entry |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
444 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
445 self._chronoInsert(self.vpanel, _entry) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
446 |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
447 if mblog_item.comments: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
448 # entry has comments, we keep the comment node as a reference |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
449 self.comments[mblog_item.comments_hash] = _entry |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
450 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
|
451 |
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
|
452 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 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
|
460 |
119 | 461 def updateValue(self, type, jid, value): |
462 """Update a jid value in entries | |
463 @param type: one of 'avatar', 'nick' | |
464 @param jid: jid concerned | |
465 @param value: new value""" | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
466 def updateVPanel(vpanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
467 for child in vpanel.children: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
468 if isinstance(child, MicroblogEntry) and child.author == jid: |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
469 child.updateAvatar(value) |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
470 elif isinstance(child, VerticalPanel): |
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
471 updateVPanel(child) |
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
|
472 if type == 'avatar': |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
473 updateVPanel(self.vpanel) |
119 | 474 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 def setAcceptedGroup(self, group): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 """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
|
477 @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
|
478 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 if isinstance(group, list): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 self.accepted_groups.extend(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
481 else: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 self.accepted_groups.append(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
484 def isJidAccepted(self, jid): |
163
b887186e8fc8
browser side: get entity's microblogs for newly added contacts
Goffi <goffi@goffi.org>
parents:
148
diff
changeset
|
485 """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
|
486 @param jid: jid |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 @return: True if the jid is accepted""" |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
488 if self.accept_all(): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
489 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
490 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
|
491 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
|
492 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 return False |
19 | 494 |
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 |
20 | 496 class StatusPanel(HTMLPanel, ClickHandler): |
497 def __init__(self, host, status=''): | |
498 self.host = host | |
499 self.status = status or ' ' | |
19 | 500 HTMLPanel.__init__(self, self.__getContent()) |
20 | 501 self.setStyleName('statusPanel') |
502 ClickHandler.__init__(self) | |
503 self.addClickListener(self) | |
19 | 504 |
505 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
|
506 return "<span class='status'>%(status)s</span>" % {'status': html_sanitize(self.status)} |
19 | 507 |
508 def changeStatus(self, new_status): | |
20 | 509 self.status = new_status or ' ' |
19 | 510 self.setHTML(self.__getContent()) |
511 | |
62 | 512 def onClick(self, sender): |
20 | 513 #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
|
514 self.host.setSelected(None) |
20 | 515 |
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
|
516 |
19 | 517 class ChatText(HTMLPanel): |
518 | |
519 def __init__(self, timestamp, nick, mymess, msg): | |
520 _date = datetime.fromtimestamp(float(timestamp or time())) | |
521 _msg_class = ["chat_text_msg"] | |
522 if mymess: | |
523 _msg_class.append("chat_text_mymess") | |
524 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
|
525 {"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
|
526 "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
|
527 "msg_class": ' '.join(_msg_class), |
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
|
528 "msg": html_sanitize(msg)} |
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
|
529 ) |
19 | 530 self.setStyleName('chatText') |
33 | 531 |
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
|
532 |
33 | 533 class Occupant(HTML): |
534 """Occupant of a MUC room""" | |
535 | |
536 def __init__(self, nick): | |
537 self.nick = nick | |
35 | 538 HTML.__init__(self, "<div class='occupant'>%s</div>" % html_sanitize(nick)) |
539 | |
540 def __str__(self): | |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
541 return self.nick |
33 | 542 |
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
|
543 |
33 | 544 class OccupantsList(AbsolutePanel): |
545 """Panel user to show occupants of a room""" | |
546 | |
547 def __init__(self): | |
548 AbsolutePanel.__init__(self) | |
35 | 549 self.occupants_list = {} |
33 | 550 self.setStyleName('occupantsList') |
551 | |
552 def addOccupant(self, nick): | |
35 | 553 _occupant = Occupant(nick) |
554 self.occupants_list[nick] = _occupant | |
555 self.add(_occupant) | |
33 | 556 |
35 | 557 def removeOccupant(self, nick): |
558 try: | |
559 self.remove(self.occupants_list[nick]) | |
560 except KeyError: | |
561 print "ERROR: trying to remove an unexisting nick" | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
562 |
35 | 563 def clear(self): |
564 self.occupants_list.clear() | |
565 AbsolutePanel.clear(self) | |
566 | |
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
|
567 |
195 | 568 class ChatPanel(base_widget.LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
569 |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
570 def __init__(self, host, target, type_='one2one'): |
19 | 571 """Panel used for conversation (one 2 one or group chat) |
572 @param host: SatWebFrontend instance | |
573 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) | |
574 @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
|
575 base_widget.LiberviaWidget.__init__(self, host, target.bare, selectable=True) |
34 | 576 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
|
577 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
|
578 self.type = type_ |
33 | 579 self.nick = None |
19 | 580 if not target: |
581 print "ERROR: Empty target !" | |
582 return | |
583 self.target = target | |
84 | 584 self.__body = AbsolutePanel() |
585 self.__body.setStyleName('chatPanel_body') | |
33 | 586 chat_area = HorizontalPanel() |
587 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
|
588 if type_ == 'group': |
33 | 589 self.occupants_list = OccupantsList() |
590 chat_area.add(self.occupants_list) | |
84 | 591 self.__body.add(chat_area) |
33 | 592 self.content = AbsolutePanel() |
593 self.content.setStyleName('chatContent') | |
195 | 594 self.content_scroll = base_widget.ScrollPanelWrapper(self.content) |
34 | 595 chat_area.add(self.content_scroll) |
596 chat_area.setCellWidth(self.content_scroll, '100%') | |
84 | 597 self.vpanel.add(self.__body) |
598 self.addStyleName('chatPanel') | |
34 | 599 self.setWidget(self.vpanel) |
19 | 600 |
84 | 601 """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
|
602 #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
|
603 #for the same reason as doAttachChildren |
195 | 604 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
|
605 |
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
|
606 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
|
607 #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
|
608 #the event will not propagate to children |
195 | 609 base_widget.ScrollPanelWrapper.doAttachChildren(self)""" |
610 | |
611 @classmethod | |
612 def registerClass(cls): | |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
199
diff
changeset
|
613 base_widget.LiberviaWidget.addDropKey("CONTACT", cls.createChat) |
195 | 614 |
615 @classmethod | |
200
0f5c2f799913
browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
Goffi <goffi@goffi.org>
parents:
199
diff
changeset
|
616 def createChat(cls, host, item): |
195 | 617 _contact = JID(item) |
618 host.contact_panel.setContactMessageWaiting(_contact.bare, False) | |
619 _new_panel = ChatPanel(host, _contact) #XXX: pyjamas doesn't seems to support creating with cls directly | |
620 _new_panel.historyPrint() | |
621 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
|
622 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
623 def getWarningData(self): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
624 if self.type not in ["one2one", "group"]: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
625 raise Exception("Unmanaged type !") |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
626 if self.type == "one2one": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
627 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
|
628 elif self.type == "group": |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
629 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
|
630 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
|
631 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
632 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
|
633 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
|
634 self.host.bridge.call('sendMessage', None, str(self.target), text, '', mess_type) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
635 |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
636 def onQuit(self): |
195 | 637 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
|
638 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
|
639 self.host.bridge.call('mucLeave', None, self.target.bare) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
640 |
19 | 641 def setUserNick(self, nick): |
642 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
643 self.nick = nick | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
644 |
33 | 645 def setPresents(self, nicks): |
646 """Set the users presents in this room | |
647 @param occupants: list of nicks (string)""" | |
35 | 648 self.occupants_list.clear() |
33 | 649 for nick in nicks: |
650 self.occupants_list.addOccupant(nick) | |
651 | |
35 | 652 def userJoined(self, nick, data): |
653 self.occupants_list.addOccupant(nick) | |
654 self.printInfo("=> %s has joined the room" % nick) | |
655 | |
656 def userLeft(self, nick, data): | |
657 self.occupants_list.removeOccupant(nick) | |
658 self.printInfo("<= %s has left the room" % nick) | |
659 | |
19 | 660 def historyPrint(self, size=20): |
661 """Print the initial history""" | |
662 def getHistoryCB(history): | |
123 | 663 for line in history: |
137 | 664 timestamp, from_jid, to_jid, message, mess_type = line |
123 | 665 self.printMessage(from_jid, message, timestamp) |
666 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
|
667 |
35 | 668 def printInfo(self, msg, type='normal'): |
669 """Print general info | |
670 @param msg: message to print | |
671 @type: one of: | |
672 normal: general info like "toto has joined the room" | |
673 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
674 """ | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
675 _wid = Label(msg) |
35 | 676 if type == 'normal': |
677 _wid.setStyleName('chatTextInfo') | |
678 elif type == 'me': | |
679 _wid.setStyleName('chatTextMe') | |
680 else: | |
681 _wid.setStyleName('chatTextInfo') | |
682 self.content.add(_wid) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
683 |
19 | 684 def printMessage(self, from_jid, msg, timestamp=None): |
685 """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
|
686 _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
|
687 nick = _jid.node if self.type == 'one2one' else _jid.resource |
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
|
688 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 | 689 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
|
690 self.printInfo('* %s %s' % (nick, msg[4:]), type='me') |
35 | 691 return |
19 | 692 self.content.add(ChatText(timestamp, nick, mymess, msg)) |
34 | 693 self.content_scroll.scrollToBottom() |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
694 |
36 | 695 def startGame(self, game_type, referee, players): |
696 """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
|
697 if game_type == "Tarot": |
167
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
698 if hasattr(self, "tarot_panel"): |
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
699 return |
36 | 700 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
|
701 self.vpanel.insert(self.tarot_panel, 0) |
36 | 702 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
|
703 elif game_type == "RadioCol": |
167
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
704 #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
|
705 # 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
|
706 if hasattr(self, "radiocol_panel"): |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
707 return |
127 | 708 self.radiocol_panel = RadioColPanel(self, referee, self.nick) |
709 self.vpanel.insert(self.radiocol_panel, 0) | |
710 self.vpanel.setCellHeight(self.radiocol_panel, self.radiocol_panel.getHeight()) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
711 |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
712 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
713 """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
|
714 #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
|
715 if game_type == "Tarot": |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
716 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
|
717 elif game_type == "RadioCol": |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
718 return self.radiocol_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
719 |
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
|
720 |
195 | 721 class WebPanel(base_widget.LiberviaWidget): |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
722 """ (mini)browser like widget """ |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
723 |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
724 def __init__(self, host, url=None): |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
725 """ |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
726 @param host: SatWebFrontend instance |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
727 """ |
195 | 728 base_widget.LiberviaWidget.__init__(self, host) |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
729 self._vpanel = VerticalPanel() |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
730 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
|
731 self._url = dialog.ExtTextBox(enter_cb=self.onUrlClick) |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
732 self._url.setText(url or "") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
733 self._url.setWidth('100%') |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
734 hpanel = HorizontalPanel() |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
735 hpanel.add(self._url) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
736 btn = Button("Go", self.onUrlClick) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
737 hpanel.setCellWidth(self._url, "100%") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
738 #self.setCellWidth(btn, "10%") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
739 hpanel.add(self._url) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
740 hpanel.add(btn) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
741 self._vpanel.add(hpanel) |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
742 self._vpanel.setCellHeight(hpanel, '20px') |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
743 self._frame = Frame(url or "") |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
744 self._frame.setSize('100%', '100%') |
188
39936b83da9d
Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents:
187
diff
changeset
|
745 DOM.setStyleAttribute(self._frame.getElement(), "position", "relative") |
181
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
746 self._vpanel.add(self._frame) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
747 self.setWidget(self._vpanel) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
748 |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
749 def onUrlClick(self, sender): |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
750 self._frame.setUrl(self._url.getText()) |
c0b78a3af06d
browser side: web widget first draft
Goffi <goffi@goffi.org>
parents:
179
diff
changeset
|
751 |
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
|
752 |
33 | 753 class MainPanel(AbsolutePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
754 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
755 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
|
756 self.host = host |
33 | 757 AbsolutePanel.__init__(self) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
758 |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
759 #menu |
23 | 760 menu = Menu(host) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
761 |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
762 #unibox |
33 | 763 unibox_panel = UniBoxPanel(host) |
764 self.host.setUniBox(unibox_panel.unibox) | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
765 |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
766 #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
|
767 status = host.status_panel |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
768 |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
769 #contacts |
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
|
770 _contacts = HorizontalPanel() |
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
|
771 _contacts.addStyleName('globalLeftArea') |
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
|
772 contacts_switch = Button(u'«', self._contactsSwitch) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
773 contacts_switch.addStyleName('contactsSwitch') |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
774 _contacts.add(contacts_switch) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
775 _contacts.add(self.host.contact_panel) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
776 |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
777 #tabs |
195 | 778 self.tab_panel = base_widget.MainTabPanel(host) |
779 self.discuss_panel = base_widget.WidgetsPanel(self.host, locked=True) | |
23 | 780 self.tab_panel.add(self.discuss_panel, "Discussions") |
781 self.tab_panel.selectTab(0) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
782 |
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
|
783 header = AbsolutePanel() |
109
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
784 header.add(menu) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
785 header.add(unibox_panel) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
786 header.add(status) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
787 header.setStyleName('header') |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
788 self.add(header) |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
789 |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
790 _hpanel = HorizontalPanel() |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
791 _hpanel.add(_contacts) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
792 _hpanel.add(self.tab_panel) |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
793 self.add(_hpanel) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
794 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
795 self.setWidth("100%") |
33 | 796 Window.addWindowResizeListener(self) |
797 | |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
798 def _contactsSwitch(self, btn): |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
799 """ (Un)hide contacts panel """ |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
800 cpanel = self.host.contact_panel |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
801 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
|
802 btn.setText(u"«" if cpanel.getVisible() else u"»") |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
803 self.host.resize() |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
804 |
33 | 805 def onWindowResized(self, width, height): |
806 _elts = doc().getElementsByClassName('gwt-TabBar') | |
807 if not _elts.length: | |
808 tab_bar_h = 0 | |
809 else: | |
810 tab_bar_h = _elts.item(0).offsetHeight | |
811 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
|
812 self.setHeight("%s%s" % (ideal_height, "px")) |