blackadder has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks.

I would like to know how to program the progress bar in Perl/Tk. I have been developing (or trying very hard – since I am new to Tk) this utility that will obtain permission information pertaining to a given drive. The DirTree call display does take some time to get the tree directory structure for very large drives (where as if I use any WinNt browser and select a drive the information is almost instant). So my questions are:

1- I am I doing something wrong that causing this delay in display the DirTree of the drive?

2- If no, then how and where can I incorporate a progress bar to indicate that the script is compiling a directory tree list so the script doesn’t look like it’s hung?

3- If a drive that is either doesn't exit or its removable (i.e if the floppy or cd-rom drive) was inputted. Where in the script I can capture it and issue a Win32 based MsgBox informing of the error?
I have tried the modifying the sub OnNewPath to
if ($tk{dir_tree}-> chdir ($dr{path})) { $tk{dir_tree}-> delete('all'); ShowServer($dr{path}); } else { Win32::MsgBox(“$^E”); }
But this did not work.

Many Thanks to all benevolent contributors.
require 5.006; use strict; use warnings 'all'; use Tk 800.005; use Tk::TList; use Tk::Frame; use Tk::DirTree; use Tk::Adjuster; use Tk::Scrollbar; use Win32; use Win32::NetAdmin; use Win32::AdminMisc; use Win32::NetResource; use vars qw/%tk %dr %im/; $dr{path} = "c:\\"; $dr{server} = ShowServer($dr{path}); $dr{perms} = "Permissions '" . $dr{path} . "'"; $dr{domain} = "Domain : " . Win32::DomainName(); printf "\n%s,\t%s,\t%s,\t%s", $dr{path}, $dr{server}, $dr{perms}, $dr{ +domain} . "\n"; $tk{mw} = MainWindow-> new (-background=> 'white'); $tk{mw}-> geometry('900x700'); $tk{top_frame} = $tk{mw}-> Frame; $tk{left_frame} = $tk{mw}-> Frame; $tk{adjuster} = $tk{mw}-> Adjuster(-widget=> $tk{left_frame}, -side=> +'left'); $tk{entry_box_label} = $tk{top_frame}-> Label(-text=> "Path: "); $tk{entry_box} = $tk{top_frame}-> Entry(-textvariable=> \ $dr{path}); $tk{dir_tree_label} = $tk{left_frame}-> Label(-textvariable=> \ $dr{se +rver}); $tk{dir_tree} = $tk{left_frame}-> Scrolled('DirTree', -height=> '0', - +width=> '0', -scrollbars=>'e',); $tk{entry_box}-> bind('<Key-Return>', sub {&OnNewPath();}); $tk{top_frame}-> pack(qw/-side top -fill x/); $tk{left_frame}-> pack(qw/-side left -fill y/); $tk{adjuster}-> pack(qw/-side left -fill y/); $tk{entry_box_label}-> pack(qw/-side left -fill both/); $tk{entry_box}-> pack(qw/-side top -fill both -expand 1/); $tk{dir_tree_label}-> pack(qw/-side top -fill both/); $tk{dir_tree}-> pack(qw/-side left -fill both -expand 1/); MainLoop; exit(0); sub ShowServer{ my $drv = @_; my $srv; if (Win32::NetResource::GetUNCName( my $unc, $dr{path})){ $unc =~ s/^\\\\(\w)+//; $srv = $&; return $dr{server} = "[ Remote Server Name : " . uc($srv) . " ]";} else{ $srv = Win32::NodeName(); return $dr{server} = "[ Local Server Name : " . uc($srv) . " ]";}} sub OnNewPath{ $tk{dir_tree}-> delete('all'); $tk{dir_tree}-> chdir ($dr{path}); ShowServer($dr{path});}
Blackadder

Replies are listed 'Best First'.
Re: Programming the progress bar in Perl/Tk and Retrieving the last error msg
by Courage (Parson) on Aug 07, 2002 at 15:40 UTC
    Following node: Tk::DirTree & Win covers 80% of your question. If after using those advices you'll need more help, let me know, I'll see what I can do.

    Courage, the Cowardly Dog

      Thanks for the hint ;-)