changeset 430:edb240ff7936

core (menu): avoid crash when removing SideMenu from parent if it has already been removed
author Goffi <goffi@goffi.org>
date Sun, 01 Mar 2020 22:11:25 +0100
parents cebf657d78ef
children f3c5e3caa170
files cagou/core/menu.py
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/menu.py	Sun Mar 01 22:11:25 2020 +0100
+++ b/cagou/core/menu.py	Sun Mar 01 22:11:25 2020 +0100
@@ -128,12 +128,18 @@
         self._set_anim_kw(kw, self.size_hint_open, self.size_open)
         Animation(**kw).start(self)
 
+    def _removeFromParent(self, anim, menu):
+        # self.parent can already be None if the widget has been removed by a callback
+        # before the animation started.
+        if self.parent is not None:
+            self.parent.remove_widget(self)
+
     def hide(self):
         Window.unbind(on_keyboard=self.key_input)
         kw = {'d': 0.2}
         self._set_anim_kw(kw, self.size_hint_close, self.size_close)
         anim = Animation(**kw)
-        anim.bind(on_complete=lambda anim, menu: self.parent.remove_widget(self))
+        anim.bind(on_complete=self._removeFromParent)
         anim.start(self)
         if self.callback_on_close:
             self.do_callback()