halfcountplus has asked for the wisdom of the Perl Monks concerning the following question:
history() is the function in question (what else)#!/usr/bin/perl -w use strict; use Tk; my $MW = MainWindow->new(); my $entry1 = $MW->Entry; my $enhist = history(\$entry1,"new"); $entry1->bind("<Key-Return>"=>sub{history(\$entry1,"add", $enhist)}); $entry1->bind("<Key-Up>"=>sub{history(\$entry1,"up", $enhist)}); $entry1->bind("<Key-Down>"=>sub{history(\$entry1,"down", $enhist)}); my $entry2 = $MW->Entry; my $enhist2 = history(\$entry2,"new"); $entry2->bind("<Key-Return>"=>sub{history(\$entry2,"add", $enhist2)}); $entry2->bind("<Key-Up>"=>sub{history(\$entry2,"up", $enhist2)}); $entry2->bind("<Key-Down>"=>sub{history(\$entry2,"down", $enhist2)}); ##GRID## $entry1->grid(-row=>0,-column=>0); $entry2->grid(-row=>2,-column=>0); MainLoop;################## sub history { my $entry = shift; my $cmand = shift; my $hist; if ($cmand eq "new") { my %hash; my @list; $hash{hlist} = \@list; $hash{place} = 0; my $ref = \%hash; return $ref; } else {$hist = shift;} if ($cmand eq "add") { my $string = $$entry->get; $$entry->delete('0','end'); push(@{$hist->{hlist}},$string); $hist->{place}++; } elsif ($cmand eq "up") { if ($hist->{place} <= 0) {$hist->{place} = $#{$hist->{hlist}}} else {$hist->{place}--}; $$entry->delete('0','end'); $$entry->insert('1',$hist->{hlist}[$hist->{place}]); } elsif ($cmand eq "down") { $$entry->delete('0','end'); if ($hist->{place} == $#{$hist->{hlist}}) { $hist->{place} = -1; return} $hist->{place}++; $$entry->insert('1',$hist->{hlist}[$hist->{place}]); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What to do with my "Tk entry command-history" function
by shmem (Chancellor) on Sep 06, 2008 at 09:44 UTC | |
by dwm042 (Priest) on Sep 06, 2008 at 14:42 UTC | |
|
Re: What to do with my "Tk entry command-history" function
by binf-jw (Monk) on Sep 06, 2008 at 09:27 UTC | |
|
Re: What to do with my "Tk entry command-history" function
by broomduster (Priest) on Sep 06, 2008 at 14:36 UTC | |
|
Re: What to do with my "Tk entry command-history" function
by zentara (Cardinal) on Sep 06, 2008 at 15:11 UTC |