tags:

views:

19

answers:

1

Problem: Widget 'A' is a toplevel window that is displayed after a button click in MainWindow 'B'. How do I assign a handler to handle the signal sent back after the 'X' along the window border of Widget 'A' is clicked (see below for current implementation)?

def on_mainWindow_B_button_clicked(self, widget):
     self.widget_a.show()

def on_widget_a_destroy(self, widget): #this is the handler I have right now yet after it's called and widget.a closes and 'on_mainWindow_B_button_clicked' is called for the second time none of widget.a's children appear in the new window
     widget.hide()
+1  A: 

The handler for the delete_event signal must return True in order to stop the Window being permanently destroyed on closing.

    self.widget_a.connect('delete_event', self.on_widget_a_delete)

def on_widget_a_delete(self, widget, event):
    widget.hide()
    # do something
    return True

If you only want to have the window hide, there's a builtin shortcut you can use:

self.widget_a.connect('delete_event', self.widget_a.hide_on_delete)
bobince
Does the event parameter have to be present if a return value is specified?
Drew
An event argument will always be passed, but you can of course ignore it; typically you signify that by assigning it to the name `_`.
bobince