note 626 added to gtk.gtkprogressbar.constructor.php
| From: | fsockopen dot AT dot yahoo dot it at ez1 dot php dot net | Date: | Tue, 28 Mar 2006 22:03:53 +0000 |
| Subject: | note 626 added to gtk.gtkprogressbar.constructor.php | ||
| Groups: | php.gtk.webmaster | ||
| Request: | Send a blank email to php-gtk-webmaster+get-2953@lists.php.net to get a copy of this message | ||
Hi,
I' ve used this system and it woks ...
but I would like to know how can I obtain the same using:
while(gtk::event_pending()) gtk::main_iteration();
in GTK 1.0.1 ?
This script is an example I've done grabbing code around ... it' read 1K each second from
__FILE__ and when stop_reading() is called output the bytes readed.
<?php
/* $Id: progressbar.php,v 1.9 2006/03/28 00:00:00 fmk Exp $ */
if (!class_exists('gtk')) {
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
dl('php_gtk.dll');
else
dl('php_gtk.so');
}
/*
* Called when delete-event happens. Returns false to indicate that the event
* should proceed.
*/
function delete_event()
{
return false;
}
function do_anything()
{
return true;
}
function stop_reading()
{
global $file_content, $fp, $btn_stop, $tid;
$btn_stop->set_sensitive(false);
if(is_resource($fp)) fclose($fp);
gtk::timeout_remove($tid);
printf("file content:\n%s", $file_content);
}
function start_read()
{
global $window_progress, $fp;
reset_values();
$window_progress->show_all();
$fp = fopen(__FILE__, 'r');
read_bytes(1024);
}
function read_bytes($bytes)
{
global $progressbar, $fp, $file_content, $tid;
if(!feof($fp)){
$file_content .= fread($fp,$bytes);
$readed = strlen($file_content);
$total = filesize(__FILE__);
$perc = strlen($file_content)*100/$total;
// print "\n\nreaded ".$readed." of ".$total." $perc%\n";
$progressbar->set_percentage($perc/100);
/* Give back the control to the interface for updates and re-call read_bytes($bytes) after 1
second */
$tid = gtk::timeout_add(1000,'read_bytes',$bytes);
}else stop_reading();
}
function reset_values()
{
global $progressbar, $fp, $file_content, $tid;
$fp = null;
$file_content = '';
$tid = null;
$progressbar->set_percentage(1);
}
/* file handler */
$fp = null;
/* file content */
$file_content = '';
/* timeout handler id */
$tid = null;
$window_progress = &new GtkWindow();
$window_progress->set_uposition(200, 250);
$window_progress->set_policy(false, false, true);
$window_progress->connect_object('destroy', 'do_anything');
$window_progress->connect_object('delete_event', 'do_anything');
/* These adjustment settings are on the wild side for demo purposes */
$adjustment = &new GtkAdjustment(0, 0, 100, 1, 1, 1);
$value = $adjustment->value;
$progressbar = &new GtkProgressBar($adjustment);
$progressbar->set_show_text(true);
$progressbar->set_text_alignment(0.02, 1.0);
$progressbar->set_format_string("%v%% complete");
$progressbar->set_usize(gdk::screen_width()/2, 30);
$box = &new GtkVBox(false, 10);
$box->set_border_width(10);
$btn_stop = &new GtkButton('Stop');
$btn_stop->connect_object('clicked', 'stop_reading');
$box->pack_start($progressbar, false);
$box->pack_start($btn_stop, false);
$window_progress->add($box);
/*
* Create a new top-level window and connect the signals to the appropriate
* functions. Note that all constructors must be assigned by reference.
*/
$window = &new GtkWindow();
$window->connect_object('destroy', array('gtk', 'main_quit'));
$window->connect('delete-event', 'delete_event');
/*
* Create a button and connect its 'clicked' signal to destroy() function.
*/
$button = &new GtkButton('Close');
$button->connect_object('clicked', array('gtk', 'main_quit'));
/*
* Create a vertical layout box.
*/
$box = &new GtkVBox(false, 10);
$box->set_border_width(10);
/*
* Create a button widget to start
*/
$btn_start = &new GtkButton('Start Read');
$btn_start->connect_object('clicked', 'start_read');
/*
* Add buttons to the vertical layout box.
*/
$box->pack_start($btn_start, false);
$box->pack_start($button, false);
/*
* Add layout box to the window, set window attributes and show everything.
*/
$window->add($box);
$window->set_title('Progress example!');
$window->set_name('MainWindow');
$window->set_usize(150, 200);
$window->show_all();
/* Run the main loop. */
Gtk::main();
?>
http://gtk.php.net:80/manual1/en/gtk.gtkprogressbar.constructor.php