Delete event for a FileChooserDialog
i'd like to hide a FileChooserDialog when i delete its window. I can just hide it from the the 'Cancel' Button but when i close it from its window it doen't respond and then it crashes.
The crash happens when i do this, in sequence:
I open it (it works fine)
I try to close it from the window 'X' button: the buttons 'OK' and 'CANCEL' disappear and FileFilter too
- I re-try to close it. Now the window become white: it seems it doesn't respond.
- I re-try to close it. It is closed.
- I try to re-open the FileChooserDialog just closed. It doesn't work anymore and the shell now tells me what it's wrong.
My code is simple:
self.__apri_FileChooserDialog = Gtk.FileChooserDialog(title='', \ parent=None, \ action=Gtk.FileChooserAction.OPEN, \ buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, \ Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) self.__salva_FileChooserDialog.connect("delete-event", self.nascondi) def nascondi(self, widget, args=()): widget.get_window().hide_on_delete()
def nascondi(self, widget, args=()): widget.get_window().hide_on_delete()
For some reason you get the GdkWindow of the dialog widget here, and try to call a method that GdkWindow does not have. That cannot work...
In any case hide_on_delete() is, as far as I know, a bit useless in python (because the number of arguments does not match the signal). Fortunately doing it yourself is not difficult. Try this:
def on_delete_event (widget, event): widget.hide() return True self.__salva_FileChooserDialog.connect("delete-event", on_delete_event)