|
From: Erick B. <er...@je...> - 2001-07-24 14:36:10
|
On Tue, 24 Jul 2001 08:27:17 -0500, Eoi...@de... said:
|
| Does any have the following ...
|
| Idiots Guide to PERL Progressbars
| 3 easy Steps to Progressbars & Perl
| Progressbars by example..
| etc, etc, etc, etc, etc, etc, etc, etc, etc, etc, etc, etc, etc,
| etc,
| etc,
Eoin,
I use this subroutine to create a window that displays when I transfer a
file in an FTP client I made. Obviously you will have to modify some of
the code.
# code #
#===================
sub CreateProgressWin {
#===================
$ProgWin = new Win32::GUI::DialogBox(
-name => "ProgWin",
-text => "Progress Window",
-size => [280, 220],
-pos => [($screen_width/2)-125,
($screen_height/2)-100],# center it
-style =>,
);
$ProgWin->AddLabel(
-name => "ProgLbl",
-text => "Sending",
-pos => [10, 10],
-size => [$ProgWin->ScaleWidth-20, 70],
-foreground => [255, 255, 255],
-background => [0, 0, 0],
);
$ProgWin->AddLabel(
-name => "ProgLblSize",
-text => "0 bytes of 0 bytes",
-pos => [45, 65],
-size => [$ProgWin->ScaleWidth-40, 20],
-foreground => [255, 255, 255],
-background => [0, 0, 0],
);
$ProgWin->AddLabel(
-name => "ProgLblPercent",
-text => "0%",
-pos => [($ProgWin->ScaleWidth/2)-15, 90],
-size => [50, 20],
-foreground => [255, 255, 255],
-background => [0, 0, 0],
);
$ProgWin->AddProgressBar(
-smooth => 1,
-name => "ProgBar",
-pos => [0, $ProgWin->ScaleHeight-25],
-size => [$ProgWin->ScaleWidth, 25],
);
# Abort Button #
$ProgWin->AddButton(
-text => "Abort",
-name => "Abort",
-pos => [($ProgWin->ScaleWidth()/2)-25,
$ProgWin->ScaleHeight()-60],
-tabstop => 1,
-cancel => 1,
-default => 1,
);
$ProgWin->Abort->SetFocus();
}
Then, I initialize my values before the transfer:
# code #
my $track=0;
$ProgWin->ProgLbl->Text("Sending $LocalFile...");
$ProgWin->ProgBar->SetRange(0, 100);
$ProgWin->ProgBar->SetPos(0);
$ProgWin->ProgLblSize->Text("$track bytes of $size bytes sent");
$ProgWin->ProgLblPercent->Text(int($pos)."%");
$ProgWin->Show();
Then, while I read data, I ~SetPos~, although you can do it another way.
# code #
while(1) {
Win32::GUI::DoEvents();
# I'm actually NOT sure if this is needed
last if ($abort_trans);
$ProgWin->ProgLblSize->Text("$track bytes of $size bytes sent");
$percent = $track/$size;
$pos = 100*$percent;
$ProgWin->ProgLblPercent->Text(int($pos)."%");
$ProgWin->ProgBar->SetPos($pos);
Win32::GUI::DoEvents();
# Or this...although, I think it helps
last unless $len = sysread(FILE, $buffer="", $blksize);
$track += $len;
my $wlen;
unless(defined($wlen = $sock->write($buffer,$len)) && $wlen ==
$len) {
$sock->abort;
$ProgWin->Hide();
Msg_Box("Cannot write to remote file $LocalFileName:
$!",48,"Can't Write To File");
close(FILE); ResetTimer();
return undef;
}
}
$ProgWin->Hide();
# Then hide it!
# end of code #
I hope this helps!
regards,
erick
|