package main_config_tk ; my $Win_background = "white" ; my $Win_foreground = "black" ; my $max_length = 50 ; sub file_select_box { # my ( $event, %parent, $key, $I) = @_ ; my ( $event, $key, $filter_file) = @_ ; my @all_files ; my @list_files = () ; # my $filter_file = "[0-9,A-Z,a-z]" ; # my $filter_file = "" ; print " box:", ${$key}, "\n" ; my $tt = ${$key} ; my $lb; my $nw ; my $w ; my $ff ; my $my_file ; $nw = MainWindow->new (-width => 600, -height => 350, -background => $Win_background, -foreground => $Win_foreground ); $nw->title("Tk: main config:: file replacement for {$tt}"); my $f = $nw->Text( -width => $max_length + 30, -height => 1, -background => $Win_background, -foreground => $Win_foreground, -wrap => 'none')->pack(-expand => 'x', -fill => 'both', -side => 'top'); $f->configure(-state => 'normal'); $w = $f->Label(-text => "File Filter", -justify => 'center', -relief => 'groove', -width => $max_length ); $f->windowCreate('end', -window => $w); $w = $f->Entry(-width => 60, -textvariable => \$filter_file, -justify => 'left' ); $f->windowCreate('end', -window => $w); $w->bind("", [\&main_config::list_regenerate, \@all_files, \@list_files, \$filter_file, \$lb ] ) ; $f = $nw->Text(-background => $Win_background, -foreground => $Win_foreground)->pack(-side => 'bottom'); $f->Button(-text => "Cancel", -command => sub { $nw->destroy() if Tk::Exists($nw) ; })->pack(-side => 'left'); $f->Button(-text => "Done", -command => sub { my $x_file_name = $lb->get($lb->curselection()) ; # print "the file name: {", $x_file_name, "}\n" ; # $parent{$key}{'ARRAY'}[$I] = $x_file_name ; ${$key} = $x_file_name ; $nw->destroy() if Tk::Exists($nw) ; })->pack(-side => 'bottom'); my $path = './' ; opendir( ALLFILES, $path ); @all_files = readdir( ALLFILES ); closedir( ALLFILES ); $lb = $nw->Scrolled("Listbox", -scrollbars => "e", -selectmode => "single")->pack (-fill => 'both') ; @list_files = () ; foreach $my_file ( sort( @all_files ) ) { if ( $my_file =~ $filter_file ) { push( @list_files, $my_file ) ; } } # @list_files = @all_files ; $lb->insert('end', @list_files ) ; # $lb->insert('end', qw/red green yellow blue/) ; $lb->bind('', sub{ my $x_file_name = $lb->get($lb->curselection()) ; # print "the file name: {", $x_file_name, "}\n" ; } ) ; $lb->bind('', sub{ my $x_file_name = $lb->get($lb->curselection()) ; # print "the CLICK file name: {", $x_file_name, "}\n" ; if ( -d $x_file_name ) { print " directory file \n" ; } else { ${$key} = $x_file_name ; $nw->destroy() if Tk::Exists($nw) ; } } ) ; } 1;