How to get a validator to work in a frame

Thanks. So is Clone called implicitly? There’s no call for it, even if that’s the reason init is called twice. Could I just use a pass statement in the Clone body, or does it need functionality?

Also, do you know why it didn’t work when I set the recursive flag and called Validate on self?

Thanks.

···

---------- Forwarded message ----------
From: Robin Dunn <
robin@alldunn.com>
To: wxPython-users@lists.wxwidgets.org
Date: Mon, 31 Jul 2006 09:33:00 -0700
Subject: Re: [wxPython-users] How to get a validator to work in a frame

John Salerno wrote:

---------- Forwarded message ----------
From: “Werner F. Bruhin” <
werner.bruhin@free.fr>
To: wxPython-users@lists.wxwidgets.org
Date: Sat, 29 Jul 2006 09:05:31 +0200

Subject: Re: [wxPython-users] How to get a validator to work in a frame
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

Thanks. I also tried to set the recursive flag and call Validate on
self (the frame), but that still didn’t work. Your method works,
however, by calling it on the panel. But I don’t understand either why

init is called twice. The validator is created when the TextCtrl
is, but other than that I don’t see when init would get called
again.

Probably when its Clone method is called.


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

John Salerno wrote:

Thanks. So is Clone called implicitly? There's no call for it, even if that's the reason __init__ is called twice. Could I just use a pass statement in the Clone body, or does it need functionality?

The validators are cloned when they are assigned to the control. I agree that this doesn't make much sense from a Python perspective, but it does in C++.

Also, do you know why it didn't work when I set the recursive flag and called Validate on self?

Validate doesn't do anything with self's validator, only the children's validators. The recursive flag only causes it to also call the children's Validate method so the validators of the grandchildren will also be checked.

···

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