GtkProgressBar Constructor

GtkProgressBar ( GtkAdjustment adjustment );

When constructing a progress bar, you need to specify an associated GtkAdjustment which will be used to configure the progress bar's initial value and range.

Ejemplo 33. Setting up a Progress Bar

<?php

dl('php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));

function update_bar() {
  global $progressbar, $value;
  $progressbar->set_percentage($value);
  start_update();
  }

function start_update() {
  global $value;
  if($value <= 1.0) {
    $value += 0.01;
    gtk::timeout_add(200, 'update_bar');
    }
  else gtk::timeout_add(50, array('gtk', 'main_quit'));
  }

$window = &new GtkWindow();
$window->set_uposition(200, 250);
$window->set_policy(false, false, true);
$window->connect_object('destroy', array('gtk', 'main_quit'));

/* These adjustment settings are on the wild side for demo purposes */
$adjustment = &new GtkAdjustment(0.5, 100.0, 200.0, 0.0, 0.0, 0.0);
$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);
$window->add($progressbar);

$window->show_all();

start_update();
gtk::main();

?>
To create a progress bar in activity mode, delete the references to the text string and replace them with
$progressbar->set_activity_mode(true);
and any further methods appropriate to an activity indicator. You will also need to replace
$progressbar->set_percentage($value);
in the update_bar() function with
$progressbar->set_value($value);

Note that a progress bar in activity mode will not be redrawn when the values of the lower and upper bounds in the attached GtkAdjustment have been exceeded.