comparison libervia.py @ 4:7325e787c22b

personalEvent management signal first draft, microblogs are now put in a central grid
author Goffi <goffi@goffi.org>
date Sun, 13 Feb 2011 16:20:22 +0100
parents 669c531a857e
children a663b9955cf3
comparison
equal deleted inserted replaced
3:154d4caa57f4 4:7325e787c22b
22 import pyjd # this is dummy in pyjs 22 import pyjd # this is dummy in pyjs
23 from pyjamas.ui.SimplePanel import SimplePanel 23 from pyjamas.ui.SimplePanel import SimplePanel
24 from pyjamas.ui.RootPanel import RootPanel 24 from pyjamas.ui.RootPanel import RootPanel
25 from pyjamas.ui.VerticalPanel import VerticalPanel 25 from pyjamas.ui.VerticalPanel import VerticalPanel
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel 26 from pyjamas.ui.HorizontalPanel import HorizontalPanel
27 from pyjamas.ui.HTMLPanel import HTMLPanel
28 from pyjamas.ui.Grid import Grid
27 from pyjamas.ui.Label import Label 29 from pyjamas.ui.Label import Label
28 from pyjamas.ui import HasAlignment 30 from pyjamas.ui import HasAlignment
29 from pyjamas.ui.MenuBar import MenuBar 31 from pyjamas.ui.MenuBar import MenuBar
30 from pyjamas.ui.MenuItem import MenuItem 32 from pyjamas.ui.MenuItem import MenuItem
31 from pyjamas import Window 33 from pyjamas import Window
32 from pyjamas.ui.AutoComplete import AutoCompleteTextBox 34 from pyjamas.ui.AutoComplete import AutoCompleteTextBox
33 from pyjamas.JSONService import JSONProxy 35 from pyjamas.JSONService import JSONProxy
34 from register import RegisterPanel, RegisterBox 36 from register import RegisterPanel, RegisterBox
35 from pyjamas import DOM 37 from pyjamas import DOM
36 from contact import ContactPanel 38 from contact import ContactPanel
39 from datetime import datetime
37 40
38 41
39 class LiberviaJsonProxy(JSONProxy): 42 class LiberviaJsonProxy(JSONProxy):
40 def __init__(self, *args, **kwargs): 43 def __init__(self, *args, **kwargs):
41 JSONProxy.__init__(self, *args, **kwargs) 44 JSONProxy.__init__(self, *args, **kwargs)
155 if contact.jid in self.groups[sender.group]: 158 if contact.jid in self.groups[sender.group]:
156 contact.removeStyleName("selected") 159 contact.removeStyleName("selected")
157 160
158 class MicroblogEntry(SimplePanel): 161 class MicroblogEntry(SimplePanel):
159 162
160 def __init__(self, text): 163 def __init__(self, body, author, timestamp):
161 SimplePanel.__init__(self) 164 SimplePanel.__init__(self)
162 self._vPanel = VerticalPanel() 165
163 self._vPanel.setStyleName('microblogEntry') 166 _datetime = datetime.fromtimestamp(timestamp)
164 _label = Label(text) 167
165 self._vPanel.add(_label) 168 panel = HTMLPanel("<div class='mb_entry_author'>%(author)s on <span class='mb_entry_timestamp'>%(timestamp)s</span></div><p class='mb_entry_body'>%(body)s</p>" %
166 self.add(self._vPanel) 169 {"author": author,
167 170 "timestamp": _datetime,
171 "body": body}
172 )
173 panel.setStyleName('microblogEntry')
174 self.add(panel)
168 175
169 176
170 class MicroblogPanel(VerticalPanel): 177 class MicroblogPanel(VerticalPanel):
171 178
172 def __init__(self): 179 def __init__(self):
173 VerticalPanel.__init__(self) 180 VerticalPanel.__init__(self)
174 self.setStyleName('microblogPanel') 181 self.setStyleName('microblogPanel')
175 182
176 def addEntry(self, text, author=None, date=None): 183 def addEntry(self, text, author=None, timestamp=None):
177 """Add an entry to the panel 184 """Add an entry to the panel
178 @param text: main text of the entry 185 @param text: main text of the entry
179 @param author: who wrote the entry 186 @param author: who wrote the entry
180 @param date: when the entry was written""" 187 @param date: when the entry was written"""
181 _entry = MicroblogEntry(text) 188 _entry = MicroblogEntry(text, author, timestamp)
182 self.add(_entry) 189 self.add(_entry)
183 190
184 class MiddlePannel(HorizontalPanel): 191 class MiddlePannel(HorizontalPanel):
185 192
186 def __init__(self,host): 193 def __init__(self, host):
187 self.host=host 194 self.host=host
188 HorizontalPanel.__init__(self) 195 HorizontalPanel.__init__(self)
189 self._left = self.host.contactPanel 196 self._left = self.host.contactPanel
190 self._right = HorizontalPanel() 197 self._right = Grid(1,3)
191 self._right.setWidth('100%') 198 self._right.setWidth('100%')
192 self._right.setHeight('100%') 199 self._right.setHeight('100%')
193 test = MicroblogPanel()
194 self._right.add(test)
195 test.addEntry("test entry")
196 self.add(self._left) 200 self.add(self._left)
197 self.setCellWidth(self._left, "15%") 201 self.setCellWidth(self._left, "15%")
198 self.add(self._right) 202 self.add(self._right)
199 self.setCellWidth(self._right, "85%") 203 self.setCellWidth(self._right, "85%")
200 204
205 def changePanel(self, idx, panel):
206 print "panel:",panel
207 print "idx:",idx
208 self._right.setWidget(0,idx,panel)
209
201 class MainPanel(VerticalPanel): 210 class MainPanel(VerticalPanel):
202 211
203 def __init__(self, host): 212 def __init__(self, host):
204 self.host=host 213 self.host=host
205 VerticalPanel.__init__(self) 214 VerticalPanel.__init__(self)
207 self.setHorizontalAlignment(HasAlignment.ALIGN_LEFT) 216 self.setHorizontalAlignment(HasAlignment.ALIGN_LEFT)
208 self.setVerticalAlignment(HasAlignment.ALIGN_TOP) 217 self.setVerticalAlignment(HasAlignment.ALIGN_TOP)
209 218
210 menu = Menu() 219 menu = Menu()
211 magic_box = host.magicBox 220 magic_box = host.magicBox
212 middle_panel = MiddlePannel(self.host) 221 self.middle_panel = MiddlePannel(self.host)
213 middle_panel.setWidth('100%') 222 self.middle_panel.setWidth('100%')
214 223
215 self.add(menu) 224 self.add(menu)
216 self.add(magic_box) 225 self.add(magic_box)
217 self.add(middle_panel) 226 self.add(self.middle_panel)
218 227
219 self.setCellHeight(menu, "5%") 228 self.setCellHeight(menu, "5%")
220 self.setCellHeight(magic_box, "5%") 229 self.setCellHeight(magic_box, "5%")
221 self.setCellVerticalAlignment(magic_box, HasAlignment.ALIGN_CENTER) 230 self.setCellVerticalAlignment(magic_box, HasAlignment.ALIGN_CENTER)
222 self.setCellHorizontalAlignment(magic_box, HasAlignment.ALIGN_CENTER) 231 self.setCellHorizontalAlignment(magic_box, HasAlignment.ALIGN_CENTER)
223 self.setCellHeight(middle_panel, "90%") 232 self.setCellHeight(self.middle_panel, "90%")
224 self.setCellWidth(middle_panel, "100%") 233 self.setCellWidth(self.middle_panel, "100%")
225 234
226 self.setWidth("100%") 235 self.setWidth("100%")
227 self.setHeight("100%") 236 self.setHeight("100%")
228 237
229 class SatWebFrontend: 238 class SatWebFrontend:
230 def onModuleLoad(self): 239 def onModuleLoad(self):
231 self.magicBox = MagicBox() 240 self.magicBox = MagicBox()
232 self.contactPanel = ContactPanel(self) 241 self.contactPanel = ContactPanel(self)
233 self.panel = MainPanel(self) 242 self.panel = MainPanel(self)
243 self.middle_panel = self.panel.middle_panel
244 self.mpanels = [MicroblogPanel()]
245 self.middle_panel.changePanel(1,self.mpanels[0])
234 self._dialog = None 246 self._dialog = None
235 RootPanel().add(self.panel) 247 RootPanel().add(self.panel)
236 self._register = RegisterCall() 248 self._register = RegisterCall()
237 self._register.call('isRegistered',self._isRegisteredCB) 249 self._register.call('isRegistered',self._isRegisteredCB)
238 250
269 281
270 def _getSignalsCB(self, signal_data): 282 def _getSignalsCB(self, signal_data):
271 bridge_signals = BridgeSignals() 283 bridge_signals = BridgeSignals()
272 bridge_signals.call('getSignals', self._getSignalsCB) 284 bridge_signals.call('getSignals', self._getSignalsCB)
273 print('Got signal ==> name: %s, params: %s' % (signal_data[0],signal_data[1])) 285 print('Got signal ==> name: %s, params: %s' % (signal_data[0],signal_data[1]))
274 286 name,args = signal_data
287 if name == 'personalEvent':
288 self._personalEventCb(*args)
289
290 ## Signals callbacks ##
291
292 def _personalEventCb(self, sender, event_type, data, profile):
293 if event_type == "MICROBLOG":
294 if not data.has_key('content'):
295 print ("WARNING: No content found in microblog data")
296 return
297 for panel in self.mpanels:
298 if isinstance(panel,MicroblogPanel):
299 content = data['content']
300 author = data.get('author')
301 print "timestamp: %s" % data.get('timestamp')
302 timestamp = float(data.get('timestamp'),0) #XXX: int doesn't work here
303 panel.addEntry(content, author, timestamp)
275 304
276 if __name__ == '__main__': 305 if __name__ == '__main__':
277 pyjd.setup("http://localhost:8080/libervia.html") 306 pyjd.setup("http://localhost:8080/libervia.html")
278 app = SatWebFrontend() 307 app = SatWebFrontend()
279 app.onModuleLoad() 308 app.onModuleLoad()