On Fri, 13 Dec 2002 09:22:01 +0100, [EMAIL PROTECTED] (Anette
Seiler) wrote:

>Hi,
>
>thanks to all for answering. After discussing it with my colleagues I will 
>do it in a way Peter and zentara suggested.
>
>By the way, the software is intended for librarians who want to download 
>certain metadata-records from the web onto their computer for upgrading and 
>uploading to a library system.

Hi, if you are interested, here is a little frontend GUI to download
files using gtk-perl. You can easily change it to automatically enter
the filename to get.  If you need help doing that, let me know.
This one uses gtk, but tk has similar scripts.

##############################################################
#!/usr/bin/perl -w
use strict;
use Gtk;
use LWP::UserAgent;
set_locale Gtk;
init Gtk;

my $true = 1;
my $false = 0;

my ($window,$button,$vbox,$hbox,$label,$label1,
     $entry,$adj,$pbar,$URL,$filename);

# Create the window.
$window = new Gtk::Window( 'toplevel' );
$window->signal_connect( 'delete_event', sub { Gtk->exit( 0 ); } );
$window->border_width(10);

$vbox = new Gtk::VBox( $false, 0 );
$hbox = new Gtk::HBox($false,0);
$window->add($vbox);

# Label to let the user know what is going on.
$label = new Gtk::Label("--------------------Gtk
downloader--------------------");
$vbox->pack_start( $label, $false, $false, 10 );
$label->show();

# Label to display URL to retreive.
$label1 = new Gtk::Label( "file to retrieve\n" );
$vbox->pack_start( $label1, $false, $false, 10 );
$label1->show();

# Create the Entry 
$entry = new Gtk::Entry(100);
$entry->signal_connect( "activate",\&get_entry,1,2);
$entry->set_text( "Enter" );
$entry->append_text( "Url" );
$entry->select_region( 0, length( $entry->get_text() ) );
$vbox->pack_start( $entry, $true, $true, 0 );
$entry->show();

# Set up the progress bar
$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(1);
$pbar->show();

#Create start button
$button = new Gtk::Button( "Start" );
$button->signal_connect( "clicked", \&get_file);
$hbox->pack_start($button, $true, $false,0);
$button->show();

# Create the close button
$button = new Gtk::Button( "Close" );
$button->signal_connect( 'clicked', sub { Gtk->exit( 0 ); } );
$hbox->pack_start( $button, $true, $false,0);
$button->show();

$vbox->add($hbox);
$hbox->show();
$vbox->show();
$window->show();

main Gtk;
exit( 0 );
################################################################

sub get_file{
get_entry();
my $ua  = LWP::UserAgent->new;
open(IN,">$filename"); 
my $value = 0;
my $expected_length;
my $bytes_received = 0;
my $res = $ua->request(HTTP::Request->new(GET => $URL),
    sub {
        my ( $chunk, $res ) = @_;
        $bytes_received += length($chunk);
        unless ( defined $expected_length ) {
            $expected_length = $res->content_length || 0;
            $label1->set_text( "Getting $filename\n$expected_length
bytes" );
           }if($expected_length){
                  $value= int (100 * $bytes_received / $expected_length)
|| 0;
                   }
        # write to the file
        print IN $chunk;
   
   $pbar->set_value( ++$value ) if ($value =~ /^[0-9]+$/);

 # Run the main loop as long as events are pending
 Gtk->main_iteration while ( Gtk->events_pending );
});
close IN;
# Download is done, inform the user.

if(-s $filename eq 0){
        $label1->set_text( "file contained no data\nCheck URL" );
        unlink $filename;  
  }else{
        $label1->set_text( "$filename saved\n Download Complete" );
        $pbar->set_value(101);
  }

return;
}
sub get_entry{
$URL = $entry->get_text();
$pbar->set_value(0);
$filename = substr("$URL", rindex("$URL", "/" )+1);
$filename =~ s/~//g;
$filename = $filename || $URL;
$filename =~ s/[~\/]//g;
$label1->set_text("$filename\n");
return;
}

######################################################



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to