diff sat_frontends/quick_frontend/quick_widgets.py @ 2851:7764383a968c

quick_frontend (widget, chat): implementation of new sync mechanism, first draft: QuickWidget implement base of sync mechanism with a sync property which can be overriden, and resync method which is called when resynchronisation is needed. When resync is required, chat widget get missing occupant and history elements A new callable argument can be used with historyPrint, when set it is called when history has been fully printed.
author Goffi <goffi@goffi.org>
date Sun, 10 Mar 2019 18:03:11 +0100
parents 42380a4f6433
children e2595c81eb6d
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_widgets.py	Sun Mar 10 18:03:02 2019 +0100
+++ b/sat_frontends/quick_frontend/quick_widgets.py	Sun Mar 10 18:03:11 2019 +0100
@@ -334,6 +334,7 @@
         self.targets = set()
         self.addTarget(target)
         self.profiles = set()
+        self._sync = True
         if isinstance(profiles, basestring):
             self.addProfile(profiles)
         elif profiles is None:
@@ -354,6 +355,31 @@
         )
         return list(self.profiles)[0]
 
+    # synchronisation state
+
+    @property
+    def sync(self):
+        return self._sync
+
+    @sync.setter
+    def sync(self, state):
+        """state of synchronisation with backend
+
+        @param state(bool): True when backend is synchronised
+            False is set by core
+            True must be set by the widget when resynchronisation is finished
+        """
+        self._sync = state
+
+    def resync(self):
+        """Method called when backend can be resynchronized
+
+        The widget has to set self.sync itself when the synchronisation if finished
+        """
+        pass
+
+    # target/profile
+
     def addTarget(self, target):
         """Add a target if it doesn't already exists
 
@@ -370,6 +396,8 @@
             raise ValueError("multiple profiles are not allowed")
         self.profiles.add(profile)
 
+    # widget identitication
+
     @staticmethod
     def getWidgetHash(target, profiles):
         """Return the hash associated with this target for this widget class
@@ -386,6 +414,8 @@
         """
         return unicode(target)  # by defaut, there is one hash for one target
 
+    # widget life events
+
     def onDelete(self, *args, **kwargs):
         """Called when a widget is being deleted