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

Hi monks,

I'm using the next code
my $top = MainWindow -> new(title=>"Choose Directory(must be a pro +ject Directory)"); $top->withdraw; my $t = $top->Toplevel; # my $top = new MainWindow; # $top->withdraw; # my $t = $top->Toplevel; $t->title("Choose Directory(must be a project Directory)"); # my $t = $top->Frame; my $ok = 0; # flag: "1" means OK, "-1" means cancelled # Create Frame widget before the DirTree widget, so it's always vi +sible # if the window gets resized. my $f = $t->Frame->pack(-fill => "x", -side => "bottom"); #my $curr_dir = Cwd::cwd(); my $curr_dir = 'k:/'; my $d; $d = $t->Scrolled('DirTree', -scrollbars => 'osoe', -width => 60, -height => 20, -selectmode => 'browse', -exportselection => 1, -browsecmd => sub { $curr_dir = shift }, # With this version of -command a double-click will # select the directory #-command => sub { $ok = 1 }, # With this version of -command a double-click will # open a directory. Selection is only possible with # the Ok button. -command => sub { $d->opencmd($_[0]) } )->pack(-fill => "both", -expand => 1); # Set the initial directory $d->chdir($curr_dir); $d->chdir('c:/'); $f->Button(-text => 'Ok', -command => sub{$ok = 1} )->pack(-side => 'left', qw/-padx +50 -ipadx 10/); $f->Button(-text => 'Cancel', -command => sub {$ok = -1})->pack(-side => 'right',qw/-pady + 3 -padx 50/); $top->bind('<Key-Escape>',[$top=>'destroy']); $t->bind('<Key-Escape>',sub{$ok=3}); $f->bind('<Key-Escape>',sub{$ok=3}); # You probably want to set a grab. See the Tk::FBox source code fo +r # more information (search for grabCurrent, waitVariable and # grabRelease). $f->waitVariable(\$ok); if ($ok == 1) { warn "The resulting directory is: $curr_dir\n"; }#elsif($ok == -1){exit(0);} else{print"No directory chosen.\n";goto TOP;} $top => 'destroy'; return ($curr_dir);


I want to close the window after choosing the directory
in order to use this window again and not have more then one window open at a time

Another thing I want to do is to present all drives on the computer as options in the tree

I appreciate the help,
Thaks in advace,
Moked

Replies are listed 'Best First'.
Re: operation on DIRTree
by Anonymous Monk on Oct 24, 2007 at 12:31 UTC