in reply to Perl::Tk help to startup.

Here's an example of a listbox with directories only, and when you click on an item, it will show information in the text widget.

#!perl -w use strict; use File::Find; use Tk; use Tk::Frame; use Tk::Text; use Tk::Scrollbar; use Tk::Adjuster; # Main Window my $mw = new MainWindow; $mw->geometry('400x300'); # Main Frame my $lf = $mw->Frame; # Left Frame; my $aj = $mw->Adjuster(-widget => $lf, -side => 'left'); my $rf = $mw->Frame; # Right Frame; # Args my $path = $ARGV[0]; # path passed in on the cmd line # create list of directories my %dirs; find(sub {$dirs{$File::Find::dir}++;}, $path); my($ListBox) = $lf->Scrolled('Listbox', -height => '0', -width => '0', -scrollbars => 'e', ); my($OutputText) = $rf->Scrolled('Text', -height => '1', -width => '1', -scrollbars => 'osoe', ); # Load dir names into the listbox $ListBox->insert('end', keys %dirs); # Left mouse button calls display sub $ListBox->bind('<ButtonRelease-1>', sub { OnShowFileAttr(); } ); # Pack everything $lf->pack(qw/-side left -fill y/); $aj->pack(qw/-side left -fill y/); $rf->pack(qw/-side right -fill both -expand 1/); $ListBox ->pack(qw/-side left -fill both -expand 1/); $OutputText->pack(qw/-side bottom -fill both -expand 1/); # Start the main event loop MainLoop; exit 0; sub OnShowFileAttr { my ($index) = $ListBox->curselection(); my $filestats = join ":", lstat($ListBox->get($index)); $OutputText->insert('end', $filestats."\n"); }
The OnShowFileAttr method is where you will want to add your file/dir stat information retrieval. The $ListBox->get($index) will contain the item selected.

This is just a rudimentary script, but it should be less confusing, and hopefully meets your requirements.

--
.dave.

Replies are listed 'Best First'.
Re: Re: Perl::Tk help to startup.
by blackadder (Hermit) on Jul 16, 2002 at 16:55 UTC
    Dave: Thank you x 1000^100 times.

    I have modified the sub OnShowFileAttr to get_perms (which retrieves ACE permission information on the selected object)

    However, if I may, I have the following questions:

    1- every time an object is selected (in the left box), the script will add it to the bottom of the box list on the right. How can I get the script to refresh rather than add it to the end of the list, the reason is if I click on an object, I only need to see it once rather than adding it to the end of the list each time I click on he object?

    2- The Directory list is not sorted in the in the order they appear (i.e c:/, then sub directories in that folder) how can I tie it up so they are sorted in the oder they appear?

    3- I would like to represent account permission information in a graphical form, ie if its a user account then an Icon representing a single user will appear, or else and Icon representing a group instead?

    4- Finally, is it possible (once point 3 implemented) I can move a user account by clicking a dragging then dropping it on top a group Icon? For example if the path c$:/temp has User_a and Group_a allowed to access it, then I drag user_a and drop it on top of the icon representing Group_a, so the path will only show Group_a have accesxs permission and within this group user_a will reaside?

    Your help is like a life line to me at the moment. So Thank you very much in advance.
    use Tk; use strict; use File::Find; use Tk::Frame; use Tk::Text; use Tk::Scrollbar; use Tk::Adjuster; use Win32::Perms; my $path = shift @ARGV; my $mw = new MainWindow; #main frame $mw->geometry('400x300'); my $left_frame = $mw->Frame; #left frame my $adjuster = $mw->Adjuster(-widget=> $left_frame, -side=>'left'); my $right_frame = $mw->Frame; #left frame # create a list of directories my %dirs; find(sub { $dirs{$File::Find::dir}++;}, $path); my ($list_box) = $left_frame->Scrolled('Listbox', -height=>'0', -width=>'0', -scrollbars=>'e', ); my ($output_text) = $right_frame->Scrolled('Text', -height=>'1', -width=>'1', -scrollbars=>'osoe',); #Load dir names into the list box $list_box->insert('end', keys %dirs); $list_box->bind('<ButtonRelease-1>',sub {get_perms();}); #pack everything $left_frame->pack(qw/-side left -fill y/); $adjuster->pack(qw/-side left -fill y/); $right_frame->pack(qw/-side right -fill both -expand 1/); $list_box->pack(qw/-side left -fill both -expand 1/); $output_text->pack(qw/-side bottom -fill both -expand 1/); + MainLoop; exit 0; sub get_perms { my ($indx) = $list_box->curselection(); my $path = $list_box->get($indx); print $path; my $perms = new Win32::Perms($path) || die "\n$^E\n"; my $counter = $perms->Get(\ my @list); foreach my $item (@list) { while (my ($f, $v) = each %$item) { next if ($f !~ /account|access/i ); $output_text->insert('end', $f.": ".$v."\n"); } } }