comparison src/browser/libervia_main.py @ 462:07433bd892ee

server and browser sides: fixes UI parameters initialisation with user values + small refactoring
author souliane <souliane@mailoo.org>
date Wed, 04 Jun 2014 00:23:14 +0200
parents d0cd8ae579f7
children 97c72fe4a5f2
comparison
equal deleted inserted replaced
461:4f25aa5039b3 462:07433bd892ee
195 self._register.call('getMenus', self.panel.menu.createMenus) 195 self._register.call('getMenus', self.panel.menu.createMenus)
196 self._register.call('registerParams', None) 196 self._register.call('registerParams', None)
197 self._register.call('isRegistered', self._isRegisteredCB) 197 self._register.call('isRegistered', self._isRegisteredCB)
198 self.initialised = False 198 self.initialised = False
199 self.init_cache = [] # used to cache events until initialisation is done 199 self.init_cache = [] # used to cache events until initialisation is done
200 # define here the parameters that have an incidende to UI refresh 200 self.ui_params = {key: C.UI_PARAMS[key]['initial_value'] for key in C.UI_PARAMS}
201 self.params_ui = {"unibox": {"name": C.ENABLE_UNIBOX_PARAM,
202 "category": C.ENABLE_UNIBOX_KEY,
203 "cast": lambda value: value == 'true',
204 "value": None
205 }
206 }
207 201
208 def addSelectedListener(self, callback): 202 def addSelectedListener(self, callback):
209 self._selected_listeners.add(callback) 203 self._selected_listeners.add(callback)
210 204
211 def getSelected(self): 205 def getSelected(self):
283 log.warning('trying to remove a non registered Widget: %s' % wid.getDebugName()) 277 log.warning('trying to remove a non registered Widget: %s' % wid.getDebugName())
284 278
285 def refresh(self): 279 def refresh(self):
286 """Refresh the general display.""" 280 """Refresh the general display."""
287 self.panel.refresh() 281 self.panel.refresh()
288 if self.params_ui['unibox']['value']: 282 if self.getUIParam('unibox'):
289 self.uni_box = self.panel.unibox_panel.unibox 283 self.uni_box = self.panel.unibox_panel.unibox
290 else: 284 else:
291 self.uni_box = None 285 self.uni_box = None
292 for lib_wid in self.libervia_widgets: 286 for lib_wid in self.libervia_widgets:
293 lib_wid.refresh() 287 lib_wid.refresh()
365 self.discuss_panel.addWidget(panels.MicroblogPanel(self, [])) 359 self.discuss_panel.addWidget(panels.MicroblogPanel(self, []))
366 360
367 # get ui params and refresh the display 361 # get ui params and refresh the display
368 count = 0 # used to do something similar to DeferredList 362 count = 0 # used to do something similar to DeferredList
369 363
370 def params_ui_cb(param, value=None): 364 def ui_params_cb(param):
371 count += 1 365 def cb(value):
372 refresh = count == len(self.params_ui) 366 count += 1
373 self._paramUpdate(param['name'], value, param['category'], refresh) 367 refresh = count == len(C.UI_PARAMS)
374 for param in self.params_ui: 368 self._paramUpdate(C.UI_PARAMS[param]['name'], value, C.UI_PARAMS[param]['category'], refresh)
375 self.bridge.call('asyncGetParamA', lambda value: params_ui_cb(self.params_ui[param], value), 369 return cb
376 self.params_ui[param]['name'], self.params_ui[param]['category']) 370
371 for param in C.UI_PARAMS:
372 self.bridge.call('asyncGetParamA', ui_params_cb(param), C.UI_PARAMS[param]['name'], C.UI_PARAMS[param]['category'])
377 373
378 def _tryAutoConnect(self, skip_validation=False): 374 def _tryAutoConnect(self, skip_validation=False):
379 """This method retrieve the eventual URL parameters to auto-connect the user. 375 """This method retrieve the eventual URL parameters to auto-connect the user.
380 @param skip_validation: if True, set the form values but do not validate it 376 @param skip_validation: if True, set the form values but do not validate it
381 """ 377 """
855 def _paramUpdate(self, name, value, category, refresh=True): 851 def _paramUpdate(self, name, value, category, refresh=True):
856 """This is called when the paramUpdate signal is received, but also 852 """This is called when the paramUpdate signal is received, but also
857 during initialization when the UI parameters values are retrieved. 853 during initialization when the UI parameters values are retrieved.
858 @param refresh: set to True to refresh the general UI 854 @param refresh: set to True to refresh the general UI
859 """ 855 """
860 for param in self.params_ui: 856 for param in C.UI_PARAMS:
861 if name == self.params_ui[param]['name']: 857 if name == C.UI_PARAMS[param]['name'] and category == C.UI_PARAMS[param]['category']:
862 self.params_ui[param]['value'] = self.params_ui[param]['cast'](value) 858 self.ui_params[param] = C.UI_PARAMS[param]['cast_from_str'](value)
863 if refresh: 859 if refresh:
864 self.refresh() 860 self.refresh()
865 break 861 break
862
863 def getUIParam(self, param):
864 """Return UI param cached value
865
866 @param param: the parameter key
867 """
868 return self.ui_params[param] if param in self.ui_params else None
866 869
867 def sendError(self, errorData): 870 def sendError(self, errorData):
868 dialog.InfoDialog("Error while sending message", 871 dialog.InfoDialog("Error while sending message",
869 "Your message can't be sent", Width="400px").center() 872 "Your message can't be sent", Width="400px").center()
870 log.error("sendError: %s" % str(errorData)) 873 log.error("sendError: %s" % str(errorData))