17
votes

Will signals automatically disconnect, when target object is destroyed? Without recording the signal id from g_signal_connect(), can I remove that signal?

3

3 Answers

17
votes

If you didn't save the signal handler ID, you can search for it using g_signal_handler_find() and disconnect it the usual way, or disconnect any signals that match certain criteria with g_signal_handlers_disconnect_matched() or g_signal_handlers_disconnect_by_func().

9
votes

Of course when the target object is destroyed, the signals connected to it are removed (otherwise there would be a massive memory leak, but read the warning on g_signal_connect_object). However, to call g_signal_handler_disconnect you need the handler id given by g_signal_connectand friends.

1
votes

You can use the *handler_block_by_func* and *handler_unblock_by_func* methods.

Example (PyGTK):

def on_treeview_fixedexpenses_cursor_changed(self, widget):
    self.checkbutton_fixedexpensetax.handler_block_by_func(self.on_checkbutton_fixedexpensetax_toggled)
    self.updateCurrentFixedExpense()
    self.checkbutton_fixedexpensetax.handler_unblock_by_func(self.on_checkbutton_fixedexpensetax_toggled)

Source: http://www.pygtk.org/docs/pygobject/class-gobject.html