Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disconnect a signal of Gtk?

Tags:

signals

gtk

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

like image 556
daisy Avatar asked Nov 07 '11 13:11

daisy


3 Answers

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

like image 127
ptomato Avatar answered Oct 24 '22 02:10

ptomato


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.

like image 30
Basile Starynkevitch Avatar answered Oct 24 '22 01:10

Basile Starynkevitch


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

like image 1
Jesús González Avatar answered Oct 24 '22 01:10

Jesús González



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!