[ruby-gnome2-doc-cvs] [Hiki] update - tut-gtk-signals

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2004年 4月 3日 (土) 07:06:04 JST


-------------------------
REMOTE_ADDR = 200.216.151.125
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/en/?tut-gtk-signals
-------------------------
+ {{link "tut-gtk-helloworld", "tut-gtk-intro", "tut-gtk", "tut-gtk-events"}}
  = 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.





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