comparison cagou/plugins/plugin_wid_chat.py @ 356:307c2501d8b2

chat: keep as many instances of opened chat as there are active WHWrapper, instead of just one: Chat instances can be shown on any WHWrapper, even in all at the same time, so we keep as many instances as active wrapper to avoid unnecessary widget (re)creation
author Goffi <goffi@goffi.org>
date Fri, 17 Jan 2020 20:35:57 +0100
parents aa860c10acfc
children 4d3a0c4f2430
comparison
equal deleted inserted replaced
355:8b6621cc142c 356:307c2501d8b2
765 765
766 def onVisible(self): 766 def onVisible(self):
767 if not self.sync: 767 if not self.sync:
768 self.resync() 768 self.resync()
769 769
770 def onDelete(self): 770 def onDelete(self, **kwargs):
771 # we always keep one widget, so it's available when swiping 771 # we always keep one widget, so it's available when swiping
772 # TODO: delete all widgets when chat is closed 772 # TODO: delete all widgets when chat is closed
773 nb_instances = sum(1 for _ in self.host.widgets.getWidgetInstances(self)) 773 nb_instances = sum(1 for _ in self.host.widgets.getWidgetInstances(self))
774 if nb_instances > 1: 774 # we want to keep at least one instance of Chat by WHWrapper
775 return super(Chat, self).onDelete() 775 nb_to_keep = len(G.host.widgets_handler.children)
776 else: 776 if nb_instances <= nb_to_keep:
777 return False 777 return False
778 778
779 def _history_unlock(self, __): 779 def _history_unlock(self, __):
780 self._history_prepend_lock = False 780 self._history_prepend_lock = False
781 log.debug("history prepend unlocked") 781 log.debug("history prepend unlocked")