Problem with RichTextCtrl Event Handling

For testing purposes, I'm trying to print in the console everything that I
write in a RichTextCtrl. However, it isn't working. Here is the way I wrote
the binding for the RichTextCtrl, called textArea:

*self.textArea.Bind( wx.EVT_KEY_DOWN, self.syntaxColoring_C )*

And here is the event handler:

*def syntaxColoring_C( self, event ):
    print self.textArea.GetValue()*

However, when I type something, only a blank line is printed in the console,
and nothing appears written in the RichTextCtrl. What am I doing wrong?
Thanks in advance.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Problem-with-RichTextCtrl-Event-Handling-tp5724135.html
Sent from the wxPython-users mailing list archive at Nabble.com.

My guess is that you are not passing the key event on properly. Try adding “event.Skip ()” to your event handlers.

David

···

On May 5, 2015 7:12 PM, “stdq” fernando.karpinski@gmail.com wrote:

For testing purposes, I’m trying to print in the console everything that I

write in a RichTextCtrl. However, it isn’t working. Here is the way I wrote

the binding for the RichTextCtrl, called textArea:

self.textArea.Bind( wx.EVT_KEY_DOWN, self.syntaxColoring_C )

And here is the event handler:

*def syntaxColoring_C( self, event ):

print self.textArea.GetValue()*

However, when I type something, only a blank line is printed in the console,

and nothing appears written in the RichTextCtrl. What am I doing wrong?

Thanks in advance.

View this message in context: http://wxpython-users.1045709.n5.nabble.com/Problem-with-RichTextCtrl-Event-Handling-tp5724135.html

Sent from the wxPython-users mailing list archive at Nabble.com.

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

stdq wrote:

For testing purposes, I'm trying to print in the console everything that I
write in a RichTextCtrl. However, it isn't working. Here is the way I wrote
the binding for the RichTextCtrl, called textArea:

*self.textArea.Bind( wx.EVT_KEY_DOWN, self.syntaxColoring_C )*

And here is the event handler:

*def syntaxColoring_C( self, event ):
    print self.textArea.GetValue()*

However, when I type something, only a blank line is printed in the console,
and nothing appears written in the RichTextCtrl. What am I doing wrong?

Your event handlers are first in line. You get control before anything
else is done. In this case, your handler is called before the RTC has
seen the message, so the text will not have changed. Further, unless
you call event.Skip(), your handler will be the ONLY one called, so the
RTC itself never sees the character.

Also, remember that the RTC might not take any action on a "key down"
message at all. With keystrokes, the control has to choose between "key
down", "key up", and "char", and each one has its pros and cons. It may
be more useful for you to look at EVT_RICHTEXT_CHARACTER.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Thanks, both of you.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Re-Problem-with-RichTextCtrl-Event-Handling-tp5724136p5724160.html
Sent from the wxPython-users mailing list archive at Nabble.com.