in reply to perl tk::DirList

Hi, I wrote Tk::CanvasDirTree. Your lack of experience with Perl/Tk limits you in how you see the usefulness of the module. If you look at the demo1 or demo2 (and exclude the color and graphic changes which are only for the demonstration of capabilities), when you click on a directory in the left frame, the directory name is written in the right frame. Be flexible here, so instead of writing the dir name on the right, open the directory with opendir, and list all the files of the type you want. What is written in the right frame is not part of the module, it's how I used the module.

In Tk, you will not find many pre-made solutions, you need to combine different widgets.

So here is how I might start it. I put a listbox in the right frame to print the filelist. You need to double-click the file to select it. (That is one drawback of the listbox.... a single click highlights it, but you need a double-click or a right-click to do an action. There are other widgets you can use though).

#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::CanvasDirTree; use Encode; my $mw = MainWindow->new(); $mw->geometry('+200+50'); $mw->fontCreate('big', -family=>'arial', -weight=>'bold', -size=>int(-18*18/14)); my $frame = $mw->Frame()->pack(-expand=>1,-fill=>'both'); my $ztree = $frame->Scrolled('CanvasDirTree', -bg =>'white', -width =>350, -height =>350, -font => 'big', # defaults to system -scrollbars =>'osow', -borderwidth =>15, -scrollregion => [0,0,700,700] )->pack(-side=>'left',-fill=>'both', -expand=>1); my @filearray; my $lb = $frame->Scrolled('Listbox', -listvariable => \@filearray, -scrollbars =>'osoe', -bg=>'white', -width => 30, -selectmode => 'browse', )->pack(-side=>'right',-fill=>'both',-expand=>1);; $lb -> bind("<Double-Button-1>",\&display); my $button = $mw->Button(-text=>'Exit',-command=>sub{exit})->pack(); $ztree->bind('<ButtonPress-1>', sub{ my $selected = $ztree->get_selected(); if(length $selected){ opendir my $dh, $selected or warn "Error: $!"; my @files = grep !/^\.\.?$/, readdir $dh; @files = grep {-f "$selected/$_"} @files; closedir $dh; #make it utf8 safe @filearray = map{ decode('utf8',$_) } @files; } }); # set scrollbar colors my $xbar = $ztree->Subwidget("xscrollbar"); my $ybar = $ztree->Subwidget("yscrollbar"); # do not attempt to change the scrollbar's -yscrollbackcommand # it is used internally by CanvasDirTree for($xbar,$ybar){ $_->configure( -background => "darkseagreen", -activebackground => "lightgreen", -troughcolor => "black", ); } MainLoop; sub display { my $selected = $lb -> get($lb -> curselection); print "you chose $selected\n"; $lb->selectionClear(0, 'end'); }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: perl tk::DirList
by patmcl (Novice) on Jun 19, 2007 at 21:04 UTC
    Thanks,
    I cannot get the ::canvisDirTree into my @inc. I am in windows xp and I am using the perl and perl/tk provided by Activstate Perl. This does not include CanvisDirTree. I ran perl makefile.pl and it created Makefile. However i do not seem to have "make".
      Hi, just manually copy CanvasDirTree.pm into your INC folder. I wrote it for linux, so I really can't say it is bug-proof on Win32, because of the way the Win32 filesystem is setup. If the demos run, you ought to be Ok.

      I'm not really a human, but I play one on earth. Cogito ergo sum a bum