For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > July 2007 > list box search ....









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author list box search ....
nagandla@gmail.com

2007-07-17, 8:03 am

Hi all...

In my Front end i had a browse entry ,Dyna tab frame and listbox
widget.....

so if select a directory in browse entry the files in that directory
will come into listbox.....

so wat i need is i want to search with in that list box...

means without putting one more textbox for searching,i need to
search..
means for ex ..when i am typing some file name like "abc " the cursor
must automatically go to the file name which starts with "abc"...like
that

how can i do that...

here i will give code to some extent...
#!/usr/bin/perl
use Tk;
use Tk::LabFrame;
use Tk::DynaTabFrame;
use File::Find;
use Tk::BrowseEntry;


my ($selected_folder,$prev_canvas,$onlyfol,
$folder_tab,$count,$nb);
my @dir =();
my @details =();
my %files_list;
my %list_of_all_files = ();
my @ooo = ();
my %files_with_path;
my $path = "/national";
my $mw = MainWindow->new;
$mw->protocol(WM_DELETE_WINDOW => \&bye);
$mw->geometry("860x840+1+25");
$mw->maxsize(860,840);
$mw->minsize(860,840);
$mw->resizable(0,0);
$mw->title("Pyro");

my $folder_list = $mw->BrowseEntry(
-background => 'white',
-font => ['Arial','12'],
-textvariable => \$selected_folder,
-browsecmd => sub{&add_files_to_tab;},
-width => '35',
-disabledforeground => 'black',
-state => 'readonly'
)->pack(-side=>'top',
-anchor => 'w',
-fill=>'both',
-expand=>'1');


$nb= $mw->DynaTabFrame(-tabclose => sub {
my ($dtf, $caption) = @_ ;
if($caption eq 'Preview')
{
return;
}
delete($list_of_all_files{$caption});
$dtf->delete($caption);
if(defined(@ooo))
{
for my $i ( 0 .. $#ooo )
{
if ( $ooo[ $i ] eq $caption )
{
splice @ooo, $i, 1; # deleting $i index from @ooo array
last;
}
}
}},
-raisecmd => sub {my $onlyfol = $nb->raised_name();
if (exists $list_of_all_files{$onlyfol})
{
$list_of_all_files{$onlyfol}->focus;

}},

-tabside => 'nw',-raisecolor => 'pink')->pack(-side=>'top',
-anchor => 'w',
-fill=>'both',
-ipady => '90',
-expand=>'1');

my $preview_page = $nb->add( -caption => 'Preview') ;
$prev_canvas = $preview_page->Canvas(-bg => 'white')->pack(-fill =>
'both',
-expand => '1');

$ENV{SDL_WINDOWID} = $prev_canvas->id;


opendir(DIR,$path);
my @file_s = readdir(DIR);
my @files;
foreach(@file_s)
{
push(@files,$_) if ($_ !~ /\.$/)
}
closedir(DIR);
$folder_list->insert('end',sort(@files));


MainLoop;

sub bye
{
exit;
}

sub add_files_to_tab
{
my @only_folder=();
$selected_folder = $path . '/' . $selected_folder;
@only_folder = split /\//,$selected_folder;
@dir = ' ';
push(@dir,$selected_folder);

$onlyfol = $only_folder[$#only_folder];
$nb->raise($onlyfol)if exists $list_of_all_files{$onlyfol};
if(defined(@ooo))
{
foreach(@ooo)
{
if($_ =~ /$onlyfol/)
{
return;
}
}
}
if(scalar(@ooo) == 5){return;}else{
$folder_tab = $nb->add(-caption => $onlyfol);}
$list_of_all_files{$onlyfol} = $folder_tab->Scrolled('Listbox',-bg =>
'white',-font => ['Arial','12'])->pack(-expand => '1',-fill =>
'both');
$list_of_all_files{$onlyfol}->focus;

push(@ooo,$onlyfol);
print "@ooo\n";
%files_list = ();
# %files_with_path = ();
find(\&wanted,@dir);

}

sub wanted
{
if(($_ =~ /\.mpg$/) or ($_ =~ /\.dif$/) or ($_ =~ /\.westley$/))
{
my $folder = $File::Find::dir;
my $onlyfol = $nb->raised_name();
$files_with_path{$_} = $folder;
$list_of_all_files{$onlyfol}->insert('end',sort($_));
$files_list{$_} = $_;
}
}


Regards
Lakshmi Nagandla

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com