Auto-Complete Autocomplete

I am trying to extend the behavior of ttk :: combobox to make it behave like a Google search box in my browser - that is, I would like it to automatically fall and restrict the entries in the list so that those that match the line I typed so far since Ultimately, I would like to select the part of the line that was autocompleted, so that the next character that the user enters will delete it and restart the matching process.

I found the page in the Tcler wiki , but it seems like selecting an entry with an entered letter, which is not what I want. (Think about what the user selects from the list of US states. When they type A, I want the selection limited to Alabama, Alaska, Arizona and Arkansas, and when they type L, the list should be limited to Alabama and Alaska. Code on the wiki will select Alabama when the user types A and then Louisiana when they type L.)

I tried to define some bindings on ttk :: combobox, but gave it - to be honest, I can’t remember why - and tried to extend the behavior of the ttk :: entry to cover it.

After borrowing from ttk / combobox.tcl, I was able to publish the list and restrict the entries in the list, but now I have big problems when I added the bindings so that the up and down arrows change the selection. To be precise, the selected item moves with pleasure, but while the input widget loses focus, the whole application freezes and my tclsh absorbs the entire processor.

I am developing ActiveTcl 8.6 for both Windows and Linux, and it seems to work the same on both platforms, although I have not tried Linux since I first saw that it does not hang on Windows. I would be very happy to share my code, but since the demo version of the script works up to about 450 lines, I would not read it myself if someone else posted this a lot.

Can someone help by asking the right question to light a bulb for me? The problem is with the synchronization problem, but I don’t know where to start tracking it.

Thank you very much.

Change I had a brain, and I think the reason I gave up trying to extend ttk :: combobx was because there really were already a lot of bindings, and some things that I didn't want. The current effort uses the validate command for the input and binding widget Key-Up, Key-Down, FocusIn, and FocusOut.

The current code is on pastebin here .

+4
source share
1 answer

Well, that was awkward!

I looked again at the code on the wiki and found that it did what I most wanted. It does not publish the list, but it does autocomplete, and if you try to navigate the (unpublished) list by pressing the "Key-Up" or "Key-Down" key, it starts by highlighting the corresponding item.

This is enough for what I need; if I decide that a list really needs to be published, I can see about it at that time. (Given my bad experience trying to knock over my own, however, I suspect that I will just live with it.)

Thanks so much for the anticipation and suggestions.

+2
source

Source: https://habr.com/ru/post/1483389/


All Articles