comparison libervia.py @ 28:258dfaa1035f

browser side: - roomJoined signal added and open a new tab - name refactoring - connected contact are saved - launchTarotGame method used
author Goffi <goffi@goffi.org>
date Sat, 07 May 2011 23:58:57 +0200
parents 0ce2a57b34ca
children e70521e6d803
comparison
equal deleted inserted replaced
27:d89982865c57 28:258dfaa1035f
68 self.cb={} 68 self.cb={}
69 69
70 class BridgeCall(LiberviaJsonProxy): 70 class BridgeCall(LiberviaJsonProxy):
71 def __init__(self): 71 def __init__(self):
72 LiberviaJsonProxy.__init__(self, "/json_api", 72 LiberviaJsonProxy.__init__(self, "/json_api",
73 ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus"]) 73 ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus", "launchTarotGame"])
74 74
75 class BridgeSignals(LiberviaJsonProxy): 75 class BridgeSignals(LiberviaJsonProxy):
76 def __init__(self): 76 def __init__(self):
77 LiberviaJsonProxy.__init__(self, "/json_signal_api", 77 LiberviaJsonProxy.__init__(self, "/json_signal_api",
78 ["getSignals"]) 78 ["getSignals"])
79 79
80 80
81 class UniBox(AutoCompleteTextBox): 81 class UniBox(AutoCompleteTextBox):
82 """This text box is used as a main typing point, for message, microblog, etc"""
82 83
83 def __init__(self, host): 84 def __init__(self, host):
84 AutoCompleteTextBox.__init__(self) 85 AutoCompleteTextBox.__init__(self)
85 self._popup = None 86 self._popup = None
86 self._timer = Timer(notify=self._timeCb) 87 self._timer = Timer(notify=self._timeCb)
139 _end = txt.find(': ') 140 _end = txt.find(': ')
140 if _end == -1: 141 if _end == -1:
141 type = "STATUS" 142 type = "STATUS"
142 else: 143 else:
143 target = txt[1:_end] #only one target group is managed for the moment 144 target = txt[1:_end] #only one target group is managed for the moment
144 if not target in self.host.contactPanel.getGroups(): 145 if not target in self.host.contact_panel.getGroups():
145 target = None 146 target = None
146 elif self.host.selected == None: 147 elif self.host.selected == None:
147 type = "STATUS" 148 type = "STATUS"
148 elif isinstance(self.host.selected, ChatPanel): 149 elif isinstance(self.host.selected, ChatPanel):
149 type = "ONE2ONE" 150 type = "ONE2ONE"
187 def onModuleLoad(self): 188 def onModuleLoad(self):
188 self.whoami = None 189 self.whoami = None
189 self.bridge = BridgeCall() 190 self.bridge = BridgeCall()
190 self.bridge_signals = BridgeSignals() 191 self.bridge_signals = BridgeSignals()
191 self.selected = None 192 self.selected = None
192 self.uniBox = UniBox(self) 193 self.uni_box = UniBox(self)
193 self.uniBox.addKey("@@: ") 194 self.uni_box.addKey("@@: ")
194 self.statusPanel = StatusPanel(self) 195 self.status_panel = StatusPanel(self)
195 self.contactPanel = ContactPanel(self) 196 self.contact_panel = ContactPanel(self)
196 self.panel = MainPanel(self) 197 self.panel = MainPanel(self)
197 self.discuss_panel = self.panel.discuss_panel 198 self.discuss_panel = self.panel.discuss_panel
198 self.tab_panel = self.panel.tab_panel 199 self.tab_panel = self.panel.tab_panel
199 self.mpanels = [EmptyPanel(self), MicroblogPanel(self, accept_all=True), EmptyPanel(self)] 200 self.mpanels = [EmptyPanel(self), MicroblogPanel(self, accept_all=True), EmptyPanel(self)]
200 self.discuss_panel.changePanel(0,self.mpanels[0]) 201 self.discuss_panel.changePanel(0,self.mpanels[0])
238 self.bridge.call('getProfileJid', self._getProfileJidCB) 239 self.bridge.call('getProfileJid', self._getProfileJidCB)
239 240
240 def _getContactsCB(self, contacts_data): 241 def _getContactsCB(self, contacts_data):
241 for contact in contacts_data: 242 for contact in contacts_data:
242 jid, attributes, groups = contact 243 jid, attributes, groups = contact
243 self.contactPanel.addContact(jid, attributes, groups) 244 self.contact_panel.addContact(jid, attributes, groups)
244 245
245 def _getSignalsCB(self, signal_data): 246 def _getSignalsCB(self, signal_data):
246 bridge_signals = BridgeSignals() 247 bridge_signals = BridgeSignals()
247 bridge_signals.call('getSignals', self._getSignalsCB) 248 bridge_signals.call('getSignals', self._getSignalsCB)
248 print('Got signal ==> name: %s, params: %s' % (signal_data[0],signal_data[1])) 249 print('Got signal ==> name: %s, params: %s' % (signal_data[0],signal_data[1]))
251 self._personalEventCb(*args) 252 self._personalEventCb(*args)
252 elif name == 'newMessage': 253 elif name == 'newMessage':
253 self._newMessageCb(*args) 254 self._newMessageCb(*args)
254 elif name == 'presenceUpdate': 255 elif name == 'presenceUpdate':
255 self._presenceUpdateCb(*args) 256 self._presenceUpdateCb(*args)
257 elif name == 'roomJoined':
258 self._roomJoinedCb(*args)
256 259
257 def _getProfileJidCB(self, jid): 260 def _getProfileJidCB(self, jid):
258 self.whoami = JID(jid) 261 self.whoami = JID(jid)
259 #we can now ask our status 262 #we can now ask our status
260 self.bridge.call('getPresenceStatus', self._getPresenceStatusCB) 263 self.bridge.call('getPresenceStatus', self._getPresenceStatusCB)
286 if isinstance(panel,ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare): 289 if isinstance(panel,ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare):
287 panel.printMessage(_from, msg) 290 panel.printMessage(_from, msg)
288 291
289 def _presenceUpdateCb(self, entity, show, priority, statuses): 292 def _presenceUpdateCb(self, entity, show, priority, statuses):
290 _entity = JID(entity) 293 _entity = JID(entity)
291 #XXX: QnD way to only get our status 294 #XXX: QnD way to get our status
292 if self.whoami and self.whoami.bare == _entity.bare and statuses: 295 if self.whoami and self.whoami.bare == _entity.bare and statuses:
293 self.statusPanel.changeStatus(statuses.values()[0]) 296 self.status_panel.changeStatus(statuses.values()[0])
297 if not self.whoami or self.whoami.bare != _entity.bare:
298 self.contact_panel.setConnected(_entity.bare, _entity.resource, show, priority, statuses)
299
300 def _roomJoinedCb(self, room_id, room_service, room_nicks, user_nick, profile):
301 print "roomJoined"
302 print room_id
303 _target = JID("%s@%s" % (room_id,room_service))
304 if room_id.startswith('sat_tarot_'): #XXX: it's not really beautiful, but it works :)
305 self.tab_panel.add(ChatPanel(self, _target), "Tarot")
306 else:
307 self.tab_panel.add(ChatPanel(self, _target), str(_target))
308
294 309
295 def _getPresenceStatusCB(self, presence_data): 310 def _getPresenceStatusCB(self, presence_data):
296 #XXX we are only interested in our own presence so far 311 for entity in presence_data:
297 if self.whoami and presence_data.has_key(self.whoami.bare): 312 for resource in presence_data[entity]:
298 myjid = self.whoami.bare 313 args = presence_data[entity][resource]
299 if presence_data[myjid]: 314 self._presenceUpdateCb("%s/%s" % (entity, resource), *args)
300 args = presence_data[myjid].values()[0]
301 self._presenceUpdateCb(myjid, *args)
302 315
303 if __name__ == '__main__': 316 if __name__ == '__main__':
304 pyjd.setup("http://localhost:8080/libervia.html") 317 pyjd.setup("http://localhost:8080/libervia.html")
305 app = SatWebFrontend() 318 app = SatWebFrontend()
306 app.onModuleLoad() 319 app.onModuleLoad()