Please refer to the example:
Sample Code 68: How to display progress bar while processing long task - Part 2 using_idle_add?
Replace the code in:
| Code: |
function process_task() {
echo "processing subtask $this->subtask_count: ";
for ($i=0; $i<10; ++$i) {
usleep(50000); // sleep for half a second
print ".";
}
print "\n";
++$this->subtask_count;
$percent_complete = $this->subtask_count/$this->max_task_count;
|
with your function clb()
| Code: |
function process_task() {
# note: these are the codes from your function clb()
# but you need you have to change the code below
global $lb1;
$abc = file_get_contents('http://www.livescore.com/default.dll
/Game?comp=norway1&game=232197');
$regex = "'Stromsgodset \[(.*)\] Ham Kam'";
preg_match($regex,$abc,$out);
$lb1->set_text($out[0]);
++$this->subtask_count;
$percent_complete = $this->subtask_count/$this->max_task_count;
|
Note that you need to change the code of your original function clb(). I suppose your file "http://www.livescore.com/default.dll/Game" is huge, that's why you want to have a progress bar. If this is the case, then you need to change file_get_contents() and use fopen() with fread() instead. Read in chunks of, say, 4096 bytes. For each iteration, you update the progress bar. If you use file_get_contents(), the entire control is passed over to PHP-GTK, and you get no opportunity to update the progress bar.
Just remember that the progress bar needs to be updated manually by you. So the key is to chop up your "big" task into smaller sub-tasks. For each sub-task, update the progress bar incrementally.
If you don't chop up the task (e.g. if you use file_get_contents), you will only see the progress bar updated from 0 to 100% at the end of the long task.
Hope this helps.
Regards,
/kksou