Mercurial > libervia-web
annotate libervia.py @ 11:331c093e4eb3
magicBox is now able to send global microblog
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Mar 2011 17:53:12 +0100 |
parents | c80b75bf2e91 |
children | 0110d4e1d816 |
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 |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
28 from pyjamas.ui.Grid import Grid |
0 | 29 from pyjamas.ui.Label import Label |
30 from pyjamas.ui import HasAlignment | |
31 from pyjamas.ui.MenuBar import MenuBar | |
32 from pyjamas.ui.MenuItem import MenuItem | |
6 | 33 from pyjamas.ui.AutoComplete import AutoCompleteTextBox |
34 from pyjamas.ui.DropWidget import DropWidget | |
0 | 35 from pyjamas import Window |
36 from pyjamas.JSONService import JSONProxy | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
37 from pyjamas.ui.KeyboardListener import KEY_ENTER |
0 | 38 from register import RegisterPanel, RegisterBox |
1 | 39 from pyjamas import DOM |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
40 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
|
41 from datetime import datetime |
0 | 42 |
43 | |
44 class LiberviaJsonProxy(JSONProxy): | |
45 def __init__(self, *args, **kwargs): | |
46 JSONProxy.__init__(self, *args, **kwargs) | |
47 self.handler=self | |
48 self.cb={} | |
49 | |
50 def call(self, method, cb, *args): | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
51 if cb: |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
52 self.cb[method] = cb |
0 | 53 self.callMethod(method,args) |
54 | |
55 def onRemoteResponse(self, response, request_info): | |
56 if self.cb.has_key(request_info.method): | |
57 self.cb[request_info.method](response) | |
58 del self.cb[request_info.method] | |
59 | |
60 def onRemoteError(self, code, errobj, request_info): | |
61 if code != 0: | |
62 Window.alert("Internal server error") | |
63 else: | |
64 if isinstance(errobj['message'],dict): | |
65 Window.alert("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString'])) | |
66 else: | |
67 Window.alert("Error: %s" % errobj['message']) | |
68 | |
69 class RegisterCall(LiberviaJsonProxy): | |
70 def __init__(self): | |
71 LiberviaJsonProxy.__init__(self, "/register_api", | |
72 ["isRegistered","isConnected","connect"]) | |
73 self.handler=self | |
74 self.cb={} | |
75 | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
76 class BridgeCall(LiberviaJsonProxy): |
0 | 77 def __init__(self): |
78 LiberviaJsonProxy.__init__(self, "/json_api", | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
79 ["getContacts", "sendMblog"]) |
0 | 80 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
81 class BridgeSignals(LiberviaJsonProxy): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
82 def __init__(self): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
83 LiberviaJsonProxy.__init__(self, "/json_signal_api", |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
84 ["getSignals"]) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
85 |
0 | 86 class MenuCmd: |
87 | |
88 def __init__(self, object, handler): | |
89 self._object = object | |
90 self._handler = handler | |
91 | |
92 def execute(self): | |
93 handler = getattr(self._object, self._handler) | |
94 handler() | |
95 | |
96 class Menu(SimplePanel): | |
97 | |
98 def __init__(self): | |
99 SimplePanel.__init__(self) | |
100 | |
101 menu_general = MenuBar(vertical=True) | |
102 menu_general.addItem("Properties", MenuCmd(self, "onProperties")) | |
103 | |
104 menu_games = MenuBar(vertical=True) | |
105 menu_games.addItem("Tarot", MenuCmd(self, "onTarotGame")) | |
106 menu_games.addItem("Xiangqi", MenuCmd(self, "onXiangqiGame")) | |
107 | |
108 menubar = MenuBar(vertical=False) | |
109 menubar.addItem(MenuItem("General", menu_general)) | |
110 menubar.addItem(MenuItem("Games", True, menu_games)) | |
111 self.add(menubar) | |
112 | |
113 def onProperties(self): | |
114 Window.alert("Properties selected") | |
115 | |
116 def onTarotGame(self): | |
117 Window.alert("Tarot selected") | |
118 | |
119 def onXiangqiGame(self): | |
120 Window.alert("Xiangqi selected") | |
121 | |
122 class MagicBox(AutoCompleteTextBox): | |
123 | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
124 def __init__(self, host): |
0 | 125 AutoCompleteTextBox.__init__(self) |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
126 self.host = host |
1 | 127 |
128 def addKey(self, key): | |
129 self.getCompletionItems().completions.append(key) | |
130 | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
131 def onKeyPress(self, sender, keycode, modifiers): |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
132 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
|
133 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
|
134 self.setText('') |
1 | 135 |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
136 def complete(self): |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
137 #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
|
138 #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
|
139 return AutoCompleteTextBox.complete(self) |
0 | 140 |
6 | 141 class EmptyPanel(DropWidget, SimplePanel): |
142 """Empty dropable panel""" | |
143 | |
9 | 144 def __init__(self, host, data): |
6 | 145 SimplePanel.__init__(self) |
9 | 146 self.host = host |
147 self.data = data | |
6 | 148 _panel = HTMLPanel(" ") |
149 self.add(_panel) | |
150 self.setHeight('100%') | |
151 DropWidget.__init__(self) | |
152 | |
153 def onDragEnter(self, event): | |
154 self.addStyleName('dragover') | |
155 DOM.eventPreventDefault(event) | |
156 | |
157 def onDragLeave(self, event): | |
158 self.removeStyleName('dragover') | |
159 | |
160 def onDragOver(self, event): | |
161 DOM.eventPreventDefault(event) | |
162 | |
163 def onDrop(self, event): | |
9 | 164 print "Empty Panel: onDrop" |
6 | 165 dt = event.dataTransfer |
166 #'text', 'text/plain', and 'Text' are equivalent. | |
167 try: | |
168 item = dt.getData("text/plain") | |
169 print "message: %s" % item | |
170 except: | |
171 print "no message found" | |
9 | 172 item=' ' |
6 | 173 DOM.eventPreventDefault(event) |
9 | 174 self.host.mpanels.insert(0,MicroblogPanel(item)) |
175 self.host.middle_panel.changePanel(self.data,self.host.mpanels[0]) | |
6 | 176 |
177 | |
178 | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
179 class MicroblogEntry(SimplePanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
180 |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
181 def __init__(self, body, author, timestamp): |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
182 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
|
183 |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
184 _datetime = datetime.fromtimestamp(timestamp) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
185 |
6 | 186 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
|
187 {"author": author, |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
188 "timestamp": _datetime, |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
189 "body": body} |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
190 ) |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
191 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
|
192 self.add(panel) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
193 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
194 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
195 class MicroblogPanel(VerticalPanel): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
196 |
9 | 197 def __init__(self,title=' '): |
198 title=title.replace('<','<').replace('>','>') | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
199 VerticalPanel.__init__(self) |
9 | 200 _class = ['mb_panel_header'] |
201 if title == ' ': | |
202 _class.append('empty_header') | |
203 self.add(HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),title))) | |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
204 self.setStyleName('microblogPanel') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
205 |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
206 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
|
207 """Add an entry to the panel |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
208 @param text: main text of the entry |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
209 @param author: who wrote the entry |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
210 @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
|
211 _entry = MicroblogEntry(text, author, timestamp) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
212 self.add(_entry) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
213 |
0 | 214 class MiddlePannel(HorizontalPanel): |
215 | |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
216 def __init__(self, host): |
1 | 217 self.host=host |
0 | 218 HorizontalPanel.__init__(self) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
219 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
|
220 self._right = Grid(1,3) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
221 self._right.setWidth('100%') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
222 self._right.setHeight('100%') |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
223 self.add(self._left) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
224 self.setCellWidth(self._left, "15%") |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
225 self.add(self._right) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
226 self.setCellWidth(self._right, "85%") |
6 | 227 self.setHeight('100%') |
0 | 228 |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 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
|
233 |
0 | 234 class MainPanel(VerticalPanel): |
235 | |
1 | 236 def __init__(self, host): |
237 self.host=host | |
0 | 238 VerticalPanel.__init__(self) |
239 | |
240 self.setHorizontalAlignment(HasAlignment.ALIGN_LEFT) | |
241 self.setVerticalAlignment(HasAlignment.ALIGN_TOP) | |
242 | |
243 menu = Menu() | |
1 | 244 magic_box = host.magicBox |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
245 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
|
246 self.middle_panel.setWidth('100%') |
0 | 247 |
248 self.add(menu) | |
249 self.add(magic_box) | |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
250 self.add(self.middle_panel) |
0 | 251 |
252 self.setCellHeight(menu, "5%") | |
253 self.setCellHeight(magic_box, "5%") | |
254 self.setCellVerticalAlignment(magic_box, HasAlignment.ALIGN_CENTER) | |
255 self.setCellHorizontalAlignment(magic_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
|
256 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
|
257 self.setCellWidth(self.middle_panel, "100%") |
0 | 258 |
259 self.setWidth("100%") | |
260 self.setHeight("100%") | |
261 | |
262 class SatWebFrontend: | |
263 def onModuleLoad(self): | |
11
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
264 self.bridge = BridgeCall() |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
265 self.bridge_signals = BridgeSignals() |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
266 self.magicBox = MagicBox(self) |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
267 self.magicBox.addKey("@@: ") |
1 | 268 self.contactPanel = ContactPanel(self) |
269 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
|
270 self.middle_panel = self.panel.middle_panel |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
271 self.mpanels = [MicroblogPanel()] |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
272 self.middle_panel.changePanel(1,self.mpanels[0]) |
9 | 273 self.middle_panel.changePanel(0,EmptyPanel(self, 0)) |
274 self.middle_panel.changePanel(2,EmptyPanel(self, 2)) | |
0 | 275 self._dialog = None |
276 RootPanel().add(self.panel) | |
277 self._register = RegisterCall() | |
1 | 278 self._register.call('isRegistered',self._isRegisteredCB) |
0 | 279 |
1 | 280 def _isRegisteredCB(self, registered): |
0 | 281 if not registered: |
282 self._dialog = RegisterBox(self.logged,centered=True) | |
283 self._dialog.show() | |
284 else: | |
1 | 285 self._register.call('isConnected', self._isConnectedCB) |
0 | 286 |
1 | 287 def _isConnectedCB(self, connected): |
0 | 288 if not connected: |
289 self._register.call('connect',self.logged) | |
290 else: | |
291 self.logged() | |
292 | |
293 def logged(self): | |
294 if self._dialog: | |
295 self._dialog.hide() | |
296 del self._dialog # don't work if self._dialog is None | |
1 | 297 |
298 #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
|
299 self.bridge.call('getContacts', self._getContactsCB) |
331c093e4eb3
magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
300 self.bridge_signals.call('getSignals', self._getSignalsCB) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
301 |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
302 |
1 | 303 def _getContactsCB(self, contacts_data): |
304 for contact in contacts_data: | |
305 jid, attributes, groups = contact | |
306 self.contactPanel.addContact(jid, attributes, groups) | |
0 | 307 |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
308 def _getSignalsCB(self, signal_data): |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
309 bridge_signals = BridgeSignals() |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
310 bridge_signals.call('getSignals', self._getSignalsCB) |
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
311 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
|
312 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
|
313 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
|
314 self._personalEventCb(*args) |
2
669c531a857e
signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
315 |
4
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
316 ## Signals callbacks ## |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
317 |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
318 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
|
319 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
|
320 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
|
321 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
|
322 return |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
323 for panel in self.mpanels: |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
324 if isinstance(panel,MicroblogPanel): |
7325e787c22b
personalEvent management signal first draft, microblogs are now put in a central grid
Goffi <goffi@goffi.org>
parents:
2
diff
changeset
|
325 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
|
326 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
|
327 print "timestamp: %s" % data.get('timestamp') |
9 | 328 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
|
329 panel.addEntry(content, author, timestamp) |
0 | 330 |
331 if __name__ == '__main__': | |
1 | 332 pyjd.setup("http://localhost:8080/libervia.html") |
0 | 333 app = SatWebFrontend() |
334 app.onModuleLoad() | |
335 pyjd.run() | |
336 |