Chapter 3 Signal Handling
Written by kksou   
Sunday, 13 April 2008

What are Signals

Signals are the links between your php-gtk application and the user. Signals allow you to know when the user do something — clicked a button, pressed a key, inserted a character, deleted a row, selected an image, etc. Through signals, you are able to act accordingly based on user's actions.

Connecting Signals

Signals are like the newsletters or news feeds. There are millions of free newsletters and news feeds currently out there on Internet. You only subscribe to the ones you are interested, so that you will not be flooded with too much information.

Same for signals. Take a look at the PHP-GTK manual. There are hundreds of signals listed there. You probably do not need to be informed about all these signals in your application. You register with php-gtk which are the ones you're interested in with the connect() method.

Signal Name

Take a look again at the index of signals in the php-gtk manual. In php-gtk each signal is identified by a unique name. For example,

  • We have seen that the signal that is emitted when the user clicks a button is called 'clicked'.
  • The signal that is emitted when a button is pressed is called 'pressed'.
  • The signal that is emitted when a button is being released is called 'released'.

When you register a signal with connect(), you need to know the name of this signal and specify it as the first argument.

Callback Function

When you register a signal with connect(), you also specify the name of your callback function as the second argument. For example, after you have registered the 'click' signal with $button->connect('clicked', 'on_click')on_click()

Since the callback function is used to handle a signal, you will sometimes see a callback function being referred to as a signal handler.



User reviews

There are no user reviews yet.

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Copyright © 2006-2008. kksou.com. All Rights Reserved