Live Search in PopupWindow

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.

I’m not quite sure what you are talking about, but try this (839 Bytes) (7.4 KB)

1 Like

That does work, but it uses a wx.Dialog, which has a title bar. I would prefer the popup not have a title bar. If I change it to a wx.PopupWindow, then I get the same buggy behavior where the popup takes the focus. So something about PopupWIndows seems to be messing with focus in more recent versions. I’d like to know what that is and, more specifically, how to avoid it.

My credo is standard which works across all platforms, sorry :sunglasses:

Hi, waylan

You may like this post? (Auto Completion for TextCtrl not suggesting everything from result array - #7 by spyro).

well, if you find the title bar boring, try this :sneezing_face: (849 Bytes) (7.4 KB)

Thanks for the pointer @komoto48g. Unfortunately, that example exhibits the same focus issue for me.