Mercurial > libervia-web
comparison libervia.py @ 20:8f4b1a8914c3
- User status is now updated
- by default, the uniBar target the status
- clicking on user's status unselect the selected widget
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 16 Apr 2011 18:06:02 +0200 |
parents | e8e3704eb97f |
children | 77c2e48efa29 |
comparison
equal
deleted
inserted
replaced
19:e8e3704eb97f | 20:8f4b1a8914c3 |
---|---|
65 self.cb={} | 65 self.cb={} |
66 | 66 |
67 class BridgeCall(LiberviaJsonProxy): | 67 class BridgeCall(LiberviaJsonProxy): |
68 def __init__(self): | 68 def __init__(self): |
69 LiberviaJsonProxy.__init__(self, "/json_api", | 69 LiberviaJsonProxy.__init__(self, "/json_api", |
70 ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory"]) | 70 ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus"]) |
71 | 71 |
72 class BridgeSignals(LiberviaJsonProxy): | 72 class BridgeSignals(LiberviaJsonProxy): |
73 def __init__(self): | 73 def __init__(self): |
74 LiberviaJsonProxy.__init__(self, "/json_signal_api", | 74 LiberviaJsonProxy.__init__(self, "/json_signal_api", |
75 ["getSignals"]) | 75 ["getSignals"]) |
88 if keycode == KEY_ENTER and not self.visible: | 88 if keycode == KEY_ENTER and not self.visible: |
89 _txt = self.getText() | 89 _txt = self.getText() |
90 if _txt: | 90 if _txt: |
91 if _txt.startswith('@'): | 91 if _txt.startswith('@'): |
92 self.host.bridge.call('sendMblog', None, self.getText()) | 92 self.host.bridge.call('sendMblog', None, self.getText()) |
93 elif self.host.selected == None: | |
94 print "changement de status pour", _txt | |
95 self.host.bridge.call('setStatus', None, _txt) | |
93 elif isinstance(self.host.selected, ChatPanel): | 96 elif isinstance(self.host.selected, ChatPanel): |
94 _chat = self.host.selected | 97 _chat = self.host.selected |
95 self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', 'chat') | 98 self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', 'chat') |
96 self.setText('') | 99 self.setText('') |
97 | 100 |
98 def complete(self): | 101 def complete(self): |
99 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done | 102 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
100 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this | 103 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this |
107 self.bridge = BridgeCall() | 110 self.bridge = BridgeCall() |
108 self.bridge_signals = BridgeSignals() | 111 self.bridge_signals = BridgeSignals() |
109 self.selected = None | 112 self.selected = None |
110 self.uniBox = UniBox(self) | 113 self.uniBox = UniBox(self) |
111 self.uniBox.addKey("@@: ") | 114 self.uniBox.addKey("@@: ") |
112 self.statusPanel = StatusPanel() | 115 self.statusPanel = StatusPanel(self) |
113 self.contactPanel = ContactPanel(self) | 116 self.contactPanel = ContactPanel(self) |
114 self.panel = MainPanel(self) | 117 self.panel = MainPanel(self) |
115 self.middle_panel = self.panel.middle_panel | 118 self.middle_panel = self.panel.middle_panel |
116 self.mpanels = [EmptyPanel(self), MicroblogPanel(self, accept_all=True), EmptyPanel(self)] | 119 self.mpanels = [EmptyPanel(self), MicroblogPanel(self, accept_all=True), EmptyPanel(self)] |
117 self.middle_panel.changePanel(0,self.mpanels[0]) | 120 self.middle_panel.changePanel(0,self.mpanels[0]) |
166 name,args = signal_data | 169 name,args = signal_data |
167 if name == 'personalEvent': | 170 if name == 'personalEvent': |
168 self._personalEventCb(*args) | 171 self._personalEventCb(*args) |
169 elif name == 'newMessage': | 172 elif name == 'newMessage': |
170 self._newMessageCb(*args) | 173 self._newMessageCb(*args) |
174 elif name == 'presenceUpdate': | |
175 self._presenceUpdateCb(*args) | |
171 | 176 |
172 def _getProfileJidCB(self, jid): | 177 def _getProfileJidCB(self, jid): |
173 self.whoami = JID(jid) | 178 self.whoami = JID(jid) |
179 #we can now ask our status | |
180 self.bridge.call('getPresenceStatus', self._getPresenceStatusCB) | |
181 | |
174 | 182 |
175 | 183 |
176 ## Signals callbacks ## | 184 ## Signals callbacks ## |
177 | 185 |
178 def _personalEventCb(self, sender, event_type, data, profile): | 186 def _personalEventCb(self, sender, event_type, data, profile): |
200 _to = JID(to_jid) | 208 _to = JID(to_jid) |
201 for panel in self.mpanels: | 209 for panel in self.mpanels: |
202 if isinstance(panel,ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare): | 210 if isinstance(panel,ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare): |
203 panel.printMessage(_from, msg) | 211 panel.printMessage(_from, msg) |
204 | 212 |
213 def _presenceUpdateCb(self, entity, show, priority, statuses): | |
214 _entity = JID(entity) | |
215 #XXX: QnD way to only get our status | |
216 if self.whoami and self.whoami.bare == _entity.bare and statuses: | |
217 self.statusPanel.changeStatus(statuses.values()[0]) | |
218 | |
219 def _getPresenceStatusCB(self, presence_data): | |
220 #XXX we are only interested in our own presence so far | |
221 if self.whoami and presence_data.has_key(self.whoami.bare): | |
222 myjid = self.whoami.bare | |
223 if presence_data[myjid]: | |
224 args = presence_data[myjid].values()[0] | |
225 self._presenceUpdateCb(myjid, *args) | |
226 | |
205 if __name__ == '__main__': | 227 if __name__ == '__main__': |
206 pyjd.setup("http://localhost:8080/libervia.html") | 228 pyjd.setup("http://localhost:8080/libervia.html") |
207 app = SatWebFrontend() | 229 app = SatWebFrontend() |
208 app.onModuleLoad() | 230 app.onModuleLoad() |
209 pyjd.run() | 231 pyjd.run() |