comparison libervia.py @ 326:36927be51481

browser_side: fixed the behavior regarding "Enable unibox" parameter: - unibox is disabled by default - dynamic refresh of the concerned widgets - use the generic method refresh instead of setUniBox
author souliane <souliane@mailoo.org>
date Tue, 07 Jan 2014 15:36:18 +0100
parents d07b54fdc60a
children 835a8ae799e7
comparison
equal deleted inserted replaced
325:d07b54fdc60a 326:36927be51481
184 self._register = RegisterCall() 184 self._register = RegisterCall()
185 self._register.call('registerParams', None) 185 self._register.call('registerParams', None)
186 self._register.call('isRegistered', self._isRegisteredCB) 186 self._register.call('isRegistered', self._isRegisteredCB)
187 self.initialised = False 187 self.initialised = False
188 self.init_cache = [] # used to cache events until initialisation is done 188 self.init_cache = [] # used to cache events until initialisation is done
189 # define here the parameters that have an incidende to UI refresh
190 self.params_ui = {"unibox": {"name": Const.ENABLE_UNIBOX_PARAM,
191 "category": Const.ENABLE_UNIBOX_KEY,
192 "cast": lambda value: value == 'true',
193 "value": None
194 }
195 }
189 196
190 def addSelectedListener(self, callback): 197 def addSelectedListener(self, callback):
191 self._selected_listeners.add(callback) 198 self._selected_listeners.add(callback)
192 199
193 def getSelected(self): 200 def getSelected(self):
262 try: 269 try:
263 self.libervia_widgets.remove(wid) 270 self.libervia_widgets.remove(wid)
264 except KeyError: 271 except KeyError:
265 print ('WARNING: trying to remove a non registered Widget:', wid.getDebugName()) 272 print ('WARNING: trying to remove a non registered Widget:', wid.getDebugName())
266 273
267 def _setUniBox(self, enable): 274 def refresh(self):
268 """Enable or disable the unibox widget. 275 """Refresh the general display."""
269 @param enable: boolean 276 self.panel.refresh()
270 """ 277 if self.params_ui['unibox']['value']:
271 self.uni_box = self.panel.setUniBoxPanel(enable == 'true') 278 self.uni_box = self.panel.unibox_panel.unibox
279 else:
280 self.uni_box = None
281 for lib_wid in self.libervia_widgets:
282 lib_wid.refresh()
283 self.resize()
272 284
273 def addTab(self, label, wid, select=True): 285 def addTab(self, label, wid, select=True):
274 """Create a new tab and eventually add a widget in 286 """Create a new tab and eventually add a widget in
275 @param label: label of the tab 287 @param label: label of the tab
276 @param wid: LiberviaWidget to add 288 @param wid: LiberviaWidget to add
326 338
327 def domain_eb(value): 339 def domain_eb(value):
328 self._defaultDomain = "libervia.org" 340 self._defaultDomain = "libervia.org"
329 341
330 self.bridge.call("getNewAccountDomain", (domain_cb, domain_eb)) 342 self.bridge.call("getNewAccountDomain", (domain_cb, domain_eb))
331 343 self.discuss_panel.addWidget(panels.MicroblogPanel(self, []))
332 def unibox_cb(enable): 344
333 self._setUniBox(enable) 345 # get ui params and refresh the display
334 self.discuss_panel.addWidget(panels.MicroblogPanel(self, [])) 346 count = 0 # used to do something similar to DeferredList
335 self.resize() # resize after all the UI elements have been attached 347
336 348 def params_ui_cb(param, value=None):
337 self.bridge.call('asyncGetParamA', unibox_cb, Const.ENABLE_UNIBOX_PARAM, Const.ENABLE_UNIBOX_KEY) 349 count += 1
350 refresh = count == len(self.params_ui)
351 self._paramUpdate(param['name'], value, param['category'], refresh)
352 for param in self.params_ui:
353 self.bridge.call('asyncGetParamA', lambda value: params_ui_cb(self.params_ui[param], value),
354 self.params_ui[param]['name'], self.params_ui[param]['category'])
338 355
339 def _tryAutoConnect(self): 356 def _tryAutoConnect(self):
340 """This method retrieve the eventual URL parameters to auto-connect the user.""" 357 """This method retrieve the eventual URL parameters to auto-connect the user."""
341 params = getURLParams(Window.getLocation().getSearch()) 358 params = getURLParams(Window.getLocation().getSearch())
342 if "login" in params: 359 if "login" in params:
393 self._personalEventCb(*args) 410 self._personalEventCb(*args)
394 elif name == 'newMessage': 411 elif name == 'newMessage':
395 self._newMessageCb(*args) 412 self._newMessageCb(*args)
396 elif name == 'presenceUpdate': 413 elif name == 'presenceUpdate':
397 self._presenceUpdateCb(*args) 414 self._presenceUpdateCb(*args)
415 elif name == 'paramUpdate':
416 self._paramUpdate(*args)
398 elif name == 'roomJoined': 417 elif name == 'roomJoined':
399 self._roomJoinedCb(*args) 418 self._roomJoinedCb(*args)
400 elif name == 'roomLeft': 419 elif name == 'roomLeft':
401 self._roomLeftCb(*args) 420 self._roomLeftCb(*args)
402 elif name == 'roomUserJoined': 421 elif name == 'roomUserJoined':
783 dialog.ConfirmDialog(confirm_cb, text=data["message"], title=data["title"]).show() 802 dialog.ConfirmDialog(confirm_cb, text=data["message"], title=data["title"]).show()
784 803
785 def _newAlert(self, message, title, alert_type): 804 def _newAlert(self, message, title, alert_type):
786 dialog.InfoDialog(title, message).show() 805 dialog.InfoDialog(title, message).show()
787 806
807 def _paramUpdate(self, name, value, category, refresh=True):
808 """This is called when the paramUpdate signal is received, but also
809 during initialization when the UI parameters values are retrieved.
810 @param refresh: set to True to refresh the general UI
811 """
812 for param in self.params_ui:
813 if name == self.params_ui[param]['name']:
814 self.params_ui[param]['value'] = self.params_ui[param]['cast'](value)
815 if refresh:
816 self.refresh()
817 break
818
788 def sendError(self, errorData): 819 def sendError(self, errorData):
789 dialog.InfoDialog("Error while sending message", 820 dialog.InfoDialog("Error while sending message",
790 "Your message can't be sent", Width="400px").center() 821 "Your message can't be sent", Width="400px").center()
791 print "sendError: %s" % str(errorData) 822 print "sendError: %s" % str(errorData)
792 823