changeset 355:8b6621cc142c

core (widgets handler): clear widgets when WHWrapper is detached: when WHWrapper is detached from parent, we call clear_widgets to detach children. This avoid CagouWidget.whwrapper to lead to this now unused wrapper (this was causing a bug when testing if a widget is attached and could be re-used, leading to the unnecessary creation of new widgets). Added ignore_missing when removing current_slide from visible widgets, to avoid error logging if wrapper was not active.
author Goffi <goffi@goffi.org>
date Fri, 17 Jan 2020 20:33:43 +0100
parents aa860c10acfc
children 307c2501d8b2
files cagou/core/widgets_handler.py
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/widgets_handler.py	Fri Jan 17 18:44:35 2020 +0100
+++ b/cagou/core/widgets_handler.py	Fri Jan 17 20:33:43 2020 +0100
@@ -87,6 +87,12 @@
                 return wid
         return next(iter(wid_list))
 
+    def on_parent(self, __, new_parent):
+        if new_parent is None:
+            # we detach all children so CagouWidget.whwrapper won't link to this one
+            # anymore
+            self.clear_widgets()
+
     @property
     def _left_wid(self):
         return self._main_wid(self._left_wids)
@@ -351,7 +357,7 @@
     def clear_widgets(self):
         current_slide = self.current_slide
         if current_slide is not None:
-            G.host._removeVisibleWidget(current_slide)
+            G.host._removeVisibleWidget(current_slide, ignore_missing=True)
 
         super().clear_widgets()