Gtk2

 view release on metacpan or  search on metacpan

examples/cellrenderer_progress.pl  view on Meta::CPAN

use Glib qw(TRUE FALSE);
use Gtk2 -init;

my $liststore;
my $increasing = TRUE; # direction of progress bar change

use constant {
  COL_PERCENTAGE => 0,
  COL_TEXT       => 1,
  NUM_COLS       => 2,

  STEP           => 0.01,
};


sub increase_progress_timeout {
  my $renderer = shift;
  my $iter = $liststore->get_iter_first; # first and only row

  my $perc = $liststore->get ($iter, COL_PERCENTAGE);

  if ($perc > (1.0 - STEP)  ||  ($perc < STEP && $perc > 0.0) ) {
    $increasing = (!$increasing);
  }

  if ($increasing) {
    $perc += STEP;
  } else {
    $perc -= STEP;
  }

  my $buf = sprintf '%u %%', $perc*100;

  $liststore->set ($iter, COL_PERCENTAGE, $perc, COL_TEXT, $buf);

  return TRUE; # Call again
}


sub create_view_and_model {
  $liststore = Gtk2::ListStore->new (qw(Glib::Double Glib::String));
  my $iter = $liststore->append;
  $liststore->set ($iter, COL_PERCENTAGE, 0.5); # start at 50%

  my $view = Gtk2::TreeView->new ($liststore);

  my $renderer = Gtk2::CellRendererText->new;
  my $col = Gtk2::TreeViewColumn->new;
  $col->pack_start ($renderer, TRUE);
  $col->add_attribute ($renderer, text => COL_TEXT);
  $col->set_title ("Progress");
  $view->append_column ($col);

  $renderer = Mup::CellRendererProgress->new;
  $col = Gtk2::TreeViewColumn->new;
  $col->pack_start ($renderer, TRUE);
  $col->add_attribute ($renderer, percentage => COL_PERCENTAGE);
  $col->set_title ("Progress");
  $view->append_column ($col);

  Glib::Timeout->add (50, \&increase_progress_timeout);

  return $view;
}


my $window = Gtk2::Window->new;
$window->set_default_size (150, 100);
$window->signal_connect (delete_event => sub {Gtk2->main_quit});

my $view = create_view_and_model();

$window->add ($view);

$window->show_all;

Gtk2->main;


 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.089 second using v1.00-cache-1.14-grep-28634ff-cpan-c4b834afec8 )