changeset 34:02acbb297a61

handler, widget: deleteWidget is now properly called when a QuickWidget is deleted
author Goffi <goffi@goffi.org>
date Mon, 22 Aug 2016 20:58:12 +0200
parents c21d1be2e54c
children 20b04c58868f
files src/cagou/core/cagou_main.py src/cagou/core/widgets_handler.py
diffstat 2 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/cagou/core/cagou_main.py	Sun Aug 21 21:41:52 2016 +0200
+++ b/src/cagou/core/cagou_main.py	Mon Aug 22 20:58:12 2016 +0200
@@ -25,6 +25,7 @@
 from sat.core import log as logging
 log = logging.getLogger(__name__)
 from sat_frontends.quick_frontend.quick_app import QuickApp
+from sat_frontends.quick_frontend import quick_widgets
 from sat_frontends.bridge.DBus import DBusBridgeFrontend
 import kivy
 kivy.require('1.9.1')
@@ -326,6 +327,8 @@
             parent = to_change.parent
             idx = parent.children.index(to_change)
             parent.remove_widget(to_change)
+            if isinstance(to_change, quick_widgets.QuickWidget):
+                self.widgets.deleteWidget(to_change)
             parent.add_widget(new, index=idx)
 
     ## misc ##
--- a/src/cagou/core/widgets_handler.py	Sun Aug 21 21:41:52 2016 +0200
+++ b/src/cagou/core/widgets_handler.py	Mon Aug 22 20:58:12 2016 +0200
@@ -20,6 +20,7 @@
 
 from sat.core import log as logging
 log = logging.getLogger(__name__)
+from sat_frontends.quick_frontend import quick_widgets
 from kivy.uix.boxlayout import BoxLayout
 from kivy.uix.button import Button
 from kivy import properties
@@ -88,9 +89,11 @@
     def removeWidget(self, vertical):
         if vertical and self.vert_wid is not None:
             self.remove_widget(self.vert_wid)
+            self.vert_wid.onDelete()
             self.vert_wid = None
         elif self.hor_wid is not None:
             self.blh.remove_widget(self.hor_wid)
+            self.hor_wid.onDelete()
             self.hor_wid = None
 
     def setWidgetSize(self, vertical, size):
@@ -104,3 +107,9 @@
                 self.hor_wid = WidgetsHandler(self.default_widget, size_hint=(None, 1))
                 self.blh.add_widget(self.hor_wid, len(self.blh.children))
             self.hor_wid.width=size
+
+    def onDelete(self):
+        # when this handler is deleted, we need to delete the holded CagouWidget
+        cagou_widget = self.children[0].children[0].children[0]
+        if isinstance(cagou_widget, quick_widgets.QuickWidget):
+            G.host.widgets.deleteWidget(cagou_widget)