Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

working with the ProgressBar widget in Perl/Tk

Status
Not open for further replies.

nexus1001

IS-IT--Management
Sep 27, 2001
13
0
0
DE
Hello all

Does anyone have any experience with Tk progress bars?
I am trying to work with it to complete my program and here's the problem I am having:

I need to display a progress bar while writing lines to a file. how do I do this?? I tried various things like calling a toplevel with the progress bar in it with increasing values for the bar...but displaying the box in a non bloking way seems to be the problem...dont know..out of ideas...does anyone happen to have a good code snippet at hand??? any help appreciated fellas.
 
Hi,
I'm not so sure whether this will work using TK but this is what I use for Dos screen progres bar
print "Searching..";
print "\°";

open(BARFILE, &quot;<$barfile&quot;) || &REPORT_N_DIE(&quot;$barfile&quot;);
@barlines = <BARFILE> ;
print &quot;\°&quot;;

open(TESTCODE_OUT, &quot;>>$update&quot;) || &REPORT_N_DIE(&quot;$update&quot;);
print &quot;\°&quot;;

open(BIOSLIST,&quot;<$biosfreezelist &quot;) || &REPORT_N_DIE(&quot;$biosfreezelist&quot;);
@listlines = <BIOSLIST> ;
print &quot;\°&quot;;

foreach $barline (@barlines)
{
print &quot;\°&quot;;
@barword = split(/ /, $barline);
$barlinecounter++;
foreach $listline (@listlines)
{
seek(BIOSLIST,0,0);
# print &quot;\°&quot;;
$linecounter++;
@listword = split(/,/, $listline);


The print &quot;\°&quot;; statement will get a progress bar running when used in a dos enviornment

 
Thanks Jonv20

This will not work for Tk, since it is a purely graphical environment (furthermore I would like to use the ProgressBar widget)
But its still a pretty good idea for dos based progies it could come in handy.

Anyone else?? suggestions anything? totally stuck here!
 
I didn't even know that Tk had a progress bar widget. Would you mind displaying the syntax you are using, and what do you mean by:
&quot;but displaying the box in a non bloking way seems to be the problem&quot;

a non-blocking way? what do you mean by non-blocking?

--Jim
 
Hi Jim, I solved the problem by packing the progress bar in the program window instead of a separate toplevel.
The problem was getting the toplevel containing the progress bar to pop up and update itself without blocking the running process (a file i/o operation)
putting the progress bar in the main window is a quick fix...it will do for now.

Here is a syntax example for the ProgressBar Widget:

$progr = $parent->ProgressBar( -width => 11,
-length => 200,
-from => 0,
-gap=>0,
-to => 100,
-blocks => 50,
-colors => [0,'#30457E'],
-relief=>sunken,
-troughcolor=>'#EAEDF3',
-borderwidth=>1,
-variable => \$amt_done);

the -variable option is what is used to incrementally 'fill the bar' with whatever amount (usually a percentage of the total amount: option &quot;-to&quot;).

 
Cool ;-) 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
I have recently tried to use the ProgressBar as follows:

...

$main::amtdone = 0;
$main::mw = MainWindow->new;
$main::mw->geometry(&quot;400x30+$main::wmpos&quot;);
$main::mw->minsize('400','30');
$main::mw->maxsize('400','30');
$main::mw->title(&quot;$main::progName [Progress $main::datafile]&quot;);
$main::progress = $main::mw->ProgressBar(
-width => 20,
-borderwidth => 2,
-padx => 2,
-pady => 2,
-relief => 'sunken',
-from => 0,
-gap => 0,
-to => 100,
-blocks => 100,
-colors => [0 => 'red', 35 => 'yellow' , 70 => 'green'],
-variable => \$main::amtdone
)->pack(-fill => 'x');

$main::mw->bind('<Control-s>', sub{&main::stripfmt(&quot;$main::FMTtype&quot;, &quot;$main::datafile&quot;, &quot;$main::datafile.str&quot;)});

MainLoop;

...

sub stripfmt {
...
$main::amtdone = (($main::placeholder / $main::eofpos) * 100);
...
}


The progress bar widget pops up and looks OK.

The subroutine runs, but the progress bar does not change.
 
I solved the problem.

I needed to add the &quot;update&quot; for the following:

sub stripfmt {
...
$main::amtdone = (($main::placeholder / $main::eofpos) * 100);
$main::mw->update(&quot;idletasks&quot;); #### ADDED
...
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top