I want to create autocompletion functionality for my StyledTextCtrl. When chracter is pressed Autocomplete list must be shown with related words. Please provide a simple example for same.
Take a look at the
StyleTextCtrl_2.py sample in the demo.
Well, I had a look at this whether to recommend it as sample, but I could not immediately see how any autocompletion would be triggered. Maybe you should add some note. Pressing Ctrl+Space seems unusual now. Usually IDEs start automatically.
It depends on the needs of the application of course, and how automatic you want it to be, and if the work needed to implement that automaticness it is worth it. Depending on those factors it can be simple or moderately complex.
For example, in PyCrust it’s handled in the
EVT_CHAR event handler when the ‘.’ is typed (or other configured keys). It then tries to get what is before the ‘.’ in order to know what names to put in the autocomp list. To do that it has to interact with the content of STC editor, the Python interpreter and namespace that is active in the shell, and so on.
Why not extend the note at the beginning or
demoText = """\ ## This version of the editor has been set up to edit Python source ## code. Here is a copy of wxPython/demo/Main.py to play with. # Hit Ctrl+Space to invoke auto-completion. """