I am trying to implement live search with a TextCtrl and have the results displayed in a PopupWindow, much like Autocomplete. I have a working example without the PopupWindow, but can’t get it to work with one.
I can’t use TxtCtrl.AutoComplete (with TextCompleter/TextCompleterSimple), because that filters the results by excluding anything which doesn’t start with the “prefix” entered in the TxtCtrl. Of course, for search, results can have the search string in the middle or the end of a result, not just the beginning. Yes, it works so long as the user’s search string is the prefix, but that’s not a workable solution.
It seems that since TxtCtrl.Autocomplete was introduced, all of the examples out their implementing custom autocomplete widgets have no longer been updated. The most recent I could find is the Autocomplete 2 example on the wiki. But that example does’t even work as-is for me. Upon entry of a single character into the TxtCtrl, focus changes from the TxtCtrl to the PopupWindow. At the end of the onEnteredText method, TxtCtrl still has focus, but after it returns, focus changes and I can’t figure out why. Changing focus causes the EVT_KILL_FOCUS
event to fire and the onControlChanged
method to be called which hides the PopupWindow. Disabling that event/method will cause the popup to stay visible, but you can’t enter more that one character, so it’s not useful, among other issues.
I tried creating a simplified version in an attempt to eliminate possible causes, but I keep encountering the same issue. I’m on WxPython 4.1.1, Python 3.8 and Windows 10. Any help in avoiding the focus changing would be appreciated. Or, if you can point to a working example that would be even better.