This code
shows how to use a GtkProgressBar in
"fraction" mode, in which the progress bar advances from
one side to the other.
It also demonstrates how Pango integration allows the text to be automatically ellipsized to fit within a given rectangle : try resizing the window to see what happens with the text.
<?php
if (!class_exists('gtk'))
{
die("Please load the php-gtk2 module in your php.ini\r\n");
}
/**
* This function is the signal handler used to
* increase the fraction in the progress bar by one step
*
* @return bool must signal by fired again next time ?
*/
function stepper ()
{
global $progress;
static $pause = 0;
$pos = $progress->get_fraction()
+ $progress->get_pulse_step();
if ($pos < 1)
{
$progress->set_fraction($pos);
return true;
}
else
{
$progress->set_fraction(1.0);
if ($pause++ > 3)
Gtk::main_quit();
}
return true;
}
/**
* ---- Main code ----
*/
/**
* INIT A NEW PROGRESS BAR OBJECT AND SET PROPERTIES
*/
$progress = new gtkProgressBar();
$progress->set_ellipsize(Pango::ELLIPSIZE_MIDDLE);
$progress->set_pulse_step(0.1);
$progress->set_text("This is a test with a long text,"
. "to demonstrate Pango ellipsing");
/**
* according to Gtk+ docs, this should not be used
* http://developer.gnome.org/doc/API/2.0/gtk/gtk-General.html#id2541129
*
* but g_timeout_add_seconds is not yet in PHP-GTK
* Delay is expressed in milliseconds
*/
Gtk::timeout_add(500, 'stepper');
/******************************************************/
//INIT A NEW WINDOW AND ADD THE PROGRESS WIDGIT
$win = new gtkWindow();
$win->add($progress);
/******************************************************/
/******************************************************/
//SHOW THE WINDOW
$win->show_all();
/******************************************************/
// Main event loop
gtk::main();
?>Additional keywords: progressbar
Poslední komentáře
před 47 týdnů 1 den
před 48 týdnů 18 hod
před 48 týdnů 4 dny
před 51 týdnů 19 hod
před 1 rok 19 týdnů
před 1 rok 23 týdnů
před 1 rok 27 týdnů
před 1 rok 27 týdnů
před 1 rok 27 týdnů
před 1 rok 44 týdnů