# HG changeset patch # User souliane # Date 1402605442 -7200 # Node ID 992b900ab876812520433f5bb7e2117490d1b91c # Parent fac8e8bc9a1ae116673e2178b634a25a9e731ab0 browser side: rename and refactor constant UI_PARAMS to CACHED_PARAMS, from a dict of dict to a list of 2-tuple diff -r fac8e8bc9a1a -r 992b900ab876 src/browser/libervia_main.py --- a/src/browser/libervia_main.py Thu Jun 12 22:32:33 2014 +0200 +++ b/src/browser/libervia_main.py Thu Jun 12 22:37:22 2014 +0200 @@ -196,7 +196,7 @@ self._register.call('isRegistered', self._isRegisteredCB) self.initialised = False self.init_cache = [] # used to cache events until initialisation is done - self.ui_params = {key: C.UI_PARAMS[key]['initial_value'] for key in C.UI_PARAMS} + self.cached_params = {} def addSelectedListener(self, callback): self._selected_listeners.add(callback) @@ -278,7 +278,7 @@ def refresh(self): """Refresh the general display.""" self.panel.refresh() - if self.getUIParam('unibox'): + if self.getCachedParam(C.COMPOSITION_KEY, C.ENABLE_UNIBOX_PARAM) == 'true': self.uni_box = self.panel.unibox_panel.unibox else: self.uni_box = None @@ -357,18 +357,15 @@ self.bridge.call("getNewAccountDomain", (domain_cb, domain_eb)) self.discuss_panel.addWidget(panels.MicroblogPanel(self, [])) - # get ui params and refresh the display - count = 0 # used to do something similar to DeferredList + # get cached params and refresh the display + def param_cb(cat, name, count): + count[0] += 1 + refresh = count[0] == len(C.CACHED_PARAMS) + return lambda value: self._paramUpdate(name, value, cat, refresh) - def ui_params_cb(param): - def cb(value): - count += 1 - refresh = count == len(C.UI_PARAMS) - self._paramUpdate(C.UI_PARAMS[param]['name'], value, C.UI_PARAMS[param]['category'], refresh) - return cb - - for param in C.UI_PARAMS: - self.bridge.call('asyncGetParamA', ui_params_cb(param), C.UI_PARAMS[param]['name'], C.UI_PARAMS[param]['category']) + count = [0] # used to do something similar to DeferredList + for cat, name in C.CACHED_PARAMS: + self.bridge.call('asyncGetParamA', param_cb(cat, name, count), name, cat) def _tryAutoConnect(self, skip_validation=False): """This method retrieve the eventual URL parameters to auto-connect the user. @@ -852,19 +849,20 @@ during initialization when the UI parameters values are retrieved. @param refresh: set to True to refresh the general UI """ - for param in C.UI_PARAMS: - if name == C.UI_PARAMS[param]['name'] and category == C.UI_PARAMS[param]['category']: - self.ui_params[param] = C.UI_PARAMS[param]['cast_from_str'](value) + for param_cat, param_name in C.CACHED_PARAMS: + if name == param_name and category == param_cat: + self.cached_params[(category, name)] = value if refresh: self.refresh() break - def getUIParam(self, param): - """Return UI param cached value + def getCachedParam(self, category, name): + """Return a parameter cached value (e.g for refreshing the UI) - @param param: the parameter key + @param category (str): the parameter category + @pram name (str): the parameter name """ - return self.ui_params[param] if param in self.ui_params else None + return self.cached_params[(category, name)] if (category, name) in self.cached_params else None def sendError(self, errorData): dialog.InfoDialog("Error while sending message", diff -r fac8e8bc9a1a -r 992b900ab876 src/browser/sat_browser/constants.py --- a/src/browser/sat_browser/constants.py Thu Jun 12 22:32:33 2014 +0200 +++ b/src/browser/sat_browser/constants.py Thu Jun 12 22:37:22 2014 +0200 @@ -27,16 +27,10 @@ class Const(C): """Add here the constants that are only used by the browser side.""" - # Parameters that have an incidence on UI display/refresh: + # Cached parameters, e.g those that have an incidence on UI display/refresh: # - they can be any parameter (not necessarily specific to Libervia) - # - 'cast_from_str' is a method used to eventually convert to a non string type - # - 'initial_value' is used to initialize the display before any profile connection - UI_PARAMS = {"unibox": {"name": C.ENABLE_UNIBOX_PARAM, - "category": C.COMPOSITION_KEY, - "cast_from_str": param_to_bool, - "initial_value": False - }, - } + # - list them as a couple (category, name) + CACHED_PARAMS = [(C.COMPOSITION_KEY, C.ENABLE_UNIBOX_PARAM)] # Default avatar DEFAULT_AVATAR = "/media/misc/default_avatar.png" diff -r fac8e8bc9a1a -r 992b900ab876 src/browser/sat_browser/panels.py --- a/src/browser/sat_browser/panels.py Thu Jun 12 22:32:33 2014 +0200 +++ b/src/browser/sat_browser/panels.py Thu Jun 12 22:37:22 2014 +0200 @@ -79,7 +79,7 @@ def refresh(self): """Enable or disable this panel. Contained widgets are created when necessary.""" - enable = self.host.getUIParam('unibox') + enable = self.host.getCachedParam(C.COMPOSITION_KEY, C.ENABLE_UNIBOX_PARAM) == 'true' self.setVisible(enable) if enable and not self.unibox: self.button = Button('')