TextCtrl - processing enter key

683 views
Skip to first unread message

ErwinP

unread,
Dec 14, 2011, 2:53:41 PM12/14/11
to wxPython-users
Hello

I want to make a text-control that uses a model object that
receives the value of the text-control when either the focus
is lost or when the enter key is pressed.
I made my own class derived from wx.TextCtrl that binds the
events EVT_KILL_FOCUS and EVT_TEXT_ENTER (requires style
TE_PROCESS_ENTER).
In the event-handlers for these events I copy the value from the
control to the model.

Unfortunately when I use TE_PROCESS_ENTER, the enter key does not
switch the focus to the next text-control. I removed the
TE_PROCESS_ENTER
style. The result is that pressing enter switches the focus to the
next control and the event-handler to commit the value is still
called
(not in EVT_TEXT_ENTER but in EVT_KILL_FOCUS).
This works when I use more than one control. But when I use only one
control, the enter key does not switch focus and the EVT_TEXT_ENTER
is also missing.

Does anybody know a way to catch the enter-key in an event-handler AND
to
allow the enter-key to switch the focus to the next control ?

I am using wx-2.8.10.1, python-2.6.4, windows vista sp2

Cody

unread,
Dec 14, 2011, 3:07:56 PM12/14/11
to wxpytho...@googlegroups.com
Hi,

You need to handle the navigation to the next control in your text
enter handler when you are processing the enter key yourself
(TE_PROCESS_ENTER).

@see: wx.Window.Navigate

def OnEnter(self, evt):
evt.EventObject.Navigate() # move to next control


Cody

ErwinP

unread,
Dec 14, 2011, 3:26:12 PM12/14/11
to wxPython-users
Hello,

Thank you for your quick response, it works !

Erwin

sebastián lópez

unread,
Oct 26, 2014, 10:16:47 PM10/26/14
to wxpytho...@googlegroups.com
Hi

I'm using wxpython '3.0.0.0' and python  2.7.8 32bit and i want to use this behabiour but it fails
So when I press the tab control the selection doesn't change.

A append an example.
defaultTxtTest.py

Nathan McCorkle

unread,
Oct 27, 2014, 3:57:18 PM10/27/14
to wxpytho...@googlegroups.com


On Sunday, October 26, 2014 7:16:47 PM UTC-7, sebastián lópez wrote:
Hi

I'm using wxpython '3.0.0.0' and python  2.7.8 32bit and i want to use this behabiour but it fails
So when I press the tab control the selection doesn't change.

Add a Panel and then place your widgets (TextCtrl, etc) on that, then it works for me. You would have less overhead processing if you used EVT_FOCUS_SET and EVT_KILL_FOCUS to check for when to set defaults, rather than on each keypress. It would also be more understandable and easy to maintain if you used the TextCtrl style TE_PROCESS_ENTER to check for return/enter presses, rather than checking manually (because using TE_PROCESS_ENTER checks all this in compiled C++ code, rather than Python). 

Sebastian López

unread,
Oct 28, 2014, 7:52:14 AM10/28/14
to wxpytho...@googlegroups.com

I made the changes and it works fine for me!

--
You received this message because you are subscribed to a topic in the Google Groups "wxPython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/ckx3pa3BWgk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

textCtrlDefaultText.png
defaultTxtTest.py
Reply all
Reply to author
Forward
0 new messages