comparison sat_frontends/quick_frontend/quick_app.py @ 2846:58ea675d0f05

quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically: if AUTO_RESYNC is False, frontend must call itself the resync method. This is useful to improve performance, resynchronising all widgets at once may be resource intensive, and it may be more efficient to resync a widget only when it is visible.
author Goffi <goffi@goffi.org>
date Sun, 10 Mar 2019 18:02:42 +0100
parents 42380a4f6433
children b9da74c9d46e
comparison
equal deleted inserted replaced
2845:42380a4f6433 2846:58ea675d0f05
275 275
276 276
277 class QuickApp(object): 277 class QuickApp(object):
278 """This class contain the main methods needed for the frontend""" 278 """This class contain the main methods needed for the frontend"""
279 279
280 MB_HANDLER = True # Set to False if the frontend doesn't manage microblog 280 MB_HANDLER = True #: Set to False if the frontend doesn't manage microblog
281 AVATARS_HANDLER = True # set to False if avatars are not used 281 AVATARS_HANDLER = True #: set to False if avatars are not used
282 ENCRYPTION_HANDLERS = True # set to False if encryption is handled separatly 282 ENCRYPTION_HANDLERS = True #: set to False if encryption is handled separatly
283 #: if True, QuickApp will call resync itself, on all widgets at the same time
284 #: if False, frontend must call resync itself when suitable (e.g. widget is being
285 #: visible)
286 AUTO_RESYNC = True
283 287
284 def __init__(self, bridge_factory, xmlui, check_options=None, connect_bridge=True): 288 def __init__(self, bridge_factory, xmlui, check_options=None, connect_bridge=True):
285 """Create a frontend application 289 """Create a frontend application
286 290
287 @param bridge_factory: method to use to create the Bridge 291 @param bridge_factory: method to use to create the Bridge
443 @param state(bool): True: if the backend is resynchronising 447 @param state(bool): True: if the backend is resynchronising
444 False when we lose synchronisation, for instance if frontend is going to sleep 448 False when we lose synchronisation, for instance if frontend is going to sleep
445 or if connection has been lost and a reconnection is needed 449 or if connection has been lost and a reconnection is needed
446 """ 450 """
447 if state: 451 if state:
448 # we are resynchronising 452 if self.AUTO_RESYNC:
449 for w in self.widgets: 453 # we are resynchronising all widgets
450 try: 454 for w in self.widgets:
451 resync = w.resync 455 try:
452 except AttributeError: 456 resync = w.resync
453 pass 457 except AttributeError:
454 else: 458 pass
455 resync() 459 else:
460 resync()
456 self._sync = state 461 self._sync = state
457 else: 462 else:
458 self._sync = state 463 self._sync = state
459 # we've lost synchronisation 464 # we've lost synchronisation, all widgets must be notified
465 # note: this is always called independently of AUTO_RESYNC
460 for w in self.widgets: 466 for w in self.widgets:
461 try: 467 try:
462 w.sync = False 468 w.sync = False
463 except AttributeError: 469 except AttributeError:
464 pass 470 pass