Is it possible to add a validator to a wxSpinCtrl?

You can call SetValidator after creation. But since it is a composite
control it may not behave entirely as expected so you may want to
instead use a separate wxSpinButton and a wxTextCtrl.

I have been trying several things, none of them are 100% satisfactory so far.

1) Using wxSpinCtrl and calling SetValidator() on it after its creation. I
could not get the validator to work.

2) Using a separate wxSpinButton and wxTextCtrl.
2.1) If i specify the validator as one argument to the wxSpinButton, then the
validation is invoked properly.
2.2) If i don't but call SetValidator() later, it does not seem to work (with
nothing else changed but the constructor call and the call to SetValidator())

3) The nice thing about being able to use the wxSpinCtrl is that the user can
hit the Up/Down arrow keys and use the accelarator key of some other buttons and
the focus can stay on the Spin control button.

For now, I got my dialog to work with a wxSpinButton and wxTextCtrl, the
validator works fine and the spin value is updated when the text is changed
(something the wxSpinButton demo does not do).
The only issue i therefore have with the code right now is that it's not
possible to leave the focus on the spin button when the number in the text field
is changed by the spin button.
This feature would allow the user to use the Up/Down arrow keys to change the
value, then use an accelerator key to perform a function using that value, all
without having to move the mouse.
I tried to SetFocus() on the wxSpinButton() after a wxSpinButton event or a text
event but that does not seem to work.
Any ideas?

So far, I am amazed how easy it is to get thing going with wxPython! And i
really appreciate the help I am getting as a newbie.

Thanks!

···

--

Pierre Rouleau

Pierre_Rouleau@ImpathNetworks.com wrote:

For now, I got my dialog to work with a wxSpinButton and wxTextCtrl, the
validator works fine and the spin value is updated when the text is changed
(something the wxSpinButton demo does not do).
The only issue i therefore have with the code right now is that it's not
possible to leave the focus on the spin button when the number in the text field
is changed by the spin button.
This feature would allow the user to use the Up/Down arrow keys to change the
value, then use an accelerator key to perform a function using that value, all
without having to move the mouse.
I tried to SetFocus() on the wxSpinButton() after a wxSpinButton event or a text
event but that does not seem to work.
Any ideas?

What if you catch the EVT_KEY_DOWN on the text ctrl and process the up/down arrow keys there too?

So far, I am amazed how easy it is to get thing going with wxPython! And i
really appreciate the help I am getting as a newbie.

All I ask is that you return the favor and help another newbie someday. :slight_smile:

···

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