ruby-****@sourc*****
ruby-****@sourc*****
2003年 8月 16日 (土) 04:12:01 JST
------------------------- REMOTE_ADDR = 217.117.54.155 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/?Mechanism+of+signals+and+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" will been catched. end GLib::Instantiatable#signal_connect needs 2 things: * the name of the signal which will be catched; * 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.