一段 GTK+ 进程条展示的代码

<?
/*
Progressbar Example for Joe

Markus Fischer <[email protected]>
*/

dl'php_gtk.' . (strstrPHP_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_add500'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$value0.0100.01.05.05.0);

$w = &new GtkWindow;
$w->set_title'Progressbar test');
$w->set_default_size400100);
$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_width20);
$fr->add$bar);

$but = &new GtkButton'Start / Stop');
$but->connect'clicked''start_stop_counter');

$v = &new GtkVBox;
$v->pack_start$butfalsefalse);
$v->pack_end$frtruetrue);
$w->add$v);

$w->show_all();

Gtk::main();
?>