comparison frontends/src/quick_frontend/quick_contact_list.py @ 1939:e68483c5a999

quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
author Goffi <goffi@goffi.org>
date Mon, 18 Apr 2016 18:33:55 +0200
parents 011eff37e21d
children ccfe45302a5c
comparison
equal deleted inserted replaced
1938:011eff37e21d 1939:e68483c5a999
643 if handler is not None: 643 if handler is not None:
644 raise exceptions.InternalError(u"QuickContactListHandler must be instanciated only once") 644 raise exceptions.InternalError(u"QuickContactListHandler must be instanciated only once")
645 handler = self 645 handler = self
646 self._clist = {} # key: profile, value: ProfileContactList 646 self._clist = {} # key: profile, value: ProfileContactList
647 self._widgets = set() 647 self._widgets = set()
648 self._update_locked = False # se to True to ignore updates
648 649
649 def __getitem__(self, profile): 650 def __getitem__(self, profile):
650 """Return ProfileContactList instance for the requested profile""" 651 """Return ProfileContactList instance for the requested profile"""
651 return self._clist[profile] 652 return self._clist[profile]
652 653
855 856
856 def unselect(self, entity): 857 def unselect(self, entity):
857 for contact_list in self._clist.itervalues(): 858 for contact_list in self._clist.itervalues():
858 contact_list.select(entity) 859 contact_list.select(entity)
859 860
861 def lockUpdate(self, locked=True, do_update=True):
862 """Forbid contact list updates
863
864 Used mainly while profiles are plugged, as many updates can occurs, causing
865 an impact on performances
866 @param locked(bool): updates are forbidden if True
867 @param do_update(bool): if True, a full update is done after unlocking
868 if set to False, widget state can be inconsistent, be sure to know
869 what youa re doing!
870 """
871 log.debug(u"Contact lists updates are now {}".format(u"LOCKED" if locked else u"UNLOCKED"))
872 self._update_locked = locked
873 if not locked and do_update:
874 self.update()
875
860 def update(self, entities=None, type_=None, profile=None): 876 def update(self, entities=None, type_=None, profile=None):
861 for widget in self._widgets: 877 if not self._update_locked:
862 widget.update(entities, type_, profile) 878 for widget in self._widgets:
879 widget.update(entities, type_, profile)
863 880
864 881
865 class QuickContactList(QuickWidget): 882 class QuickContactList(QuickWidget):
866 """This class manage the visual representation of contacts""" 883 """This class manage the visual representation of contacts"""
867 SINGLE=False 884 SINGLE=False