Rhodium has asked for the wisdom of the Perl Monks concerning the following question:
Ok I created a pretty cool little Progress monitor. This was due in part to some advice from grinder
and graff on thread. So I showed some of my
collegues and guess what? Now they want a little tk widget to show up. I am pretty clueless on this one, and I would really appreciate a bit of help on this
Specifically, I don't know where to place the update, and how to call it. Also I don't know what the MainLoop does or what it's there for? I got the TK stuff from the example in Tk but it doesn't work. I've been working at this for a while and I know someone out there can tell explain this to me.. Thanks
#!/usr/local/bin/perl use strict; use Tk; use Tk::ProgressBar; my (@joblist, $job, $pid); # Get a list of all jobs currently running.. chdir(); open (IN, ".dractrack") or die "Can't open .dracktrack for input $!\n" +; while (<IN>){ chomp; push (@joblist, $_); } close IN; foreach $job ( @joblist) { if( $pid = fork ) { # print "Forking off to $pid\n"; } elsif( defined $pid ) { $| = 1; print "\n" ; my %drac; my $atstage = 0; ($drac{Type},$drac{primary},$drac{rundir},$drac{printfile},$drac{h +ostname},$drac{stages}) = split / /, $job , 6; my $mw = MainWindow->new; my $complete =0; $mw->ProgressBar( -borderwidth => 2, -relief => 'sunken', -width => 20, -padx => 2, -pady => 2, -variable => \$atstage, -colors => [0 => 'green', 50 => 'yellow' , 80 => 'red'], -resolution => 0, -blocks => 10, -anchor => "w", -from => 0, -to => $drac{stages}, )->pack( -padx => 10, -pady => 10, -side => 'top', -fill => 'both', -expand => 0 ); while ( ! $complete ){ $atstage = &CheckStage( $drac{rundir}, $drac{printfile} ); if ( $atstage == $drac{stages} ) { print "\n$drac{type} job $drac{primary} on $drac{host} -- Fini +shed\n"; $complete++; }else{ if ($atstage != 0){$mw->update();} printf("Cell: %s Verifying: %s at stage %3d of %3d -- %2.2f co +mplete \r", $drac{primary}, $drac{type}, $atstage, $drac{stages}, 100*$a +tstage/$drac{stages}); # sleep 2; } MainLoop; } } else { die "Can't fork: $!"; } } chdir(); open (DRACNEW, ">>.dracnew") or die "I think dracktrack is running"; rename (".dracnew", ".dractrack") or die "Can't replace .dracktrack.." +; sub CheckStage { my ($path, $log) = @_; open( LOG, "$path$log".".log" ) or die "Cannot open $path$log.log for input: $!\n"; my $at_stage_rec = undef; while( <LOG> ) { $at_stage_rec = $_ if /AT STAGE:/; } close LOG; $at_stage_rec ? (split / /, $at_stage_rec)[3] : undef; }
The <it>seeker</it> of perl wisdom.
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Progress Bars TK::ProgressBars First time trying it..
by {NULE} (Hermit) on Apr 20, 2002 at 01:34 UTC | |
by Rhodium (Scribe) on Apr 22, 2002 at 20:01 UTC |