In GTK+ version 2.0, the signal system has been moved from GTK to GLib. We won't go into details about the extensions which the GLib 2.0 signal system has relative to the GTK+ 1.2 signal system. The differences should not be apparent to PyGTK users.
Before we look in detail at helloworld.st, we'll
discuss signals and callbacks. GTK+ is an event driven toolkit, which means
it will sleep in GTK.Gtk main until an event occurs and
control is passed to the appropriate function.
This passing of control is done using the idea of "signals". (Note that these signals are not the same as the Unix system signals, and are not implemented using them, although the terminology is almost identical.) When an event occurs, such as the press of a mouse button, the appropriate signal will be "emitted" by the widget that was pressed. This is how GTK+ does most of its useful work. There are signals that all widgets inherit, such as "destroy", and there are signals that are widget specific, such as "toggled" on a toggle button.
To make a button perform an action, we set up a signal handler
to catch these signals and call the appropriate function. This is done by
using a GTK.GtkWidget (from the
GTK.GObject class) method such as:
handler_id = object connectSignal: aString to: anObject selector: aSelector userData: func_data
where object is the GtkWidget instance
which will be emitting the signal, and the first argument
name is a string containing the name of the signal you
wish to catch. The second and third arguments, anObject, aSelector,are the
message you wish to be sended on the object, anObject, when it is caught, and the fourth,
func_data, the data you wish to pass to this function.
The method returns a handler_id that can be used
to disconnect or block the handler.