Mercurial > libervia-backend
comparison sat_frontends/quick_frontend/quick_app.py @ 2845:42380a4f6433
quick frontend (app): new synchronisation mechanism:
on some frontend (notably on mobiles) frontend can be paused and lose synchronisation with backend, this can also happen if backend restart a connexion without resuming using stream management. To manage that, QuickApp now has a sync attribute which is True when the backend is in sync with frontend.
When synchronisation has been lost and is possible again, all widget will have their "resync" method called, which can be used to do necessary calls to update the status.
It's the responsability of each widget to then reset the "sync" attribute, once everything has been resynchronised.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 09 Mar 2019 16:33:31 +0100 |
parents | 649cb3fd7711 |
children | 58ea675d0f05 |
comparison
equal
deleted
inserted
replaced
2844:fa1cc09df195 | 2845:42380a4f6433 |
---|---|
327 self._notif_id = 0 | 327 self._notif_id = 0 |
328 self._notifications = OrderedDict() | 328 self._notifications = OrderedDict() |
329 self.features = None | 329 self.features = None |
330 self.ns_map = {} # map of short name to namespaces | 330 self.ns_map = {} # map of short name to namespaces |
331 self.encryption_plugins = [] | 331 self.encryption_plugins = [] |
332 self._sync = True # state of synchronisation with backend | |
332 | 333 |
333 def connectBridge(self): | 334 def connectBridge(self): |
334 self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb) | 335 self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb) |
335 | 336 |
336 def _namespacesGetCb(self, ns_map): | 337 def _namespacesGetCb(self, ns_map): |
422 @return (iter[object]): iterable on visible widgets | 423 @return (iter[object]): iterable on visible widgets |
423 """ | 424 """ |
424 for w in self.visisble_widgets: | 425 for w in self.visisble_widgets: |
425 if isinstance(w, quick_widgets.QuickWidget): | 426 if isinstance(w, quick_widgets.QuickWidget): |
426 return w | 427 return w |
428 | |
429 # backend state management | |
430 | |
431 @property | |
432 def sync(self): | |
433 """Get synchronization flag | |
434 | |
435 True if this frontend is synchronised with backend | |
436 """ | |
437 return self._sync | |
438 | |
439 @sync.setter | |
440 def sync(self, state): | |
441 """Called when backend is desynchronised or resynchronising | |
442 | |
443 @param state(bool): True: if the backend is resynchronising | |
444 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 | |
446 """ | |
447 if state: | |
448 # we are resynchronising | |
449 for w in self.widgets: | |
450 try: | |
451 resync = w.resync | |
452 except AttributeError: | |
453 pass | |
454 else: | |
455 resync() | |
456 self._sync = state | |
457 else: | |
458 self._sync = state | |
459 # we've lost synchronisation | |
460 for w in self.widgets: | |
461 try: | |
462 w.sync = False | |
463 except AttributeError: | |
464 pass | |
427 | 465 |
428 def registerSignal( | 466 def registerSignal( |
429 self, function_name, handler=None, iface="core", with_profile=True | 467 self, function_name, handler=None, iface="core", with_profile=True |
430 ): | 468 ): |
431 """Register a handler for a signal | 469 """Register a handler for a signal |