问题
This is one part of a two part question (other part is here)
So I'm working with wxPython and PyEnchant trying to get some fancy features going. Specifically, I want my text controls to change the color of mispelled words. I can do this if I bind the following code to a button. (where input
is a wx.TextCtrl
)
chkr = SpellChecker("en_US",self.input.GetValue())
words = self.input.GetValue().split()
wrongWords = [err.word for err in chkr]
self.input.ChangeValue("")
for word in words:
if not word in wrongWords:
self.input.SetDefaultStyle(wx.TextAttr(wx.BLACK))
self.input.AppendText(word+" ")
else:
self.input.SetDefaultStyle(wx.TextAttr(wx.RED))
self.input.AppendText(word+" ")
This works exactly how I want it, except that I do not want to have to bind it to a button.
This is where the second question comes in. I want it to happen automatically after the user has finished editing. You can see the other question for a full discussion of whhat that means, but in the scope of this question, all it means is that I must do the above operation without generating an EVT_TEXT
event.
ChangeValue()
is identical to SetValue()
, but it does not generate EVT_TEXT
, so is there an analogous function to AppendText()
which does same? Or failing that, is there a way to suppress EVT_TEXT
when it is generated by AppendText()
or someway to determine if the event came from AppendText()
? Thanks in advance.
EDIT: I've managed to get a work around going by using Unbind()
, but I'm still open to a better method if anyone can find one
来源:https://stackoverflow.com/questions/20479478/how-do-i-edit-the-color-of-a-word-without-generating-evt-text-in-wxpython