<?
/*
Progressbar Example for Joe
Markus Fischer <[email protected]>
*/
dl( 'php_gtk.' . (strstr( PHP_OS, 'WIN') ? 'dll' : 'so'));
function update_bar() {
global $bar;
global $value;
$value += 0.1;
if( $value > 1.0)
$value = 0.0;
$bar->update( $value);
return true; // its actually important to return true here, else the function gets only called one time
}
function start_stop_counter() {
global $running;
global $timeout_handle;
if( ! $running) {
$timeout_handle = Gtk::timeout_add( 500, 'update_bar'); // half a second
$running = true;
} else {
Gtk::timeout_remove( $timeout_handle);
$running = false;
}
}
/* global vars we use */
$running = false; // wether the bar (timer) is active or not
$value = 0.0; // current percentage value of the bar
$timeout_handle = 0;// holds the handle for the timeout
$adjustment = &new GtkAdjustment( $value, 0.0, 100.0, 1.0, 5.0, 5.0);
$w = &new GtkWindow;
$w->set_title( 'Progressbar test');
$w->set_default_size( 400, 100);
$w->connect_object( 'delete_event', create_function( '$we_dont_need_this_argument', 'Gtk::main_quit();'));
$bar = &new GtkProgressBar( $adjustment);
$fr = &new GtkFrame( ' Progressbar ');
$fr->set_border_width( 20);
$fr->add( $bar);
$but = &new GtkButton( 'Start / Stop');
$but->connect( 'clicked', 'start_stop_counter');
$v = &new GtkVBox;
$v->pack_start( $but, false, false);
$v->pack_end( $fr, true, true);
$w->add( $v);
$w->show_all();
Gtk::main();
?>
|