in reply to (bbfu) Re: simple Perl/Tk problems
in thread simple Perl/Tk problems

Well, below is the example from the k::Progress bar.
Now, it’s NOT blatantly obvious on to how to get this code to work in conjunction with the Dirtree so that if a large drive was selected then the progress bar will indicate that the script is obtaining information and the progress bar will disappear once the data is ready to be displayed.
Is there simpler example for a slow monk like me please?
use strict; use Tk; use Tk::ProgressBar; use Tk::Scale; my $mw = MainWindow->new; my $status_var = 0; my($fromv,$tov) = (0,100); foreach my $loop (0..1) { my $res = 0; my $blks = 10; my @p = qw(top bottom left right); foreach my $dir (qw(e)) { $mw->ProgressBar( -borderwidth => 2, -relief => 'sunken', -width => 20, -padx => 2, -pady => 2, -variable => \$status_var, -colors => [0 => 'green', 50 => 'yellow' , 80 => 'red'], -resolution => $res, -blocks => $blks, -anchor => $dir, -from => $fromv, -to => $tov )->pack( -padx => 10, -pady => 10, -side => pop(@p), -fill => 'both', -expand => 1 ); $blks = abs($blks - ($res * 2)); $res = abs(5 - $res); } ($fromv,$tov) = ($tov,$fromv); } $mw->Scale(-from => 0, -to => 100, -variable => \$status_var)->pack; MainLoop;

Replies are listed 'Best First'.
(bbfu) (Tk::Progress et Tk::DirTree) Re3: simple Perl/Tk problems
by bbfu (Curate) on Sep 11, 2002 at 16:18 UTC

    You're right, of course. It's not quite as straight-forward as I was thinking it would be. :)

    The problem is that you need a hook into the default handler for the dircmd callback, and it doesn't seem that you can get one. You're probably going to need to write your own. :(

    Here is the source of the default handler (taken directly from Tk/DirTree.pm):

    sub DirCmd { my( $w, $dir, $showhidden ) = @_; my $h = DirHandle->new( $dir ) or return(); my @names = grep( $_ ne '.' && $_ ne '..', $h->read ); @names = grep( ! /^[.]/, @names ) unless $showhidden; return( @names ); }

    Pretty simple. You just need to include a modified version of that sub in your program, and give your Tk::DirTree object a reference to it as the handler for the -dircmd callback (ie, $dirtree->configure(-dircmd => \&MyDirCmd);).

    In your copy, you need to break out that grep, probably into a for loop, or something, so that you can have your code update the Tk::ProgressBar. Of course, that's going to slow down reading of all directories. Not by much, though, hopefully.

    Anyway, regarding showing and hiding the progress bar... You could use a pop-up window to show it (there's even a Tk::ProgressBarDialog or something similar in the Snippets section of this site, I believe). I, however, would probably go with a status-bar type deal, where the progress bar is always shown, but empty, at the bottom of the window, and it just fills up while reading directories. *shrug* Up to you.

    Hope that helps!

    bbfu
    Black flowers blossum
    Fearless on my breath