Mercurial > libervia-web
comparison libervia.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 | ee744ffed7fc |
children | 8bbac49765d6 |
comparison
equal
deleted
inserted
replaced
209:4564c7bc06a7 | 210:3092f6b1710c |
---|---|
67 # #No additional argument, we call directly the callback | 67 # #No additional argument, we call directly the callback |
68 _cb(response) | 68 _cb(response) |
69 del self.cb[request_info.id] | 69 del self.cb[request_info.id] |
70 if request_info.id in self.eb: | 70 if request_info.id in self.eb: |
71 del self.eb[request_info.id] | 71 del self.eb[request_info.id] |
72 | 72 |
73 def onRemoteError(self, code, errobj, request_info): | 73 def onRemoteError(self, code, errobj, request_info): |
74 """def dump(obj): | 74 """def dump(obj): |
75 print "\n\nDUMPING %s\n\n" % obj | 75 print "\n\nDUMPING %s\n\n" % obj |
76 for i in dir(obj): | 76 for i in dir(obj): |
77 print "%s: %s" % (i, getattr(obj,i))""" | 77 print "%s: %s" % (i, getattr(obj,i))""" |
112 def __init__(self, host): | 112 def __init__(self, host): |
113 self.host = host | 113 self.host = host |
114 self.retry_delay = self.RETRY_BASE_DELAY | 114 self.retry_delay = self.RETRY_BASE_DELAY |
115 LiberviaJsonProxy.__init__(self, "/json_signal_api", | 115 LiberviaJsonProxy.__init__(self, "/json_signal_api", |
116 ["getSignals"]) | 116 ["getSignals"]) |
117 | 117 |
118 def onRemoteResponse(self, response, request_info): | 118 def onRemoteResponse(self, response, request_info): |
119 self.retry_delay = self.RETRY_BASE_DELAY | 119 self.retry_delay = self.RETRY_BASE_DELAY |
120 LiberviaJsonProxy.onRemoteResponse(self, response, request_info) | 120 LiberviaJsonProxy.onRemoteResponse(self, response, request_info) |
121 | 121 |
122 | 122 |
123 def onRemoteError(self, code, errobj, request_info): | 123 def onRemoteError(self, code, errobj, request_info): |
124 if errobj['message'] == 'Empty Response': | 124 if errobj['message'] == 'Empty Response': |
125 Window.getLocation().reload() # XXX: reset page in case of session ended. | 125 Window.getLocation().reload() # XXX: reset page in case of session ended. |
126 # FIXME: Should be done more properly without hard reload | 126 # FIXME: Should be done more properly without hard reload |
127 LiberviaJsonProxy.onRemoteError(self, code, errobj, request_info) | 127 LiberviaJsonProxy.onRemoteError(self, code, errobj, request_info) |
185 | 185 |
186 selected = widgets_panel.selected | 186 selected = widgets_panel.selected |
187 | 187 |
188 if selected == widget: | 188 if selected == widget: |
189 return | 189 return |
190 | 190 |
191 if selected: | 191 if selected: |
192 selected.removeStyleName('selected_widget') | 192 selected.removeStyleName('selected_widget') |
193 | 193 |
194 widgets_panel.selected = widget | 194 widgets_panel.selected = widget |
195 | 195 |
196 if widget: | 196 if widget: |
197 widgets_panel.selected.addStyleName('selected_widget') | 197 widgets_panel.selected.addStyleName('selected_widget') |
198 | 198 |
199 for callback in self._selected_listeners: | 199 for callback in self._selected_listeners: |
200 callback(widget) | 200 callback(widget) |
225 else: | 225 else: |
226 self.bridge.call("getCard", None, jid_str) | 226 self.bridge.call("getCard", None, jid_str) |
227 def avatarError(error_data): | 227 def avatarError(error_data): |
228 # The jid is maybe not in our roster, we ask for the VCard | 228 # The jid is maybe not in our roster, we ask for the VCard |
229 self.bridge.call("getCard", None, jid_str) | 229 self.bridge.call("getCard", None, jid_str) |
230 | 230 |
231 if jid_str not in self.avatars_cache: | 231 if jid_str not in self.avatars_cache: |
232 self.bridge.call('getEntityData', (dataReceived, avatarError), jid_str, ['avatar']) | 232 self.bridge.call('getEntityData', (dataReceived, avatarError), jid_str, ['avatar']) |
233 self.avatars_cache[jid_str] = "/media/misc/empty_avatar" | 233 self.avatars_cache[jid_str] = "/media/misc/empty_avatar" |
234 return self.avatars_cache[jid_str] | 234 return self.avatars_cache[jid_str] |
235 | 235 |
240 def unregisterWidget(self, wid): | 240 def unregisterWidget(self, wid): |
241 try: | 241 try: |
242 self.libervia_widgets.remove(wid) | 242 self.libervia_widgets.remove(wid) |
243 except KeyError: | 243 except KeyError: |
244 print ('WARNING: trying to remove a non registered Widget:', wid) | 244 print ('WARNING: trying to remove a non registered Widget:', wid) |
245 | 245 |
246 def setUniBox(self, unibox): | 246 def setUniBox(self, unibox): |
247 """register the unibox widget""" | 247 """register the unibox widget""" |
248 self.uni_box = unibox | 248 self.uni_box = unibox |
249 self.uni_box.addKey("@@: ") | 249 self.uni_box.addKey("@@: ") |
250 | 250 |
279 | 279 |
280 def logged(self): | 280 def logged(self): |
281 if self._register_box: | 281 if self._register_box: |
282 self._register_box.hide() | 282 self._register_box.hide() |
283 del self._register_box # don't work if self._register_box is None | 283 del self._register_box # don't work if self._register_box is None |
284 | 284 |
285 #it's time to fill the page | 285 #it's time to fill the page |
286 self.bridge.call('getContacts', self._getContactsCB) | 286 self.bridge.call('getContacts', self._getContactsCB) |
287 self.bridge_signals.call('getSignals', self._getSignalsCB) | 287 self.bridge_signals.call('getSignals', self._getSignalsCB) |
288 #We want to know our own jid | 288 #We want to know our own jid |
289 self.bridge.call('getProfileJid', self._getProfileJidCB) | 289 self.bridge.call('getProfileJid', self._getProfileJidCB) |
290 | |
291 | 290 |
292 def _getContactsCB(self, contacts_data): | 291 def _getContactsCB(self, contacts_data): |
293 for contact in contacts_data: | 292 for contact in contacts_data: |
294 jid, attributes, groups = contact | 293 jid, attributes, groups = contact |
295 self._newContactCb(jid, attributes, groups) | 294 self._newContactCb(jid, attributes, groups) |
352 _groups = set(mblog['groups'].split() if mblog['groups'] else []) | 351 _groups = set(mblog['groups'].split() if mblog['groups'] else []) |
353 else: | 352 else: |
354 _groups=None | 353 _groups=None |
355 mblog_entry = MicroblogItem(mblog) | 354 mblog_entry = MicroblogItem(mblog) |
356 self.mblog_cache.append((_groups, mblog_entry)) | 355 self.mblog_cache.append((_groups, mblog_entry)) |
357 | 356 |
358 if len(self.mblog_cache) > MAX_MBLOG_CACHE: | 357 if len(self.mblog_cache) > MAX_MBLOG_CACHE: |
359 del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)] | 358 del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)] |
360 for lib_wid in self.libervia_widgets: | 359 for lib_wid in self.libervia_widgets: |
361 if isinstance(lib_wid, panels.MicroblogPanel): | 360 if isinstance(lib_wid, panels.MicroblogPanel): |
362 self.FillMicroblogPanel(lib_wid) | 361 self.FillMicroblogPanel(lib_wid) |
378 if isinstance(lib_wid, panels.MicroblogPanel): | 377 if isinstance(lib_wid, panels.MicroblogPanel): |
379 if lib_wid.accept_all(): | 378 if lib_wid.accept_all(): |
380 self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'ALL', [], 10) | 379 self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'ALL', [], 10) |
381 else: | 380 else: |
382 self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'GROUP', lib_wid.accepted_groups, 10) | 381 self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'GROUP', lib_wid.accepted_groups, 10) |
383 | 382 |
384 #we ask for our own microblogs: | 383 #we ask for our own microblogs: |
385 self.bridge.call('getMassiveLastMblogs', self._ownBlogsFills, 'JID', [self.whoami.bare], 10) | 384 self.bridge.call('getMassiveLastMblogs', self._ownBlogsFills, 'JID', [self.whoami.bare], 10) |
386 | 385 |
387 ## Signals callbacks ## | 386 ## Signals callbacks ## |
388 | 387 |
397 if 'groups' in data: | 396 if 'groups' in data: |
398 _groups = set(data['groups'].split() if data['groups'] else []) | 397 _groups = set(data['groups'].split() if data['groups'] else []) |
399 else: | 398 else: |
400 _groups=None | 399 _groups=None |
401 mblog_entry = MicroblogItem(data) | 400 mblog_entry = MicroblogItem(data) |
402 | 401 |
403 for lib_wid in self.libervia_widgets: | 402 for lib_wid in self.libervia_widgets: |
404 if isinstance(lib_wid, panels.MicroblogPanel): | 403 if isinstance(lib_wid, panels.MicroblogPanel): |
405 self.addBlogEntry(lib_wid, sender, _groups, mblog_entry) | 404 self.addBlogEntry(lib_wid, sender, _groups, mblog_entry) |
406 | 405 |
407 if sender == self.whoami.bare: | 406 if sender == self.whoami.bare: |
446 showed = True | 445 showed = True |
447 if not showed: | 446 if not showed: |
448 #The message has not been showed, we must indicate it | 447 #The message has not been showed, we must indicate it |
449 other = _to if _from.bare == self.whoami.bare else _from | 448 other = _to if _from.bare == self.whoami.bare else _from |
450 self.contact_panel.setContactMessageWaiting(other.bare, True) | 449 self.contact_panel.setContactMessageWaiting(other.bare, True) |
451 | 450 |
452 def _presenceUpdateCb(self, entity, show, priority, statuses): | 451 def _presenceUpdateCb(self, entity, show, priority, statuses): |
453 _entity = JID(entity) | 452 _entity = JID(entity) |
454 #XXX: QnD way to get our status | 453 #XXX: QnD way to get our status |
455 if self.whoami and self.whoami.bare == _entity.bare and statuses: | 454 if self.whoami and self.whoami.bare == _entity.bare and statuses: |
456 self.status_panel.changeStatus(statuses.values()[0]) | 455 self.status_panel.changeStatus(statuses.values()[0]) |
478 | 477 |
479 def _roomUserLeftCb(self, room_jid_s, user_nick, user_data): | 478 def _roomUserLeftCb(self, room_jid_s, user_nick, user_data): |
480 for lib_wid in self.libervia_widgets: | 479 for lib_wid in self.libervia_widgets: |
481 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: | 480 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: |
482 lib_wid.userLeft(user_nick, user_data) | 481 lib_wid.userLeft(user_nick, user_data) |
483 | 482 |
484 def _tarotGameStartedCb(self, room_jid_s, referee, players): | 483 def _tarotGameStartedCb(self, room_jid_s, referee, players): |
485 print ("Tarot Game Started \o/") | 484 print ("Tarot Game Started \o/") |
486 for lib_wid in self.libervia_widgets: | 485 for lib_wid in self.libervia_widgets: |
487 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: | 486 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: |
488 lib_wid.startGame("Tarot", referee, players) | 487 lib_wid.startGame("Tarot", referee, players) |
494 | 493 |
495 def _radioColStartedCb(self, room_jid_s, referee): | 494 def _radioColStartedCb(self, room_jid_s, referee): |
496 for lib_wid in self.libervia_widgets: | 495 for lib_wid in self.libervia_widgets: |
497 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: | 496 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: |
498 lib_wid.startGame("RadioCol", referee) | 497 lib_wid.startGame("RadioCol", referee) |
499 | 498 |
500 def _radioColGenericCb(self, event_name, room_jid_s, args): | 499 def _radioColGenericCb(self, event_name, room_jid_s, args): |
501 for lib_wid in self.libervia_widgets: | 500 for lib_wid in self.libervia_widgets: |
502 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: | 501 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: |
503 getattr(lib_wid.getGame("RadioCol"), event_name)(*args) | 502 getattr(lib_wid.getGame("RadioCol"), event_name)(*args) |
504 | 503 |
505 | 504 |
506 def _getPresenceStatusCb(self, presence_data): | 505 def _getPresenceStatusCb(self, presence_data): |
507 for entity in presence_data: | 506 for entity in presence_data: |
508 for resource in presence_data[entity]: | 507 for resource in presence_data[entity]: |
509 args = presence_data[entity][resource] | 508 args = presence_data[entity][resource] |
510 self._presenceUpdateCb("%s/%s" % (entity, resource), *args) | 509 self._presenceUpdateCb("%s/%s" % (entity, resource), *args) |
533 | 532 |
534 def ok_cb(ignore): | 533 def ok_cb(ignore): |
535 self.bridge.call('subscription', None, "subscribed", entity, '', _dialog.getSelectedGroups()) | 534 self.bridge.call('subscription', None, "subscribed", entity, '', _dialog.getSelectedGroups()) |
536 def cancel_cb(ignore): | 535 def cancel_cb(ignore): |
537 self.bridge.call('subscription', None, "unsubscribed", entity, '', '') | 536 self.bridge.call('subscription', None, "unsubscribed", entity, '', '') |
538 | 537 |
539 _dialog = dialog.GroupSelector([msg], self.contact_panel.getGroups(), [], ok_cb, cancel_cb) | 538 _dialog = dialog.GroupSelector([msg], self.contact_panel.getGroups(), [], ok_cb, cancel_cb) |
540 _dialog.setHTML('<b>Add contact request</b>') | 539 _dialog.setHTML('<b>Add contact request</b>') |
541 _dialog.show() | 540 _dialog.show() |
542 | 541 |
543 def _contactDeletedCb(self, entity): | 542 def _contactDeletedCb(self, entity): |
554 | 553 |
555 for lib_wid in self.libervia_widgets: | 554 for lib_wid in self.libervia_widgets: |
556 if isinstance(lib_wid, panels.MicroblogPanel): | 555 if isinstance(lib_wid, panels.MicroblogPanel): |
557 if lib_wid.isJidAccepted(entity_jid_s) or (self.whoami and entity_jid_s == self.whoami.bare): | 556 if lib_wid.isJidAccepted(entity_jid_s) or (self.whoami and entity_jid_s == self.whoami.bare): |
558 lib_wid.updateValue('avatar', entity_jid_s, avatar) | 557 lib_wid.updateValue('avatar', entity_jid_s, avatar) |
559 | |
560 | 558 |
561 | 559 |
562 if __name__ == '__main__': | 560 if __name__ == '__main__': |
563 pyjd.setup("http://localhost:8080/libervia.html") | 561 pyjd.setup("http://localhost:8080/libervia.html") |
564 app = SatWebFrontend() | 562 app = SatWebFrontend() |
565 app.onModuleLoad() | 563 app.onModuleLoad() |
566 pyjd.run() | 564 pyjd.run() |
567 |