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

i have a little problem : i have the following lines of code (that work fine under linux):
sub select_dir{ my $choose_dir = $main->Toplevel; $choose_dir->title("Choose directory:"); my $ok = 0; my $frame = $choose_dir->Frame->pack( -fill => "x", -side => "bottom" ); my $curr_dir = Cwd::cwd(); my $scrolled; $scrolled = $choose_dir->Scrolled('DirTree', -scrollbars => 'osoe', -width => 35, -height => 20, -selectmode => 'browse', -exportselection => 1, -browsecmd => sub { $curr_dir=shift }, -command => sub { $ok = 1 }, )->pack(-fill => "both", -expand => 1); $scrolled->chdir($curr_dir); $frame->Button(-text => 'Ok', -command => sub { $ok = 1 } )->pack(-side => 'left'); $frame->Button(-text => 'Cancel', -command => sub { $ok = -1 } )->pack(-side => 'left'); $frame->waitVariable(\$ok); $status->configure(-text=>"Status area"); if ($ok == 1){ $choose_dir->withdraw; if (-x $curr_dir){ return $curr_dir; } tackle_err ("$1 doesn't exist"); return; } else { $choose_dir->withdraw; return; } }
and in gerneral also work under win32 , but : i can only access the directories of one harddrive (the current one) ... Is there a way to change that or is there another tk-widget more suitable for this problem

----
NaSe
:x

Replies are listed 'Best First'.
Re: Tk::DirTree & Win
by svad (Pilgrim) on May 30, 2002 at 10:48 UTC
    To solve similar problem, I add following lines into my code:
    if ($^O eq 'MSWin32') { require 'Win32API::File'; my @drv = map{s/\\$//;lc} Win32API::File::getLogicalDrives(); $dt->add_to_tree($_, $_) for @drv; }
    where my $dt = $dirlist->Scrolled('DirTree',....

    Also, to behave good on Win32, I override 'has_subdir':

    package Tk; sub has_subdir {1}
    and you will not get annoying behaviour, when before opening a window each drive will be tryed to access, causing by CD-ROM, diskette to roll, and slow network drives to slow down your program.

    Warmest wishes,
    Vadim

      correction: I override 'has_subdir' in Tk::DirTree package.
      Also there is some more to override in those packages for Win32 (for case-insensistive sorting, for exampe):
      package ::Tk::DirTree; sub has_subdir {1} sub DirCmd { my ($w, $dir, undef) = @_; $dir =~ s/^(\w:)$/$1\//; my $h = DirHandle->new($dir) or return; my @names = grep( $_ ne '.' && $_ ne '..', $h->read ); return @names; } sub add_to_tree { my( $w, $dir, $name, $parent ) = @_; my $image = $w->Getimage( $w->cget('-image') ); my $mode = 'none'; $mode = 'open' if $w->has_subdir( $dir ); my @args = (-image => $image, -text => $name); if( $parent ) { # Add in alphabetical order. foreach my $sib ($w->infoChildren( $parent )) { if( lc($sib) gt lc($dir) ) { push @args, (-before => $sib); last; } } } $w->add( $dir, @args ); $w->setmode( $dir, $mode ); }
        thanx i'll give it a shut

        ----
        NaSe
        :x

Re: Tk::DirTree & Win
by NaSe77 (Monk) on May 31, 2002 at 09:00 UTC
    quick question though: why is this a thread initialized by anonymous monk ? I have written it . what went wrong? any ideas ?

    ----
    NaSe
    :x

      I propose copying your question and those answers into Q&A section, how do you think?
      Courage.
        i dont know if the question fits into any of the catigories? but en general a good idea

        ----
        NaSe
        :x