#!/usr/bin/perl -w use Gtk; use strict; set_locale Gtk; init Gtk; my $true = 1; my $false = 0; my $command; my $site; my $dir; my $file; my $value; my $signal; my $window; my $button; my $vbox; my $label; my $adj; my $pbar; $window = new Gtk::Window( 'toplevel' ); $signal = $window->signal_connect( 'delete_event', sub { Gtk->exit( 0 ); } ); $window->border_width( 15 ); $vbox = new Gtk::VBox( $false, 0 ); $window->add( $vbox ); $label = new Gtk::Label( "Downloading Gtk-Perl Tutorial" ); $vbox->pack_start( $label, $false, $false, 10 ); $label->show(); $adj = new Gtk::Adjustment( 0, 1, 100, 0, 0, 0 ); $pbar = new_with_adjustment Gtk::ProgressBar( $adj ); $vbox->pack_start( $pbar, $false, $false, 10 ); $pbar->set_format_string( "%p%%" ); $pbar->set_show_text( 1 ); $pbar->set_value( 0 ); $pbar->show(); $vbox->show(); Gtk->main_iteration while ( Gtk->events_pending ); $window->show(); $command = "wget --dot-style=micro"; $site = "http://personal.riverusers.com"; $dir = "/~swilhelm/download/"; $file = "gtkperl-tutorial.tar.gz"; open TMP, "$command $site$dir$file 2>&1 |"; while ( $value = ) { $value =~ s/^.*\[//g; $value =~ s/ //g; $value =~ s/\%\]//g; chomp $value; $pbar->set_value( ++$value ) if ( $value =~ /^[0-9]+$/ ); Gtk->main_iteration while ( Gtk->events_pending ); } close TMP; $vbox->remove( $pbar ); $label->set_text( "Download Complete" ); $button = new Gtk::Button( "Close" ); $button->signal_connect( 'clicked', sub { Gtk->exit( 0 ); } ); $vbox->pack_start( $button, $false, $false, 0 ); $button->show(); main Gtk; exit( 0 ); # END EXAMPLE PROGRAM