[ruby-gnome2-doc-cvs] [Hiki] update - tut-gtk2-signals-callbacks

Back to archive index

ruby-****@lists***** ruby-****@lists*****
2003年 8月 10日 (日) 00:37:07 JST


-------------------------
REMOTE_ADDR = 217.117.37.226
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/?tut-gtk2-signals-callbacks
-------------------------

-------------------------
= Mechanism of signals and callbacks

Before looking at the "Hello World" program in details, we should study a bit how GTK handles signals and 
callbacks.

In the same way as your system delivers a signal to processes upon shutdown
((-Note that GTK signals are not related in any way with UNIX signals.  The GTK toolkit has been conceived 
to be independant of the underlying system. -)),  GTK sends a signal to the main loop (Gtk.main) when a 
special event occured.  The main loop will therefore call back the appropriate function of the widget.

Until a signal is received, the main loop will sleep.

In order to tell a GTK widget that it has to catch a specific signal, and then execute appropriate code,
we need to set a signal handler.

This can be done with the GLib::Instantiatable#signal_connect method, which is part of the Ruby/GLib library 
(do not forget that GTK is built on GLib):

  GLib::Instantiatable#signal_connect("signal name") do
      # Code to execute when "signal name" has been catched.
  end

GLib::Instantiatable#signal_connect needs 2 things:
* the name of the signal that the widget should catch; 
* a block code that will be executed upon reception of the given signal.

The block code can take an optional parameter as follows:

  GLib::Instantiatable#signal_connect("signal name") do |w|
      # ...
  end

The widget which issues the signal will be therefore substituted by the parameter w.




ruby-gnome2-cvs メーリングリストの案内
Back to archive index