Mercurial > libervia-web
annotate libervia.py @ 16:099c05a0dcab
browser side: microblog panel improvments
- panels can now be changed by DnD
- contacts panel's title can be used by DnD for the global microblog panel
- microblogs now appear in reverse order (from bottom to top)
- MicroblogPanel now use a ScrollPanel and 100% space
- user's message now appear in correct group when using groupblog
- MagicBox renamed to UniBox
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 15 Apr 2011 02:01:34 +0200 |
parents | 9bf8ed012adc |
children | c725b702e927 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Libervia: a Salut à Toi frontend | |
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU Affero General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU Affero General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Affero General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 import pyjd # this is dummy in pyjs | |
23 from pyjamas.ui.SimplePanel import SimplePanel | |
24 from pyjamas.ui.RootPanel import RootPanel | |
25 from pyjamas.ui.VerticalPanel import VerticalPanel | |
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel | |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
27 from pyjamas.ui.HTMLPanel import HTMLPanel |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
28 from pyjamas.ui.ScrollPanel import ScrollPanel |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
29 from pyjamas.ui.Grid import Grid |
0 | 30 from pyjamas.ui.Label import Label |
31 from pyjamas.ui import HasAlignment | |
32 from pyjamas.ui.MenuBar import MenuBar | |
33 from pyjamas.ui.MenuItem import MenuItem | |
6 | 34 from pyjamas.ui.AutoComplete import AutoCompleteTextBox |
35 from pyjamas.ui.DropWidget import DropWidget | |
0 | 36 from pyjamas import Window |
37 from pyjamas.JSONService import JSONProxy | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
38 from pyjamas.ui.KeyboardListener import KEY_ENTER |
0 | 39 from register import RegisterPanel, RegisterBox |
1 | 40 from pyjamas import DOM |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
41 from contact import ContactPanel |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
42 from datetime import datetime |
0 | 43 |
44 | |
45 class LiberviaJsonProxy(JSONProxy): | |
46 def __init__(self, *args, **kwargs): | |
47 JSONProxy.__init__(self, *args, **kwargs) | |
48 self.handler=self | |
49 self.cb={} | |
50 | |
51 def call(self, method, cb, *args): | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
52 if cb: |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
53 self.cb[method] = cb |
0 | 54 self.callMethod(method,args) |
55 | |
56 def onRemoteResponse(self, response, request_info): | |
57 if self.cb.has_key(request_info.method): | |
58 self.cb[request_info.method](response) | |
59 del self.cb[request_info.method] | |
60 | |
61 def onRemoteError(self, code, errobj, request_info): | |
62 if code != 0: | |
63 Window.alert("Internal server error") | |
64 else: | |
65 if isinstance(errobj['message'],dict): | |
66 Window.alert("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString'])) | |
67 else: | |
68 Window.alert("Error: %s" % errobj['message']) | |
69 | |
70 class RegisterCall(LiberviaJsonProxy): | |
71 def __init__(self): | |
72 LiberviaJsonProxy.__init__(self, "/register_api", | |
73 ["isRegistered","isConnected","connect"]) | |
74 self.handler=self | |
75 self.cb={} | |
76 | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
77 class BridgeCall(LiberviaJsonProxy): |
0 | 78 def __init__(self): |
79 LiberviaJsonProxy.__init__(self, "/json_api", | |
14
9bf8ed012adc
- Group microblog management, first draft
Goffi <goffi@goffi.org>
parents:
13
diff
changeset
|
80 ["getContacts", "sendMblog", "getMblogNodes"]) |
0 | 81 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
82 class BridgeSignals(LiberviaJsonProxy): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
83 def __init__(self): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
84 LiberviaJsonProxy.__init__(self, "/json_signal_api", |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
85 ["getSignals"]) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
86 |
0 | 87 class MenuCmd: |
88 | |
89 def __init__(self, object, handler): | |
90 self._object = object | |
91 self._handler = handler | |
92 | |
93 def execute(self): | |
94 handler = getattr(self._object, self._handler) | |
95 handler() | |
96 | |
97 class Menu(SimplePanel): | |
98 | |
99 def __init__(self): | |
100 SimplePanel.__init__(self) | |
101 | |
102 menu_general = MenuBar(vertical=True) | |
103 menu_general.addItem("Properties", MenuCmd(self, "onProperties")) | |
104 | |
105 menu_games = MenuBar(vertical=True) | |
106 menu_games.addItem("Tarot", MenuCmd(self, "onTarotGame")) | |
107 menu_games.addItem("Xiangqi", MenuCmd(self, "onXiangqiGame")) | |
108 | |
109 menubar = MenuBar(vertical=False) | |
110 menubar.addItem(MenuItem("General", menu_general)) | |
111 menubar.addItem(MenuItem("Games", True, menu_games)) | |
112 self.add(menubar) | |
113 | |
114 def onProperties(self): | |
115 Window.alert("Properties selected") | |
116 | |
117 def onTarotGame(self): | |
118 Window.alert("Tarot selected") | |
119 | |
120 def onXiangqiGame(self): | |
121 Window.alert("Xiangqi selected") | |
122 | |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
123 class UniBox(AutoCompleteTextBox): |
0 | 124 |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
125 def __init__(self, host): |
0 | 126 AutoCompleteTextBox.__init__(self) |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
127 self.host = host |
1 | 128 |
129 def addKey(self, key): | |
130 self.getCompletionItems().completions.append(key) | |
131 | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
132 def onKeyPress(self, sender, keycode, modifiers): |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
133 if keycode == KEY_ENTER and not self.visible: |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
134 self.host.bridge.call('sendMblog', None, self.getText()) |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
135 self.setText('') |
1 | 136 |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
137 def complete(self): |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
138 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
139 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
140 return AutoCompleteTextBox.complete(self) |
0 | 141 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
142 class DropCell(DropWidget): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
143 """Cell in the middle grid which replace itself with the dropped widget on DnD""" |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
144 |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
145 def __init__(self): |
6 | 146 DropWidget.__init__(self) |
147 | |
148 def onDragEnter(self, event): | |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
149 print "drag enter" |
6 | 150 self.addStyleName('dragover') |
151 DOM.eventPreventDefault(event) | |
152 | |
153 def onDragLeave(self, event): | |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
154 print "drag leave" |
6 | 155 self.removeStyleName('dragover') |
156 | |
157 def onDragOver(self, event): | |
158 DOM.eventPreventDefault(event) | |
159 | |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
160 def _getCellAndRow(self, grid, event): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
161 """Return cell and row index where the event is occuring""" |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
162 cell = grid.getEventTargetCell(event) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
163 row = DOM.getParent(cell) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
164 return (row.rowIndex, cell.cellIndex) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
165 |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
166 |
6 | 167 def onDrop(self, event): |
9 | 168 print "Empty Panel: onDrop" |
6 | 169 dt = event.dataTransfer |
170 #'text', 'text/plain', and 'Text' are equivalent. | |
171 try: | |
172 item = dt.getData("text/plain") | |
13 | 173 item_type = dt.getData("type") |
6 | 174 print "message: %s" % item |
13 | 175 print "type: %s" % item_type |
6 | 176 except: |
177 print "no message found" | |
9 | 178 item=' ' |
13 | 179 item_type = None |
6 | 180 DOM.eventPreventDefault(event) |
13 | 181 if item_type=="GROUP": |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
182 _mblog = MicroblogPanel(self.host, item) |
13 | 183 _mblog.setAcceptedGroup(item) |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
184 elif item_type=="CONTACT": |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
185 _mblog = MicroblogPanel(self.host, accept_all=True) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
186 self.host.mpanels.remove(self) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
187 self.host.mpanels.append(_mblog) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
188 print "DEBUG" |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
189 grid = self.getParent() |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
190 row_idx, cell_idx = self._getCellAndRow(grid, event) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
191 self.removeFromParent() |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
192 grid.setWidget(row_idx, cell_idx, _mblog) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
193 print "index:", row_idx, cell_idx |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
194 #FIXME: delete object ? Check the right way with pyjamas |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
195 #self.host.middle_panel.changePanel(self.data,self.host.mpanels[0]) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
196 |
6 | 197 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
198 class EmptyPanel(DropCell, SimplePanel): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
199 """Empty dropable panel""" |
6 | 200 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
201 def __init__(self, host): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
202 SimplePanel.__init__(self) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
203 self.host = host |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
204 _panel = HTMLPanel(" ") |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
205 self.add(_panel) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
206 self.setHeight('100%') |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
207 DropCell.__init__(self) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
208 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
209 class MicroblogEntry(SimplePanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
210 |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
211 def __init__(self, body, author, timestamp): |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
212 SimplePanel.__init__(self) |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
213 |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
214 _datetime = datetime.fromtimestamp(timestamp) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
215 |
6 | 216 panel = HTMLPanel("<div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div><div class='mb_entry_body'>%(body)s</div>" % |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
217 {"author": author, |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
218 "timestamp": _datetime, |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
219 "body": body} |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
220 ) |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
221 panel.setStyleName('microblogEntry') |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
222 self.add(panel) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
223 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
224 |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
225 class MicroblogPanel(DropCell, ScrollPanel): |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
226 |
13 | 227 def __init__(self,host, title=' ', accept_all=False): |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
228 """Panel used to show microblog |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
229 @param title: title of the panel |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
230 @param accept_all: if true, show every message, without filtering jids""" |
13 | 231 self.host = host |
232 self.accept_all = accept_all | |
9 | 233 title=title.replace('<','<').replace('>','>') |
13 | 234 self.accepted_groups = [] |
9 | 235 _class = ['mb_panel_header'] |
236 if title == ' ': | |
237 _class.append('empty_header') | |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
238 ScrollPanel.__init__(self) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
239 self.vpanel = VerticalPanel() |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
240 self.vpanel.add(HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),title))) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
241 self.vpanel.setWidth('100%') |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
242 self.setHeight('100%') |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
243 self.setStyleName('microblogPanel') |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
244 self.add(self.vpanel) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
245 DropCell.__init__(self) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
246 |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
247 def addEntry(self, text, author=None, timestamp=None): |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
248 """Add an entry to the panel |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
249 @param text: main text of the entry |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
250 @param author: who wrote the entry |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
251 @param date: when the entry was written""" |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
252 _entry = MicroblogEntry(text, author, timestamp) |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
253 self.vpanel.insert(_entry,1) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
254 |
13 | 255 def setAcceptedGroup(self, group): |
256 """Set the group which can be displayed in this panel | |
257 @param group: string of the group, or list of string | |
258 """ | |
259 if isinstance(group, list): | |
260 self.accepted_groups.extend(group) | |
261 else: | |
262 self.accepted_groups.append(group) | |
263 | |
264 def isJidAccepted(self, jid): | |
265 """Tell if a jid is actepted and show in this panel | |
266 @param jid: jid | |
267 @return: True if the jid is accepted""" | |
268 if self.accept_all: | |
269 return True | |
270 for group in self.accepted_groups: | |
271 if self.host.contactPanel.isContactInGroup(group, jid): | |
272 return True | |
273 return False | |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
274 |
13 | 275 |
276 | |
0 | 277 class MiddlePannel(HorizontalPanel): |
278 | |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
279 def __init__(self, host): |
1 | 280 self.host=host |
0 | 281 HorizontalPanel.__init__(self) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
282 self._left = self.host.contactPanel |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
283 self._right = Grid(1,3) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
284 self._right.setWidth('100%') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
285 self._right.setHeight('100%') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
286 self.add(self._left) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
287 self.setCellWidth(self._left, "15%") |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
288 self.add(self._right) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
289 self.setCellWidth(self._right, "85%") |
6 | 290 self.setHeight('100%') |
0 | 291 |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
292 def changePanel(self, idx, panel): |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
293 print "panel:",panel |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
294 print "idx:",idx |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
295 self._right.setWidget(0,idx,panel) |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
296 |
0 | 297 class MainPanel(VerticalPanel): |
298 | |
1 | 299 def __init__(self, host): |
300 self.host=host | |
0 | 301 VerticalPanel.__init__(self) |
302 | |
303 self.setHorizontalAlignment(HasAlignment.ALIGN_LEFT) | |
304 self.setVerticalAlignment(HasAlignment.ALIGN_TOP) | |
305 | |
306 menu = Menu() | |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
307 uni_box = host.uniBox |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
308 self.middle_panel = MiddlePannel(self.host) |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
309 self.middle_panel.setWidth('100%') |
0 | 310 |
311 self.add(menu) | |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
312 self.add(uni_box) |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
313 self.add(self.middle_panel) |
0 | 314 |
315 self.setCellHeight(menu, "5%") | |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
316 self.setCellHeight(uni_box, "5%") |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
317 self.setCellVerticalAlignment(uni_box, HasAlignment.ALIGN_CENTER) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
318 self.setCellHorizontalAlignment(uni_box, HasAlignment.ALIGN_CENTER) |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
319 self.setCellHeight(self.middle_panel, "90%") |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
320 self.setCellWidth(self.middle_panel, "100%") |
0 | 321 |
322 self.setWidth("100%") | |
323 self.setHeight("100%") | |
324 | |
325 class SatWebFrontend: | |
326 def onModuleLoad(self): | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
327 self.bridge = BridgeCall() |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
328 self.bridge_signals = BridgeSignals() |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
329 self.uniBox = UniBox(self) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
330 self.uniBox.addKey("@@: ") |
1 | 331 self.contactPanel = ContactPanel(self) |
332 self.panel = MainPanel(self) | |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
333 self.middle_panel = self.panel.middle_panel |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
334 self.mpanels = [EmptyPanel(self), MicroblogPanel(self, accept_all=True), EmptyPanel(self)] |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
335 self.middle_panel.changePanel(0,self.mpanels[0]) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
336 self.middle_panel.changePanel(1,self.mpanels[1]) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
337 self.middle_panel.changePanel(2,self.mpanels[2]) |
0 | 338 self._dialog = None |
339 RootPanel().add(self.panel) | |
340 self._register = RegisterCall() | |
1 | 341 self._register.call('isRegistered',self._isRegisteredCB) |
0 | 342 |
1 | 343 def _isRegisteredCB(self, registered): |
0 | 344 if not registered: |
345 self._dialog = RegisterBox(self.logged,centered=True) | |
346 self._dialog.show() | |
347 else: | |
1 | 348 self._register.call('isConnected', self._isConnectedCB) |
0 | 349 |
1 | 350 def _isConnectedCB(self, connected): |
0 | 351 if not connected: |
352 self._register.call('connect',self.logged) | |
353 else: | |
354 self.logged() | |
355 | |
356 def logged(self): | |
357 if self._dialog: | |
358 self._dialog.hide() | |
359 del self._dialog # don't work if self._dialog is None | |
1 | 360 |
361 #it's time to fill the page | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
362 self.bridge.call('getContacts', self._getContactsCB) |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
363 self.bridge_signals.call('getSignals', self._getSignalsCB) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
364 |
1 | 365 def _getContactsCB(self, contacts_data): |
366 for contact in contacts_data: | |
367 jid, attributes, groups = contact | |
368 self.contactPanel.addContact(jid, attributes, groups) | |
0 | 369 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
370 def _getSignalsCB(self, signal_data): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
371 bridge_signals = BridgeSignals() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
372 bridge_signals.call('getSignals', self._getSignalsCB) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
373 print('Got signal ==> name: %s, params: %s' % (signal_data[0],signal_data[1])) |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
374 name,args = signal_data |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
375 if name == 'personalEvent': |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
376 self._personalEventCb(*args) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
377 |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
378 ## Signals callbacks ## |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
379 |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
380 def _personalEventCb(self, sender, event_type, data, profile): |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
381 if event_type == "MICROBLOG": |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
382 if not data.has_key('content'): |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
383 print ("WARNING: No content found in microblog data") |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
384 return |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
385 print dir('') |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
386 if data.has_key('groups'): |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
387 _groups = set(data['groups'].split() if data['groups'] else []) |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
388 else: |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
389 _groups=None |
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
390 print "_groups=",_groups |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
391 for panel in self.mpanels: |
16
099c05a0dcab
browser side: microblog panel improvments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
392 if isinstance(panel,MicroblogPanel) and (panel.isJidAccepted(sender) or _groups == None or _groups.intersection(panel.accepted_groups)): |
13 | 393 print "sender:",sender |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
394 content = data['content'] |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
395 author = data.get('author') |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
396 print "timestamp: %s" % data.get('timestamp') |
9 | 397 timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
398 panel.addEntry(content, author, timestamp) |
0 | 399 |
400 if __name__ == '__main__': | |
1 | 401 pyjd.setup("http://localhost:8080/libervia.html") |
0 | 402 app = SatWebFrontend() |
403 app.onModuleLoad() | |
404 pyjd.run() | |
405 |