Create  Edit  FrontPage  Index  Search  Changes  History  RSS  Login

tips_signals

Investigate Signal behaviors

How do you find signals which you need?

Some representative signals are found in many samples, but others can't find anywhere even GTK+ API documents.

This is the introduction how I find it.

1 Try all signals in the widget which I need

When I want to know the signals behaviors, I write test scripts as below at first.

Try to click the widget, to press the keyboards, to move the widget, then you can investigate which/when signals are emitted.

require 'gtk2'
widget = Gtk::Button.new("click")        #(1)
Gtk::Button.signals(false).each do |v|   #(2)
  p v
  widget.signal_connect(v) do
    p "#{v} is occured."
  end
end
Gtk::Window.new.set_default_size(100, 100).add(widget).show_all
Gtk.main

This is a example which use Gtk::Button. But also you can investigate other Widget/Signals to change (1) and (2).

If you need to know superclass's signals, set true to GLib::MetaInterface.signals.

2 Investigate a signal deeply

Then, you find some signals to investigate deeply, try the script below.

require 'gtk2'
v = "clicked"                            #(1)
widget = Gtk::Button.new("click")        #(2)
widget.signal_connect(v) do
  p "#{v} is occured."
end
Gtk::Window.new.set_default_size(100, 100).add(widget).show_all
Gtk.main

Change (1), (2) as you need.

Last modified:2011/06/11 10:24:01
Keyword(s):
References:[tips]