Mercurial > libervia-web
comparison src/browser/libervia_main.py @ 478:992b900ab876
browser side: rename and refactor constant UI_PARAMS to CACHED_PARAMS, from a dict of dict to a list of 2-tuple
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 12 Jun 2014 22:37:22 +0200 |
parents | fac8e8bc9a1a |
children | c21ea1fe3593 |
comparison
equal
deleted
inserted
replaced
477:fac8e8bc9a1a | 478:992b900ab876 |
---|---|
194 self._register.call('getMenus', self.panel.menu.createMenus) | 194 self._register.call('getMenus', self.panel.menu.createMenus) |
195 self._register.call('registerParams', None) | 195 self._register.call('registerParams', None) |
196 self._register.call('isRegistered', self._isRegisteredCB) | 196 self._register.call('isRegistered', self._isRegisteredCB) |
197 self.initialised = False | 197 self.initialised = False |
198 self.init_cache = [] # used to cache events until initialisation is done | 198 self.init_cache = [] # used to cache events until initialisation is done |
199 self.ui_params = {key: C.UI_PARAMS[key]['initial_value'] for key in C.UI_PARAMS} | 199 self.cached_params = {} |
200 | 200 |
201 def addSelectedListener(self, callback): | 201 def addSelectedListener(self, callback): |
202 self._selected_listeners.add(callback) | 202 self._selected_listeners.add(callback) |
203 | 203 |
204 def getSelected(self): | 204 def getSelected(self): |
276 log.warning('trying to remove a non registered Widget: %s' % wid.getDebugName()) | 276 log.warning('trying to remove a non registered Widget: %s' % wid.getDebugName()) |
277 | 277 |
278 def refresh(self): | 278 def refresh(self): |
279 """Refresh the general display.""" | 279 """Refresh the general display.""" |
280 self.panel.refresh() | 280 self.panel.refresh() |
281 if self.getUIParam('unibox'): | 281 if self.getCachedParam(C.COMPOSITION_KEY, C.ENABLE_UNIBOX_PARAM) == 'true': |
282 self.uni_box = self.panel.unibox_panel.unibox | 282 self.uni_box = self.panel.unibox_panel.unibox |
283 else: | 283 else: |
284 self.uni_box = None | 284 self.uni_box = None |
285 for lib_wid in self.libervia_widgets: | 285 for lib_wid in self.libervia_widgets: |
286 lib_wid.refresh() | 286 lib_wid.refresh() |
355 self._defaultDomain = "libervia.org" | 355 self._defaultDomain = "libervia.org" |
356 | 356 |
357 self.bridge.call("getNewAccountDomain", (domain_cb, domain_eb)) | 357 self.bridge.call("getNewAccountDomain", (domain_cb, domain_eb)) |
358 self.discuss_panel.addWidget(panels.MicroblogPanel(self, [])) | 358 self.discuss_panel.addWidget(panels.MicroblogPanel(self, [])) |
359 | 359 |
360 # get ui params and refresh the display | 360 # get cached params and refresh the display |
361 count = 0 # used to do something similar to DeferredList | 361 def param_cb(cat, name, count): |
362 | 362 count[0] += 1 |
363 def ui_params_cb(param): | 363 refresh = count[0] == len(C.CACHED_PARAMS) |
364 def cb(value): | 364 return lambda value: self._paramUpdate(name, value, cat, refresh) |
365 count += 1 | 365 |
366 refresh = count == len(C.UI_PARAMS) | 366 count = [0] # used to do something similar to DeferredList |
367 self._paramUpdate(C.UI_PARAMS[param]['name'], value, C.UI_PARAMS[param]['category'], refresh) | 367 for cat, name in C.CACHED_PARAMS: |
368 return cb | 368 self.bridge.call('asyncGetParamA', param_cb(cat, name, count), name, cat) |
369 | |
370 for param in C.UI_PARAMS: | |
371 self.bridge.call('asyncGetParamA', ui_params_cb(param), C.UI_PARAMS[param]['name'], C.UI_PARAMS[param]['category']) | |
372 | 369 |
373 def _tryAutoConnect(self, skip_validation=False): | 370 def _tryAutoConnect(self, skip_validation=False): |
374 """This method retrieve the eventual URL parameters to auto-connect the user. | 371 """This method retrieve the eventual URL parameters to auto-connect the user. |
375 @param skip_validation: if True, set the form values but do not validate it | 372 @param skip_validation: if True, set the form values but do not validate it |
376 """ | 373 """ |
850 def _paramUpdate(self, name, value, category, refresh=True): | 847 def _paramUpdate(self, name, value, category, refresh=True): |
851 """This is called when the paramUpdate signal is received, but also | 848 """This is called when the paramUpdate signal is received, but also |
852 during initialization when the UI parameters values are retrieved. | 849 during initialization when the UI parameters values are retrieved. |
853 @param refresh: set to True to refresh the general UI | 850 @param refresh: set to True to refresh the general UI |
854 """ | 851 """ |
855 for param in C.UI_PARAMS: | 852 for param_cat, param_name in C.CACHED_PARAMS: |
856 if name == C.UI_PARAMS[param]['name'] and category == C.UI_PARAMS[param]['category']: | 853 if name == param_name and category == param_cat: |
857 self.ui_params[param] = C.UI_PARAMS[param]['cast_from_str'](value) | 854 self.cached_params[(category, name)] = value |
858 if refresh: | 855 if refresh: |
859 self.refresh() | 856 self.refresh() |
860 break | 857 break |
861 | 858 |
862 def getUIParam(self, param): | 859 def getCachedParam(self, category, name): |
863 """Return UI param cached value | 860 """Return a parameter cached value (e.g for refreshing the UI) |
864 | 861 |
865 @param param: the parameter key | 862 @param category (str): the parameter category |
863 @pram name (str): the parameter name | |
866 """ | 864 """ |
867 return self.ui_params[param] if param in self.ui_params else None | 865 return self.cached_params[(category, name)] if (category, name) in self.cached_params else None |
868 | 866 |
869 def sendError(self, errorData): | 867 def sendError(self, errorData): |
870 dialog.InfoDialog("Error while sending message", | 868 dialog.InfoDialog("Error while sending message", |
871 "Your message can't be sent", Width="400px").center() | 869 "Your message can't be sent", Width="400px").center() |
872 log.error("sendError: %s" % str(errorData)) | 870 log.error("sendError: %s" % str(errorData)) |