Re: [racket-users] Re: Autocomplete from a list

2019-02-17 Thread James Platt
On Feb 14, 2019, at 9:22 PM, Alex Harsanyi wrote:

> There are two solutions I can think of:
> 
> (1) derive combo-field% and override the on-popup method to construct the 
> choice menu dynamically based on what is selected in the combo box field.  
> This has a few disadvantages, namely (a) you have to produce the menu 
> immediately, so if you have to query a database for the list of items, there 
> might be a long delay for the menu to show up and (b) the menu will not 
> update when the user types more text in the field, instead it will have to be 
> closed and reopened.
> 
> (2) you can use a combination of text-field% and a list-box%, where the 
> callback on the text field will populate the list box with the filtered 
> contents.  The user would have to select an item from the list box, but this 
> can be populated in a separate thread to prevent the GUI from freezing up 
> during a database query.  It does not look as nice as GUI widgets from other 
> applications though...
> 
> Here is some example code for both options, including an animation of what it 
> looks like:
> 
> https://gist.github.com/alex-hhh/20f03dcf2f7f340d20b95cb36da39f61
> 
> Alex.

Thanks.  This is really helpful.  I will probably go with option (2) because 
it's more practical and this is a part of the application which will not be 
used frequently.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Autocomplete from a list

2019-02-15 Thread Greg Hendershott
If the user will choose very frequently (and you want the fastest UX),
and the choices in the database don't change very frequently: It might
be worth experimenting with caching the choices in memory. For
auto-complete I imagine something like a trie, or whatever the latest
hotness might be.

The memory use might be too much to accept. But if the choices have
enough redundancy, the size of the trie might not be awful.

The cache can get stale. How much this matters, depends on your app
and the data. Refreshing every N minutes might be fine? If it's not
fine, and if you're using postgresql, the db lib's postgresql-connect
accepts a notification-handler.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: Autocomplete from a list

2019-02-14 Thread Alex Harsanyi
There are two solutions I can think of:

(1) derive combo-field% and override the on-popup method to construct the 
choice menu dynamically based on what is selected in the combo box field.  
This has a few disadvantages, namely (a) you have to produce the menu 
immediately, so if you have to query a database for the list of items, 
there might be a long delay for the menu to show up and (b) the menu will 
not update when the user types more text in the field, instead it will have 
to be closed and reopened.

(2) you can use a combination of text-field% and a list-box%, where the 
callback on the text field will populate the list box with the filtered 
contents.  The user would have to select an item from the list box, but 
this can be populated in a separate thread to prevent the GUI from freezing 
up during a database query.  It does not look as nice as GUI widgets from 
other applications though...

Here is some example code for both options, including an animation of what 
it looks like:

https://gist.github.com/alex-hhh/20f03dcf2f7f340d20b95cb36da39f61

Alex.


On Friday, February 15, 2019 at 5:39:31 AM UTC+8, James Platt wrote:
>
> I have a situation where I want a Racket GUI combo-field% (or some other 
> GUI element) to allow the user to select an exact item (uniquely matching a 
> database key) from a list that is too long to display all at once.  I'm 
> thinking that some form of auto completion would be best.  In Framework, I 
> see that there is an auto-complete method in text% but I don't see a way to 
> give it a specific search space to work from.  I see the opposite. You can 
> get the list which it is auto completing from but I don't see how to set 
> it.   
>
> I mention combo-field% because the equivalent item in the LibreOffice 
> database module does what I want.  I had a LibreOffice document which was 
> connecting as client to a PostgreSQL database.  The combo-field list items 
> were populated with an SQL query which got all the official human gene 
> symbols from the database.  At the time there were something like 40,000 
> unique official gene symbols.  The user could start typing and it would 
> reduce the list, as you go, to the remaining items that match.  Also, when 
> there are too many items to display at once, LibreOffice only displays the 
> first 10 or 20 items in the combo-field menu and gives you a scroll bar. 
>  This worked out pretty well for that use case.  I now have a very similar 
> one.   
>
> What would be the best way to handle this situation?  The user needs to 
> select an exact item from a database but there are too many items for a 
> simple menu. 
>
> James

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.