double EVT_TEXT events

Sorry for the dealy, I've been swamped.

Will Sadkin wrote:

Robin,

I have a problem that's been driving me crazy, and I'd really like an explanation for it.

The problem is this:
If you set an EVT_CHAR handler, and call .SetValue() rather than
event.Skip()
in it, then two (2) EVT_TEXT events always get fired. This seems like a
total bug. I've tried using wxCallAfter() to see if that fixes it, but it doesn't. I can detect the problem, so I can work around it, but it's

really annoying me and it doesn't make any sense.

Enclosed is a trivial class derivation from wxTextCtrl, demonstrating
the problem. It uses the dbg.Logger() stuff, so you can get a clear
idea of what's happening when.

Just run foo.py, type something in the text ctrl, and look at the
resulting console output. CAn you explain why is this happening???

(FTR: I'm running under MSW, Python2.2.2, wxPython 2.4.0.7p1)

There are a couple possibilities, and they both have to do with how the native control works.

First, the native control may not be testing whether the WM_CHAR message was handled and is still sending the message that gets turned into EVT_TEXT, and the one generated by the SetValue is sent also.

Secondly, sometimes a SetValue itself will generate two EVT_TEXT events. Usually it is because the wxWindows code is sending it explicitly and the native control is sending it too. The reason the wxWindows code sends it is because some versions of the MS common controls don't send it. There are so many differnet behaviours in the different versions of the common controls that we don't try to distinguish between them all because we risk sending no event in some obscure case. It's better to get two than none.

BTW, your sample on my Windows box only gets one event.

ยทยทยท

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!