Theory of Signals and Callbacks

Before we look in detail at helloworld.rb, we'll discuss signals and callbacks. GTK is an event driven toolkit, which means it will sleep in the main loop until an event occurs and control is passed to the appropriate function.

This passing of control is done using the idea of signals. 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 function such as:

widget.signal_connect('event') { action }
Then { action } will get excecuted every time the widget receives the event 'event'. This is called a callback.