Ace128 has asked for the wisdom of the Perl Monks concerning the following question:

Alright!

While Im working on this, I was hoping maybe someone here has any good idea on this. Ok, Im doing some nice app here in perl and it uses mySQL db. Now, I've set a window's repeat to like 2 seconds, and the basic idea here is that its supposed to show up result from the mySQL db just beneath an Entry (Tk) widget (kinda like autocompletion) when user types something in the entry. So far I've done something like this:
$fastSearchMenu = $mw->Menu(-tearoff => 0); foreach my $row (@$tbl_array_ref) { $fastSearchMenu->add ('command', -label=> $row->{'path'}, -command => sub { } ); } #$menu->add('separator'); $fastSearchMenu->Popup(-popover => 'cursor'); #$fastSearchMenu->Post(300, 300); $full_PathEntry->focus();
However, this isnt really as nice as I want it. First off, I loose focus from the Entry (eventhough I do the ->focus thingy). And the old meny is floating and doesnt disapear (what its supposed to do, when the db data is updated as user types something else or so). It's also supposed to work pressing.. say.. down arrow on keyboard, and then be able of selecting from this "menu".

So, anyone here got some kewl ideas how to implement this smoothly, and make it work properly? Quite tricky... Not even sure if I should use ->Post or ->Popup either... Or maybe I should use something totally different than Tk::Menu?

Thanks,
Ace

Replies are listed 'Best First'.
Re: Autocompletion simulated in Tk
by mawe (Hermit) on Jul 16, 2005 at 05:03 UTC
      Alrighty! Just as I wanted! Thanks! However, I get kinda curious on the others mentioned. I wanna use "the best" one. And it seems like Tk::MatchEntry is the one to use, but if anyone else here knows if anyone of the following is better, please tell me:
      Tk::BrowseEntry
      Tk::HistEntry
      Tk::JBrowseEntry
      Tk::SelectionEntry

      Tk::MatchEntry is based on all those so I guess Tk::MatchEntry is the one I should go for...

      / Ace
        Hi!

        Well, they all behave a little different (as far as I understood the descriptions ;-)):
        Tk::MatchEntry: While you type into the entry, a list with choices pops up (I guess thats what you wanted).
        Tk::BrowseEntry: Well, that's just a Combobox, which doesn't really care about what you typed into the entry. Always the same items are shown in the list.
        Tk::HistEntry: This one remembers what you typed into the entry, so you can scroll back in history ;)
        Tk::SelectionEntry: I couldn't find this one :-/

        Hope this helps for your decision :)

        Regards, mawe

Re: Autocompletion simulated in Tk
by zentara (Cardinal) on Jul 16, 2005 at 11:52 UTC
    It's not entirely clear, to me anyways, what you are trying to do, but there is also JComboBox.
    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::JComboBox; #see also Tk::Spinbox my @choices; my $index; foreach my $f ( 'A' .. 'Z' ) { foreach my $s ( 'A' .. 'Z' ) { push @choices, "$f$s"; } } my $mw = MainWindow->new(); my $jcb = $mw->JComboBox( -relief => 'groove', # -popuprelief => 'groove', -mode => 'editable', -validate => 'match', -highlightthickness => 0, -choices => \@choices, -textvariable => \$index, -selectcommand => sub { print "Selected: $index\n"; } )->pack; MainLoop; #########################

    I'm not really a human, but I play one on earth. flash japh
      Alright. Tk::MatchEntry it is! Thanks for the effort thought!