comparison 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
comparison
equal deleted inserted replaced
10:c28a4840e1a8 11:331c093e4eb3
32 from pyjamas.ui.MenuItem import MenuItem 32 from pyjamas.ui.MenuItem import MenuItem
33 from pyjamas.ui.AutoComplete import AutoCompleteTextBox 33 from pyjamas.ui.AutoComplete import AutoCompleteTextBox
34 from pyjamas.ui.DropWidget import DropWidget 34 from pyjamas.ui.DropWidget import DropWidget
35 from pyjamas import Window 35 from pyjamas import Window
36 from pyjamas.JSONService import JSONProxy 36 from pyjamas.JSONService import JSONProxy
37 from pyjamas.ui.KeyboardListener import KEY_ENTER
37 from register import RegisterPanel, RegisterBox 38 from register import RegisterPanel, RegisterBox
38 from pyjamas import DOM 39 from pyjamas import DOM
39 from contact import ContactPanel 40 from contact import ContactPanel
40 from datetime import datetime 41 from datetime import datetime
41 42
45 JSONProxy.__init__(self, *args, **kwargs) 46 JSONProxy.__init__(self, *args, **kwargs)
46 self.handler=self 47 self.handler=self
47 self.cb={} 48 self.cb={}
48 49
49 def call(self, method, cb, *args): 50 def call(self, method, cb, *args):
50 self.cb[method] = cb 51 if cb:
52 self.cb[method] = cb
51 self.callMethod(method,args) 53 self.callMethod(method,args)
52 54
53 def onRemoteResponse(self, response, request_info): 55 def onRemoteResponse(self, response, request_info):
54 if self.cb.has_key(request_info.method): 56 if self.cb.has_key(request_info.method):
55 self.cb[request_info.method](response) 57 self.cb[request_info.method](response)
72 self.cb={} 74 self.cb={}
73 75
74 class BridgeCall(LiberviaJsonProxy): 76 class BridgeCall(LiberviaJsonProxy):
75 def __init__(self): 77 def __init__(self):
76 LiberviaJsonProxy.__init__(self, "/json_api", 78 LiberviaJsonProxy.__init__(self, "/json_api",
77 ["getContacts"]) 79 ["getContacts", "sendMblog"])
78 80
79 class BridgeSignals(LiberviaJsonProxy): 81 class BridgeSignals(LiberviaJsonProxy):
80 def __init__(self): 82 def __init__(self):
81 LiberviaJsonProxy.__init__(self, "/json_signal_api", 83 LiberviaJsonProxy.__init__(self, "/json_signal_api",
82 ["getSignals"]) 84 ["getSignals"])
117 def onXiangqiGame(self): 119 def onXiangqiGame(self):
118 Window.alert("Xiangqi selected") 120 Window.alert("Xiangqi selected")
119 121
120 class MagicBox(AutoCompleteTextBox): 122 class MagicBox(AutoCompleteTextBox):
121 123
122 def __init__(self): 124 def __init__(self, host):
123 AutoCompleteTextBox.__init__(self) 125 AutoCompleteTextBox.__init__(self)
126 self.host = host
124 127
125 def addKey(self, key): 128 def addKey(self, key):
126 self.getCompletionItems().completions.append(key) 129 self.getCompletionItems().completions.append(key)
127 130
128 def addContact(self, jid, attributes, groups): 131 def onKeyPress(self, sender, keycode, modifiers):
129 """Add a contact to the panel 132 if keycode == KEY_ENTER and not self.visible:
130 @param jid: jid 133 self.host.bridge.call('sendMblog', None, self.getText())
131 @attributes: cf SàT Bridge API's newContact 134 self.setText('')
132 @param groups: list of groups""" 135
133 for group in groups: 136 def complete(self):
134 if not self.groups.has_key(group): 137 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done
135 self.groups[group] = set() 138 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this
136 self._groupList.add(group) 139 return AutoCompleteTextBox.complete(self)
137 self.host.magicBox.addKey("@%s: " % group)
138 self.groups[group].add(jid)
139 self._contactList.add(jid)
140
141 def onMouseMove(self, sender, x, y):
142 pass
143
144 def onMouseDown(self, sender, x, y):
145 pass
146
147 def onMouseUp(self, sender, x, y):
148 pass
149
150 def onMouseEnter(self, sender):
151 if isinstance(sender, GroupLabel):
152 for contact in self._contactList:
153 if contact.jid in self.groups[sender.group]:
154 contact.addStyleName("selected")
155
156 def onMouseLeave(self, sender):
157 if isinstance(sender, GroupLabel):
158 for contact in self._contactList:
159 if contact.jid in self.groups[sender.group]:
160 contact.removeStyleName("selected")
161 140
162 class EmptyPanel(DropWidget, SimplePanel): 141 class EmptyPanel(DropWidget, SimplePanel):
163 """Empty dropable panel""" 142 """Empty dropable panel"""
164 143
165 def __init__(self, host, data): 144 def __init__(self, host, data):
280 self.setWidth("100%") 259 self.setWidth("100%")
281 self.setHeight("100%") 260 self.setHeight("100%")
282 261
283 class SatWebFrontend: 262 class SatWebFrontend:
284 def onModuleLoad(self): 263 def onModuleLoad(self):
285 self.magicBox = MagicBox() 264 self.bridge = BridgeCall()
265 self.bridge_signals = BridgeSignals()
266 self.magicBox = MagicBox(self)
267 self.magicBox.addKey("@@: ")
286 self.contactPanel = ContactPanel(self) 268 self.contactPanel = ContactPanel(self)
287 self.panel = MainPanel(self) 269 self.panel = MainPanel(self)
288 self.middle_panel = self.panel.middle_panel 270 self.middle_panel = self.panel.middle_panel
289 self.mpanels = [MicroblogPanel()] 271 self.mpanels = [MicroblogPanel()]
290 self.middle_panel.changePanel(1,self.mpanels[0]) 272 self.middle_panel.changePanel(1,self.mpanels[0])
312 if self._dialog: 294 if self._dialog:
313 self._dialog.hide() 295 self._dialog.hide()
314 del self._dialog # don't work if self._dialog is None 296 del self._dialog # don't work if self._dialog is None
315 297
316 #it's time to fill the page 298 #it's time to fill the page
317 bridge = BridgeCall() 299 self.bridge.call('getContacts', self._getContactsCB)
318 bridge.call('getContacts', self._getContactsCB) 300 self.bridge_signals.call('getSignals', self._getSignalsCB)
319
320 bridge_signals = BridgeSignals()
321 bridge_signals.call('getSignals', self._getSignalsCB)
322 301
323 302
324 def _getContactsCB(self, contacts_data): 303 def _getContactsCB(self, contacts_data):
325 for contact in contacts_data: 304 for contact in contacts_data:
326 jid, attributes, groups = contact 305 jid, attributes, groups = contact