Forum: Ruby-Gnome 2 Question about testing/removing signals after signal_connect()

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0d130f179f85401f248e6ebc2ef8292f?d=identicon&s=25 Eric C. (eric_c)
on 2016-06-13 23:55
Hi:

I'm having a problem with connecting signals.  I need to call
signal_connect several times with the same method.  However, I don't
want it to execute the method several times:

def do_something()
  puts "Hello"
end

def connect
  if button.signals_array.includes?("clicked",do_something)
    button.signal_connect("clicked") {do_something }
  end
end

10.times do
  connect
end

I want it to output:

Hello

only once.


This would work great except that there's no button.signals_array
available in Gtk as far as I can tell.

How can I test a widget to see if a signal is already attached to it?  I
know there's a list of signals that get executed, and connect_signals
adds to that list.  How can I check that list for duplicates?

Thanks!

Eric
This topic is locked and can not be replied to.