Home > Archive > PerlTk > December 2006 > problem with progressbar
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
problem with progressbar
|
|
|
| Hi All,
I am using progress bar in my application.
But I am getting a problem.
So, I need your help.
Here is my code. Please run the program to see the problem.
use Tk;
use Tk::ProgressBar;
$mw = MainWindow->new;
$mw->geometry( '250x150' );
$mw->resizable( 1, 0 );
initProgressBar();
my $k = 0;
for($k = 0; $k<5; $k++){
showProgressBar();
my $i = 0;
for( $i = 0; $i < 10000; $i++){
updateProgressBarPercentage($i/100);
}
withdrawProgressBar();
}
Mainloop;
sub initProgressBar{
$progbarw = $mw->Toplevel(-title => "Progress Indicator");
$progbarw->withdraw();
$progbarw->transient($mw);
$progbarw->resizable(0,0);
my $frame = $progbarw->Frame()->pack(-fill => 'both', -expand =>
'1', -padx => 10, -pady => 10);
$frame->Label(-textvariable =>\$progressBarLabel, -anchor =>
'w')->pack(-side=>'top', -fill =>'x', -expand=> '1', -pady => 5);
$progbar = $frame->ProgressBar( -width =>20, -blocks=> 1)->pack(
-fill=> 'x');
$progbarw->protocol( 'WM_DELETE_WINDOW' => \&withdrawProgressBar );
my $width = 350;
my $height = 65;
my $mw_geom = $mw->geometry();
$mw_geom =~ /(\d+)x(\d+)\+(-?\d+)\+(-?\d+)/;
my $mw_width = $1;
my $mw_height = $2;
my $mw_x = $3;
my $mw_y = $4;
my $x_cord = int($mw_x + $mw_width/2 - $width/2);
my $y_cord = int($mw_y + $mw_height/2 - $height/2);
$progbarw->geometry($width."x".$height."+$x_cord+$y_cord");
}
sub updateProgressBarLabel{
$progressBarLabel = shift;
$progbar->value(0);
$progbarw->update();
}
sub showProgressBar{
if( !$enableNomDecompile ){
$progbarw->deiconify();
}
$progbarw->raise($mw);
if ($mw->viewable()) {
$progbarw->grab;
}
}
sub withdrawProgressBar{
$progbarw->grabRelease;
$progbarw->withdraw;
}
sub updateProgressBarPercentage{
my $progress= shift;
$progbar->value($progress);
$progbarw->update();
}
The problem is here:
When you minimize the main window, the progress bar also get
minimized with it.
But after some time the next progress bar suddenly appears in
front of the console, though the main window is minimized.
The behavior should be something like this...
a) If the main window is minimized, no progress bar
should appear. The progress bar should update it's percentage
internally.
b) If the main window is maximized, the progress bar
should also appear with the latest percentage.
Is there any way to do it?????
Please replay.
Thanks,
Joy
| |
| zentara 2006-12-21, 7:02 pm |
| On 20 Dec 2006 23:51:33 -0800, "Joy" <joycseju@gmail.com> wrote:
>Hi All,
> I am using progress bar in my application.
> But I am getting a problem.
> So, I need your help.
>Here is my code. Please run the program to see the problem.
.....
.......
>The problem is here:
> When you minimize the main window, the progress bar also get
>minimized with it.
> But after some time the next progress bar suddenly appears in
>front of the console, though the main window is minimized.
> The behavior should be something like this...
> a) If the main window is minimized, no progress bar
>should appear. The progress bar should update it's percentage
>internally.
> b) If the main window is maximized, the progress bar
>should also appear with the latest percentage.
>Is there any way to do it?????
>Please replay.
>Thanks,
>Joy
Hi, I don't know why you are making it so complicated. You have
alot of grabs, interlocking sub calls, etc, which I don't understand the
reason for. Plus you left out the $enableNomDecompile and
$progressBarLabel stuff.
But, without rewriting your code, to my way, :-), I've modified it
to work. I would do it a bit differently myself, but we all have
our own styles and ways of viewing a problem.
The main change is I waited until the mainwindow is visible, to
start the progressbar, then allow the progressbar to show
only if $mw->is_mapped.
This does what you want, but I havn't really tested everything.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::ProgressBar;
my $mw = MainWindow->new;
$mw->geometry( '250x150' );
$mw->resizable( 1, 0 );
my $progbar;
my $progbarw;
$mw->waitVisibility;
initProgressBar();
run_progress();
MainLoop;
sub initProgressBar{
$progbarw = $mw->Toplevel(-title => "Progress Indicator");
$progbarw->withdraw();
$progbarw->transient($mw);
$progbarw->resizable(0,0);
my $frame = $progbarw->Frame()->pack(-fill => 'both', -expand =>'1',
-padx => 10, -pady => 10);
#$frame->Label(-textvariable =>\$progressBarLabel, -anchor
=>'w')->pack(-side=>'top', -fill =>'x', -expand=> '1', -pady => 5);
$progbar = $frame->ProgressBar( -width =>20, -blocks=>
1)->pack(-fill=> 'x');
$progbarw->protocol( 'WM_DELETE_WINDOW' => \&withdrawProgressBar );
my $width = 350;
my $height = 65;
my $mw_geom = $mw->geometry();
$mw_geom =~ /(\d+)x(\d+)\+(-?\d+)\+(-?\d+)/;
my $mw_width = $1;
my $mw_height = $2;
my $mw_x = $3;
my $mw_y = $4;
my $x_cord = int($mw_x + $mw_width/2 - $width/2);
my $y_cord = int($mw_y + $mw_height/2 - $height/2);
$progbarw->geometry($width."x".$height.'+30+30');
}
sub run_progress{
my $k = 0;
for($k = 0; $k<5; $k++){
showProgressBar() if ($mw->ismapped);
my $i = 0;
for( $i = 0; $i < 10000; $i++){
updateProgressBarPercentage($i/100);
select(undef,undef,undef,.001);
}
withdrawProgressBar();
}
}
sub updateProgressBarLabel{
# $progressBarLabel = shift;
$progbar->value(0);
$progbarw->update();
}
sub showProgressBar{
# if( !$enableNomDecompile ){
$progbarw->deiconify();
# }
$progbarw->raise($mw);
if ($mw->viewable()) {
$progbarw->grab;
}
}
sub withdrawProgressBar{
$progbarw->grabRelease;
$progbarw->withdraw;
}
sub updateProgressBarPercentage{
my $progress= shift;
$progbar->value($progress);
$progbarw->update();
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
|
|
|
|
|