Mercurial > libervia-web
diff libervia.py @ 2:669c531a857e
signals handling and first draft of microblogging
- server side: signal handling throught json_signal_api page
- browser side: - signal handling throught a json rpc call loop
- first draft of microblog panel
- ContactPanel put in a separate module
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 08 Feb 2011 21:18:31 +0100 |
parents | 0a7c685faa53 |
children | 7325e787c22b |
line wrap: on
line diff
--- a/libervia.py Mon Jan 31 20:31:25 2011 +0100 +++ b/libervia.py Tue Feb 08 21:18:31 2011 +0100 @@ -33,6 +33,7 @@ from pyjamas.JSONService import JSONProxy from register import RegisterPanel, RegisterBox from pyjamas import DOM +from contact import ContactPanel class LiberviaJsonProxy(JSONProxy): @@ -66,11 +67,16 @@ self.handler=self self.cb={} -class BrigeCall(LiberviaJsonProxy): +class BridgeCall(LiberviaJsonProxy): def __init__(self): LiberviaJsonProxy.__init__(self, "/json_api", ["getContacts"]) +class BridgeSignals(LiberviaJsonProxy): + def __init__(self): + LiberviaJsonProxy.__init__(self, "/json_signal_api", + ["getSignals"]) + class MenuCmd: def __init__(self, object, handler): @@ -115,70 +121,6 @@ def addKey(self, key): self.getCompletionItems().completions.append(key) -class GroupLabel(Label): - def __init__(self, group): - Label.__init__(self, group) - self.group = group - self.setStyleName('group') - -class ContactLabel(Label): - def __init__(self, jid, name=None): - if not name: - name=jid - Label.__init__(self, name) - self.jid=jid - self.setStyleName('contact') - -class GroupList(VerticalPanel): - - def __init__(self, parent): - VerticalPanel.__init__(self) - self._parent = parent - - def add(self, group): - _item = GroupLabel(group) - _item.addMouseListener(self._parent) - DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") - VerticalPanel.add(self, _item) - -class ContactList(VerticalPanel): - - def __init__(self): - VerticalPanel.__init__(self) - self.contacts=[] - - def __iter__(self): - return self.contacts.__iter__() - - def add(self, jid, name=None): - _item = ContactLabel(jid, name) - DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") - VerticalPanel.add(self, _item) - self.contacts.append(_item) - -class ContactPanel(SimplePanel): - """Manage the contacts and groups""" - - def __init__(self, host): - SimplePanel.__init__(self) - self.host = host - self.groups={} - - self.vPanel = VerticalPanel() - _title = Label('Contacts') - _title.setStyleName('contactTitle') - - self._contactList = ContactList() - self._contactList.setStyleName('contactList') - self._groupList = GroupList(self) - self._groupList.setStyleName('groupList') - - self.vPanel.add(_title) - self.vPanel.add(self._groupList) - self.vPanel.add(self._contactList) - self.add(self.vPanel) - self.setStyleName('contactBox') - def addContact(self, jid, attributes, groups): """Add a contact to the panel @param jid: jid @@ -213,12 +155,48 @@ if contact.jid in self.groups[sender.group]: contact.removeStyleName("selected") +class MicroblogEntry(SimplePanel): + + def __init__(self, text): + SimplePanel.__init__(self) + self._vPanel = VerticalPanel() + self._vPanel.setStyleName('microblogEntry') + _label = Label(text) + self._vPanel.add(_label) + self.add(self._vPanel) + + + +class MicroblogPanel(VerticalPanel): + + def __init__(self): + VerticalPanel.__init__(self) + self.setStyleName('microblogPanel') + + def addEntry(self, text, author=None, date=None): + """Add an entry to the panel + @param text: main text of the entry + @param author: who wrote the entry + @param date: when the entry was written""" + _entry = MicroblogEntry(text) + self.add(_entry) + class MiddlePannel(HorizontalPanel): def __init__(self,host): self.host=host HorizontalPanel.__init__(self) - self.add(self.host.contactPanel) + self._left = self.host.contactPanel + self._right = HorizontalPanel() + self._right.setWidth('100%') + self._right.setHeight('100%') + test = MicroblogPanel() + self._right.add(test) + test.addEntry("test entry") + self.add(self._left) + self.setCellWidth(self._left, "15%") + self.add(self._right) + self.setCellWidth(self._right, "85%") class MainPanel(VerticalPanel): @@ -232,6 +210,7 @@ menu = Menu() magic_box = host.magicBox middle_panel = MiddlePannel(self.host) + middle_panel.setWidth('100%') self.add(menu) self.add(magic_box) @@ -242,6 +221,7 @@ self.setCellVerticalAlignment(magic_box, HasAlignment.ALIGN_CENTER) self.setCellHorizontalAlignment(magic_box, HasAlignment.ALIGN_CENTER) self.setCellHeight(middle_panel, "90%") + self.setCellWidth(middle_panel, "100%") self.setWidth("100%") self.setHeight("100%") @@ -275,14 +255,23 @@ del self._dialog # don't work if self._dialog is None #it's time to fill the page - bridge = BrigeCall() + bridge = BridgeCall() bridge.call('getContacts', self._getContactsCB) + bridge_signals = BridgeSignals() + bridge_signals.call('getSignals', self._getSignalsCB) + + def _getContactsCB(self, contacts_data): for contact in contacts_data: jid, attributes, groups = contact self.contactPanel.addContact(jid, attributes, groups) + def _getSignalsCB(self, signal_data): + bridge_signals = BridgeSignals() + bridge_signals.call('getSignals', self._getSignalsCB) + print('Got signal ==> name: %s, params: %s' % (signal_data[0],signal_data[1])) + if __name__ == '__main__': pyjd.setup("http://localhost:8080/libervia.html")