changeset 2043:f3940f6a3222

quick frontend (widgets): a deletion with onDelete can now be cancelled if onDelete return False
author Goffi <goffi@goffi.org>
date Mon, 22 Aug 2016 20:56:51 +0200
parents 2e948c228643
children 4de202bdde05
files frontends/src/quick_frontend/quick_widgets.py
diffstat 1 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_widgets.py	Sun Aug 21 20:39:43 2016 +0200
+++ b/frontends/src/quick_frontend/quick_widgets.py	Mon Aug 22 20:56:51 2016 +0200
@@ -253,9 +253,14 @@
     def deleteWidget(self, widget_to_delete):
         """Delete a widget
 
+        this method must be called by frontends when a widget is deleted
         widget's onDelete method will be called before deletion
         """
-        widget_to_delete.onDelete()
+        if widget_to_delete.onDelete() == False:
+            return
+
+        if self.host.selected_widget == widget_to_delete:
+            self.host.selected_widget = None
 
         for widget_map in self._widgets.itervalues():
             to_delete = set()
@@ -335,8 +340,11 @@
         return unicode(target) # by defaut, there is one hash for one target
 
     def onDelete(self):
-        """Called when a widget is deleted"""
-        log.debug(u"deleting widget {}".format(self)) # Must be implemented by frontends
-        if self.host.selected_widget == self:
-            self.host.selected_widget = None
+        """Called when a widget is being deleted
 
+        @return (boot, None): False to cancel deletion
+            all other value continue deletion
+        """
+        log.debug(u"widget {} deleted".format(self))
+        return True
+