daisy
daisy

Reputation: 23591

How to disconnect a signal of Gtk?

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

Upvotes: 19

Views: 14238

Answers (3)

ptomato
ptomato

Reputation: 57940

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().

Upvotes: 18

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_connect and friends.

Upvotes: 10

Jesus
Jesus

Reputation: 26

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

Upvotes: 1

Related Questions