Search code examples
pythonpython-2.7wxpython

How do I pass highlighted text from text control in wxPython


I'm working on building some extra functions based off the PyEnchant spell checker for my wxPython GUI. Currently, I have my text controls turn misspelled words red (detailed here and here), but I'd like to incorporate the suggestions feature of PyEnchant.

Ideally, I'd like to have the suggestions pop up when the user right clicks on the highlighted word in the text control similar to how Microsoft Word does it. But this sounds pretty hard, so I'd settle for just throwing up a wx.SingleChoiceDialog when the user highlights the word then presses "alt+s" (using an accelerator table).

The key is being able to pull the text the user highlights. I can figure out everything else, but this continues to elude me to the point where I'm beginning to doubt if its possible. Hopefully it is and you know how to do it, thanks in advance


Solution

  • As mentioned, the GetStringSelection function will return the current text selection.

    The documentation for wxEditText doesn't show this function, but wxTextCtrl is also derived from wxTextEntry, and that's where the function is defined.