Call Function Within Class Using Gtk::timeout_add();

Calling a function on a repetitive basis is simple enough using something like:
Gtk::timeout_add(200, 'subtract'); //call subtract() 5 times per second

However, how would I call subtract() if it is within a class? Example:

Timer class : simplifying gtk::timeout_add

The Timer class simplifies the use of delays between user actions, without freezing the UI.

Simulating wait loops

How to use a loop, for you might want to make an IRC client :)

I had trouble finding this out, so here it is. If you want to manage a network connection (i.e. an IRC connection) you need a while (1) {} loop.

This cannot be done in PHP-GTK, because of the gtk::main() function. So, there is the gtk::timeout_add($time, $function) that executes a function every $time milliseconds. This solves our problem.


Your function must return TRUE else it will not be called again. Return FALSE to cancel the timeout.

Syndicate content