|
Written by kksou
|
|
Thursday, 17 April 2008 |
|
Objective
Let's begin our understanding of signal handling with the button click example.
Overview
- We "inform" php-gtk that we want to listen to a particular signal with connect(signal, callback_fn).
- And we write the function that will be used to handle this signal. This function is called the callback function or signal handler.
Sample Output

Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?php $window = new GtkWindow(); $window->connect_simple('destroy',array('Gtk','main_quit')); $window->set_size_request(200, 100); $vbox = new GtkVBox(); $window->add($vbox);
$button = new GtkButton('button1'); $hbox = new GtkHBox(); $hbox->pack_start($button, true, false); $vbox->pack_start($hbox, true, false);
$button->connect('clicked', 'on_click'); // note 1
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation
- The first parameter is the signal we want to listen to. In this example, we want to know when the button is clicked. The name of this signal is called 'clicked'. The second parameter is the name of your callback function that will be used to handle the signal. In this example, this is the function
'on_click()'.
- This is the callback function that is used to handle the signal 'clicked', i.e. when the user clicks the button, php-gtk will automatically calls this function that you have written. For this example, we simply echo the string "button clicked" to the command window.
User reviews Average user ratings: 5.0 (from 1 user) Note: You have to be a registered member to leave a comment. Free registration here. |
|
July 23, 2008 11:01am