comparison 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
comparison
equal deleted inserted replaced
2850:272dc905ff20 2851:7764383a968c
332 """ 332 """
333 self.host = host 333 self.host = host
334 self.targets = set() 334 self.targets = set()
335 self.addTarget(target) 335 self.addTarget(target)
336 self.profiles = set() 336 self.profiles = set()
337 self._sync = True
337 if isinstance(profiles, basestring): 338 if isinstance(profiles, basestring):
338 self.addProfile(profiles) 339 self.addProfile(profiles)
339 elif profiles is None: 340 elif profiles is None:
340 if not self.PROFILES_ALLOW_NONE: 341 if not self.PROFILES_ALLOW_NONE:
341 raise ValueError("profiles can't have a value of None") 342 raise ValueError("profiles can't have a value of None")
352 and not self.PROFILES_MULTIPLE 353 and not self.PROFILES_MULTIPLE
353 and not self.PROFILES_ALLOW_NONE 354 and not self.PROFILES_ALLOW_NONE
354 ) 355 )
355 return list(self.profiles)[0] 356 return list(self.profiles)[0]
356 357
358 # synchronisation state
359
360 @property
361 def sync(self):
362 return self._sync
363
364 @sync.setter
365 def sync(self, state):
366 """state of synchronisation with backend
367
368 @param state(bool): True when backend is synchronised
369 False is set by core
370 True must be set by the widget when resynchronisation is finished
371 """
372 self._sync = state
373
374 def resync(self):
375 """Method called when backend can be resynchronized
376
377 The widget has to set self.sync itself when the synchronisation if finished
378 """
379 pass
380
381 # target/profile
382
357 def addTarget(self, target): 383 def addTarget(self, target):
358 """Add a target if it doesn't already exists 384 """Add a target if it doesn't already exists
359 385
360 @param target: target to add 386 @param target: target to add
361 """ 387 """
367 @param profile: profile to add 393 @param profile: profile to add
368 """ 394 """
369 if self.profiles and not self.PROFILES_MULTIPLE: 395 if self.profiles and not self.PROFILES_MULTIPLE:
370 raise ValueError("multiple profiles are not allowed") 396 raise ValueError("multiple profiles are not allowed")
371 self.profiles.add(profile) 397 self.profiles.add(profile)
398
399 # widget identitication
372 400
373 @staticmethod 401 @staticmethod
374 def getWidgetHash(target, profiles): 402 def getWidgetHash(target, profiles):
375 """Return the hash associated with this target for this widget class 403 """Return the hash associated with this target for this widget class
376 404
384 @param profiles: profile(s) associated to target, see __init__ docstring 412 @param profiles: profile(s) associated to target, see __init__ docstring
385 @return: a hash (can correspond to one or many targets or profiles, depending of widget class) 413 @return: a hash (can correspond to one or many targets or profiles, depending of widget class)
386 """ 414 """
387 return unicode(target) # by defaut, there is one hash for one target 415 return unicode(target) # by defaut, there is one hash for one target
388 416
417 # widget life events
418
389 def onDelete(self, *args, **kwargs): 419 def onDelete(self, *args, **kwargs):
390 """Called when a widget is being deleted 420 """Called when a widget is being deleted
391 421
392 @return (boot, None): False to cancel deletion 422 @return (boot, None): False to cancel deletion
393 all other value continue deletion 423 all other value continue deletion