[wxPython] leaving wxTextCtrl

Hi wxUsers :slight_smile:

I have to questions concerning leaving wxTextCtrl:

1. I would like to move the focus to the next widget after hitting ENTER ?

2. after entering the n-th character the focus automaticaly moves to the next
widget.

Thankyou for sugestions.

Przemek G.

I have to questions concerning leaving wxTextCtrl:

1. I would like to move the focus to the next widget after hitting ENTER ?

Use the wxTE_PROCESS_ENTER style and move to the next field in a
EVT_TEXT_ENTER event handler.

2. after entering the n-th character the focus automaticaly moves to the

next

widget.

Catch the EVT_TEXT event and move to the next field if you have n characters
in the field.

···

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

Use the wxTE_PROCESS_ENTER style and move to the next field in a
EVT_TEXT_ENTER event handler.

> 2. after entering the n-th character the focus automaticaly moves to the

next

> widget.

Catch the EVT_TEXT event and move to the next field if you have n
characters in the field.

Yes, but what method do I use to go the next control (in enabled control
list) ?

Some kind of aCtrl.GetNextEnabledWindow().SetFocus() ?

Przemysław G. Gawroński wrote:

Use the wxTE_PROCESS_ENTER style and move to the next field in a
EVT_TEXT_ENTER event handler.

2. after entering the n-th character the focus automaticaly moves to the

next

widget.

Catch the EVT_TEXT event and move to the next field if you have n
characters in the field.

Yes, but what method do I use to go the next control (in enabled control list) ?

Some kind of aCtrl.GetNextEnabledWindow().SetFocus() ?

Inserting the following code snippet into the event handler should work, but is somewhat of a hack, since wxNavigationKeyEvent is not documented:

  (I had to work out the details by looking at the src/generic/panelg.cpp and src/msw/window.cpp in the wxWindows source code)

n = wxNavigationKeyEvent()
n.SetDirection(1)
n.SetWindowChange(0)
n.SetEventObject(None)
# really, this should be the event emitter, but its only compared
# against the panel's parent to see if the event is propogating
# downward, so None seems to work
wxPostEvent(self.GetParent(), n)
# assumes that the panel containing the is my parent

Anyone know a better way to do this?

David

David C. Fox wrote:

Przemysław G. Gawroński wrote:

Use the wxTE_PROCESS_ENTER style and move to the next field in a
EVT_TEXT_ENTER event handler.

2. after entering the n-th character the focus automaticaly moves to the

next

widget.

Catch the EVT_TEXT event and move to the next field if you have n
characters in the field.

Yes, but what method do I use to go the next control (in enabled control list) ?

Some kind of aCtrl.GetNextEnabledWindow().SetFocus() ?

Inserting the following code snippet into the event handler should work, but is somewhat of a hack, since wxNavigationKeyEvent is not documented:

(I had to work out the details by looking at the src/generic/panelg.cpp and src/msw/window.cpp in the wxWindows source code)

n = wxNavigationKeyEvent()
n.SetDirection(1)
n.SetWindowChange(0)
n.SetEventObject(None)
# really, this should be the event emitter, but its only compared
# against the panel's parent to see if the event is propogating
# downward, so None seems to work
wxPostEvent(self.GetParent(), n)
# assumes that the panel containing the is my parent

Anyone know a better way to do this?

David

Once again, if I had looked more carefully at the source code before replying, I would have come up with a better solution.

panel.GetChildren() will get a list of the panel's children in the tab order. Then you can search through the list to find the child in which enter was pressed, and call the SetFocus method of the next child in the list. I've attached a sample code.

David

nextfield2.py (1.89 KB)