PHP-GTK
Thursday, July 24, 2014 
download | documentation | applications | faq | changelog | resources 


search for in the  


previousstock_lookup
timeout_removenext

Last updated: Sun, 12 May 2013
view this page in English

timeout_add

Registers a function to be called periodically. The function will be called repeatedly after interval milliseconds until it returns false (or nothing) at which point the timeout is destroyed and will not be called again.

So to keep the timeout alive, your callback function needs to return true;

Example 13. Using Gtk::timeout_add() to create a simple clock

<?php
//Simple clock using Gtk::timeout_add()
 
//At first, we need a label displaying the time
$lbl = new GtkLabel('Clock');
//Now, call function "onTimeout" every 1 second
// (1 second == 1000 milliseconds)
//Also pass $lbl as parameter so we can
// change it in the function without using
// global variables (bad!)
Gtk::timeout_add(1000, 'onTimeout', $lbl);
 
//our callback function has one parameter,
// the one we defined in Gtk::timeout_add()
function onTimeout($lbl)
{
    //do the things we want to do
    $lbl->set_text(date('H:i:s'));
 
    //at the end, return "true" if the timeout shall
    // be executed again. If you don't return anything
    // or return false, the timeout is stopped.
    return true;
}
 
//standard stuff
$wnd = new GtkWindow();
$wnd->connect_simple('destroy', array('gtk', 'main_quit'));
$wnd->add($lbl);
$wnd->show_all();
Gtk::main();
?>

The integer returned by this method can be used by timeout_remove() to destroy the timeout independent of the return value of the callback.


User Contributed Notes
gtk.method.timeout_add.php
add a note about notes
There are no user contributed notes for this page.


previousstock_lookup
timeout_removenext

Last updated: Sun, 12 May 2013
view this page in English


credits 

PHP  Copyright © 2001-2014 The PHP Group
 All rights reserved.
Last updated: Sun May 12 20:51:01 2013 CEST