Mercurial > libervia-web
diff 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 |
line wrap: on
line diff
--- a/libervia.py Fri Mar 25 00:32:58 2011 +0100 +++ b/libervia.py Sat Mar 26 17:53:12 2011 +0100 @@ -34,6 +34,7 @@ from pyjamas.ui.DropWidget import DropWidget from pyjamas import Window from pyjamas.JSONService import JSONProxy +from pyjamas.ui.KeyboardListener import KEY_ENTER from register import RegisterPanel, RegisterBox from pyjamas import DOM from contact import ContactPanel @@ -47,7 +48,8 @@ self.cb={} def call(self, method, cb, *args): - self.cb[method] = cb + if cb: + self.cb[method] = cb self.callMethod(method,args) def onRemoteResponse(self, response, request_info): @@ -74,7 +76,7 @@ class BridgeCall(LiberviaJsonProxy): def __init__(self): LiberviaJsonProxy.__init__(self, "/json_api", - ["getContacts"]) + ["getContacts", "sendMblog"]) class BridgeSignals(LiberviaJsonProxy): def __init__(self): @@ -119,45 +121,22 @@ class MagicBox(AutoCompleteTextBox): - def __init__(self): + def __init__(self, host): AutoCompleteTextBox.__init__(self) + self.host = host def addKey(self, key): self.getCompletionItems().completions.append(key) - def addContact(self, jid, attributes, groups): - """Add a contact to the panel - @param jid: jid - @attributes: cf SàT Bridge API's newContact - @param groups: list of groups""" - for group in groups: - if not self.groups.has_key(group): - self.groups[group] = set() - self._groupList.add(group) - self.host.magicBox.addKey("@%s: " % group) - self.groups[group].add(jid) - self._contactList.add(jid) + def onKeyPress(self, sender, keycode, modifiers): + if keycode == KEY_ENTER and not self.visible: + self.host.bridge.call('sendMblog', None, self.getText()) + self.setText('') - def onMouseMove(self, sender, x, y): - pass - - def onMouseDown(self, sender, x, y): - pass - - def onMouseUp(self, sender, x, y): - pass - - def onMouseEnter(self, sender): - if isinstance(sender, GroupLabel): - for contact in self._contactList: - if contact.jid in self.groups[sender.group]: - contact.addStyleName("selected") - - def onMouseLeave(self, sender): - if isinstance(sender, GroupLabel): - for contact in self._contactList: - if contact.jid in self.groups[sender.group]: - contact.removeStyleName("selected") + def complete(self): + #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done + #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this + return AutoCompleteTextBox.complete(self) class EmptyPanel(DropWidget, SimplePanel): """Empty dropable panel""" @@ -282,7 +261,10 @@ class SatWebFrontend: def onModuleLoad(self): - self.magicBox = MagicBox() + self.bridge = BridgeCall() + self.bridge_signals = BridgeSignals() + self.magicBox = MagicBox(self) + self.magicBox.addKey("@@: ") self.contactPanel = ContactPanel(self) self.panel = MainPanel(self) self.middle_panel = self.panel.middle_panel @@ -314,11 +296,8 @@ del self._dialog # don't work if self._dialog is None #it's time to fill the page - bridge = BridgeCall() - bridge.call('getContacts', self._getContactsCB) - - bridge_signals = BridgeSignals() - bridge_signals.call('getSignals', self._getSignalsCB) + self.bridge.call('getContacts', self._getContactsCB) + self.bridge_signals.call('getSignals', self._getSignalsCB) def _getContactsCB(self, contacts_data):