arrow keys, focus override and strange behavior

Hi,
I’m trying to override the arrow key(UP and DOWN) built in focus function, I want to keep the focus handled only by tab key and LEFT and RIGHT keys.
I want to use UP and DOWN to increment or decrement the value of a PyControl.
When I use the keys the focus move once and then start to change the value of the just focused control, I can’t figure out why.

I’m on windows 7 64bit
I use wx 2.8.12.1 (msw-unicode)
and Python 2.7.5 32bit

Thank you for your attention.

focusError.py (4.77 KB)

esnho esnho wrote:

I'm trying to override the arrow key(UP and DOWN) built in focus
function, I want to keep the focus handled only by tab key and LEFT
and RIGHT keys.
I want to use UP and DOWN to increment or decrement the value of a
PyControl.
When I use the keys the focus move once and then start to change the
value of the just focused control, I can't figure out why.

You are experiencing an epic battle between the panel's attempt to
direct the keystrokes and your controls' attempt to direct the
keystrokes. If you remove the TAB_TRAVERSAL style from the panel,
suddenly your up and down keys will behave like you expect.

        panel.SetWindowStyle(panel.GetWindowStyle() & ~wx.TAB_TRAVERSAL)

However, once you do that, the left, right and tab keys will not shift
focus between the controls. You will have to add code to manage the
focus yourself. It shouldn't be hard.

···

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

Thank you!

I think I will handle the focus by adding my controls inside an array and navigate trought it like this wxPython .SetFocus() on ID - Stack Overflow, is it a right approach?

···

Il giorno venerdì 2 agosto 2013 19:51:44 UTC+2, Tim Roberts ha scritto:

esnho esnho wrote:

I’m trying to override the arrow key(UP and DOWN) built in focus

function, I want to keep the focus handled only by tab key and LEFT

and RIGHT keys.

I want to use UP and DOWN to increment or decrement the value of a

PyControl.

When I use the keys the focus move once and then start to change the

value of the just focused control, I can’t figure out why.

You are experiencing an epic battle between the panel’s attempt to

direct the keystrokes and your controls’ attempt to direct the

keystrokes. If you remove the TAB_TRAVERSAL style from the panel,

suddenly your up and down keys will behave like you expect.

    panel.SetWindowStyle(panel.GetWindowStyle() & ~wx.TAB_TRAVERSAL)

However, once you do that, the left, right and tab keys will not shift

focus between the controls. You will have to add code to manage the

focus yourself. It shouldn’t be hard.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.