TextCtrl - processing enter key

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

TextCtrl - processing enter key

ErwinP
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

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: TextCtrl - processing enter key

Cody Precord
Hi,

On Wed, Dec 14, 2011 at 1:53 PM, ErwinP <[hidden email]> wrote:

> 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 ?
>

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

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: TextCtrl - processing enter key

ErwinP
Hello,

Thank you for your quick response, it works !

Erwin

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: TextCtrl - processing enter key

sebastian lópez
In reply to this post by ErwinP
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.

El miércoles, 14 de diciembre de 2011 14:53:41 UTC-5, ErwinP escribió:
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

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

defaultTxtTest.py (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: TextCtrl - processing enter key

Nathan McCorkle


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). 

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: TextCtrl - processing enter key

sebastian lópez

I made the changes and it works fine for me!

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Nathan McCorkle
Sent: lunes, 27 de octubre de 2014 02:57 p.m.
To: [hidden email]
Subject: [wxPython-users] Re: TextCtrl - processing enter key

 



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). 

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

defaultTxtTest.py (2K) Download Attachment
textCtrlDefaultText.png (7K) Download Attachment