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.
This commit is contained in:
parent
060c985aba
commit
4c8f108192
1 changed files with 80 additions and 2 deletions
|
|
@ -334,6 +334,7 @@ class QuickWidget(object):
|
|||
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 @@ class QuickWidget(object):
|
|||
)
|
||||
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 @@ class QuickWidget(object):
|
|||
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 @@ class QuickWidget(object):
|
|||
"""
|
||||
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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue