How to get a validator to work in a frame

But why is it even getting to that line in the first place? Shouldn't
the validator kick in before it even tries the conversion? If so, then
it will test to see if the length of the input is 0, and if it is a
message box should pop up. But my code seems to skip validation all
together, so there must be something I'm doing wrong even before I get
to the int conversion line.

···

---------- Forwarded message ----------
From: "SPE Stani's Python Editor" <spe.stani.be@gmail.com>
To: wxPython-users@lists.wxwidgets.org
Date: Fri, 28 Jul 2006 18:03:19 +0200
Subject: Re: [wxPython-users] How to get a validator to work in a frame
On 7/28/06, John Salerno <johnjsal@gmail.com> wrote:

I think it has nothing to do with wxPython. Probably you are trying to
convert an empty string into an integer. You should first get the
value as a string and test if it is not empty before converting to an
integer.

Hi John,

I got it to work, but frankly I don't understand why it did not work in the first place.

Kept a reference to the panel, and then called validate on the panel. Ah, maybe that is the problem, maybe you need to use the "wxWS_EX_VALIDATE_RECURSIVELY" on your frame.

Also noticed that the validator init is called twice but the cloned is only done once, again can't explain this.

You still need to validate that user does not enter alpha characters.

You might want to look at the masked controls, there is a IntCtrl and or MaskedNumCtrl (see the demo under More Windows/Controls).

Changed version attached.

Werner

validator.py (4.13 KB)