Hello Monks
I have a small TK GUI with an Entry field and a Table to display results. I am trying to implement what I call a "progressive search": at every keyboard stroke the database query is performed. As the query string is getting longer, the number of matches are reduced at any new keyboard stroke. I am using the following approach:
Everything works fine... except that, if the subrutines take too long time to be processed, same "query string" (which is progressively getting longer) is searched at the very end of the process. If I search for the word "paragraph", for instance, typing one character after the other, I may get:$EntryQuery->idletasks;#$EntryQuery is the Tk widget where the user is + typing $SearchField->bind("<Key>", sub { print "Searching for $QueryInput\n";#$QueryInput is a variable + linked with the Entry widget my $ResultsFinal=QueryDatabase($QueryInput); DeleteAllRowsInTable(); PrintingResultsInTable($ResultsFinal); });
Searching for p Searching for pa Searching for par Searching for paragr Searching for paragra Searching for paragrap Searching for paragraph Searching for para # this should have been searched as 4th iteration, +or skipped as no more interesting (since the user has typed another l +etcharacterter) Searching for parag # this should have been searched as 5th iteration, + or skipped as no more interesting (since the user has typed another +character)
As you can imagine, in this way (if the user is typing quicker than the computer is able to process the subrutines), the user ends up with the results matching "parag" instead of "paragraph". Note that the performed subrutines (especially QueryDatabase) are very complex and may require some time to be processed.
What approach could I use to avoid this problem? I was thinking about breaking out of the sequence of the processed subrutines if the user is typing the next character (as this query is no interesting anymore). But I am not sure if this is a good approach. And if yes, which is the best method to achieve it? Thanks for any suggestions
In reply to Tk progressive search by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |