wx.PyValidator.Validate(self, win)

Is it necessary for the Validate() method to have the ‘win’ argument? In the wxPython demo, I don’t see any use of that argument in the function override. And also, what is this method actually for? What is the true nature of it?

I use the Validate method in two ways, taken from the demo. Okay, I
only use one, actually. The first way to use a validator is to limit
the acceptable key strokes. The other is to check the value in the
control at a certain time.

Depending on which method is used, different things get passed to the
win argument, as far as I can tell.

Consider a panel with a TextCtrl in it, and that control has a validator.

When binding the EVT_CHAR to the validator (as in the Demo), I use
CallAfter to use the Validate command after every keystroke and color
the the control accordingly. This requires a window argument, I pass
the results from the validators GetWindow() method, which is the text
control itself.

However, when I run the Validate method of the panel, the panel is
passed as the win argument.

I don't know why it behaves this way, but that's what I'm seeing.

That's why even in a Validate() method I use GetWindow() to get the
actual text control.

Josh

···

On Sun, Dec 26, 2010 at 5:48 AM, Boštjan Mejak <bostjan.mejak@gmail.com> wrote:

Is it necessary for the Validate() method to have the 'win' argument? In the
wxPython demo, I don't see any use of that argument in the function
override. And also, what is this method actually for? What is the true
nature of it?

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
Josh English
Joshua.R.English@gmail.com

This has not answered my question fully.

Yes, the win argument is required. This argument gets generated
automatically when wxPanel.Validate() is called.

Validate is used to determine if the value in a control is acceptable,
and so some method should be used to determine if the value is
acceptable.

The demo uses the examples of only accepting letters or digits, but
Validate could also be used to determine if a number was in a given
range, if an email address is properly formed, etc.

My guess is the win argument isn't used in the demo because there's no
guarantee that the Validate(win) method will get the actual control,
or the parent panel of that control.

Josh

···

On Sun, Dec 26, 2010 at 1:52 PM, Boštjan Mejak <bostjan.mejak@gmail.com> wrote:

This has not answered my question fully.

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
Josh English
Joshua.R.English@gmail.com

Is it necessary for the Validate() method to have the 'win' argument? In
the wxPython demo, I don't see any use of that argument in the function
override.

If you don't like it don't use it.

It is the window for which the original Validate() call was made. I think as the code currently is implemented that will always be the parent of the widget that the validator is attached to, so I guess you could just think of it as a convenience so save you having to call self.GetWindow().GetParent(). See the implementation of wxWindow::Validate at wxTrac has been migrated to GitHub Issues - wxWidgets

And also, what is this method actually for? What is the true
nature of it?

The validator's Validate method is what makes the determination of whether the value in the associated widget is valid or not.

···

On 12/26/10 5:48 AM, Bo�tjan Mejak wrote:

--
Robin Dunn
Software Craftsman

How can I avoid having a wx.EVT_CHAR event in the init of the validator? Doesn’t it suffice if I have it in the Validate method and the “if key in string.letters” stuff as well?

If you don't need character-by-character validation, or any manipulation of the typed characters, then don't bind the event. The Validate method will be called automatically when the user clicks the Ok button if the parent window is a dialog, or you can cause it to be invoked by calling the parent's Validate method if you want to check the validity of the widgets on the form in other situations as well.

···

On 12/27/10 3:42 AM, Bo�tjan Mejak wrote:

How can I avoid having a wx.EVT_CHAR event in the __init__ of the
validator? Doesn't it suffice if I have it in the Validate method and
the "if key in string.letters" stuff as well?

--
Robin Dunn
Software Craftsman

For character-by-character validation I don’t actually need a validator. I can bind the wx.EVT_CHAR event to the wx.TextCtrl’s widget. In the handler I simply do the

if keyChar in string.digits: do some validation

if keychar in string.alpha: do some validation

Is there any need for a validator?

For character-by-character validation I don’t actually need a validator. I can bind the wx.EVT_CHAR event to the wx.TextCtrl’s widget. In the handler I simply do the
if keyChar in string.digits: do some validation

if keychar in string.alpha: do some validation

Is there any need for a validator?

wlEmoticon-smile[1].png

···

From: Boštjan Mejak

Sent: Tuesday, December 28, 2010 9:41 AM

To: wxpython-users@googlegroups.com

Subject: Re: [wxPython-users] wx.PyValidator.Validate(self, win)


To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Not really because you have written your own. Smile

Gadget/Steve

Doing it in a validator is an easy way to apply the same functionality to multiple widgets, or even multiple types of widgets, without needing to derive a new class for each of them or whatever. In other words, it is one way to help you follow the OOP principle of encapsulation.

···

On 12/28/10 1:41 AM, Bo�tjan Mejak wrote:

For character-by-character validation I don't actually need a validator.
I can bind the wx.EVT_CHAR event to the wx.TextCtrl's widget. In the
handler I simply do the
if keyChar in string.digits: do some validation
if keychar in string.alpha: do some validation

Is there any need for a validator?

--
Robin Dunn
Software Craftsman

Robin, why isn’t the ‘win’ argument used in the Demo at all? It is just there. Can it be an error not to have it? I don’t see any error not having the ‘win’ argument in my overridden Validate method. Please give more info on this.

Try removing the win parameter from TextObjectValidator.Validate and see what happens. Watch the stderr output when you click Ok on the test dialog.

···

On 12/29/10 7:10 AM, Bo�tjan Mejak wrote:

Robin, why isn't the 'win' argument used in the Demo at all? It is just
there. Can it be an error not to have it? I don't see any error not
having the 'win' argument in my overridden Validate method. Please give
more info on this.

--
Robin Dunn
Software Craftsman