comparison frontends/src/quick_frontend/quick_widgets.py @ 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 6353deb1bd73
children 7f5e344938c1
comparison
equal deleted inserted replaced
2042:2e948c228643 2043:f3940f6a3222
251 return widget 251 return widget
252 252
253 def deleteWidget(self, widget_to_delete): 253 def deleteWidget(self, widget_to_delete):
254 """Delete a widget 254 """Delete a widget
255 255
256 this method must be called by frontends when a widget is deleted
256 widget's onDelete method will be called before deletion 257 widget's onDelete method will be called before deletion
257 """ 258 """
258 widget_to_delete.onDelete() 259 if widget_to_delete.onDelete() == False:
260 return
261
262 if self.host.selected_widget == widget_to_delete:
263 self.host.selected_widget = None
259 264
260 for widget_map in self._widgets.itervalues(): 265 for widget_map in self._widgets.itervalues():
261 to_delete = set() 266 to_delete = set()
262 for hash_, widget in widget_map.iteritems(): 267 for hash_, widget in widget_map.iteritems():
263 if widget_to_delete is widget: 268 if widget_to_delete is widget:
333 @return: a hash (can correspond to one or many targets or profiles, depending of widget class) 338 @return: a hash (can correspond to one or many targets or profiles, depending of widget class)
334 """ 339 """
335 return unicode(target) # by defaut, there is one hash for one target 340 return unicode(target) # by defaut, there is one hash for one target
336 341
337 def onDelete(self): 342 def onDelete(self):
338 """Called when a widget is deleted""" 343 """Called when a widget is being deleted
339 log.debug(u"deleting widget {}".format(self)) # Must be implemented by frontends 344
340 if self.host.selected_widget == self: 345 @return (boot, None): False to cancel deletion
341 self.host.selected_widget = None 346 all other value continue deletion
342 347 """
348 log.debug(u"widget {} deleted".format(self))
349 return True
350