PyValidator: Validation of one dialog field against another field in the same dialog?

22 views
Skip to first unread message

Bob Klahn

unread,
Nov 18, 2017, 6:38:48 PM11/18/17
to wxPython users
How does one create a dialog that allows one field in that dialog to be
validated (presumably using PyValidator) against a different field in
that same dialog?  Possible?

If that is possible, would someone please point me to a simple example
that does that?

I'm using wxPython 3.0.2.0 msw (classic) with Python 2.7.13.

Bob

Steve Barnes

unread,
Nov 19, 2017, 12:42:28 AM11/19/17
to wxpytho...@googlegroups.com
Bob,

I can't think of any specific examples out there but I have done similar
in the past and IIRC the trick was to, in the Validate method:

ctrl = self.GetWindow() # Get the control to validate
dlg = ctrl.GetParent() # Get the dialogue it is a part of
option = dlg.SomeOtherControl.GetValueOrSelection()

Then validate based on option, note that depending on the layout of your
dialogue you may have to do more than one GetParent and you will need to
know, (or check for the presence of), the name of the control that you
are deciding how to validate, etc.

Hope that is some help.


--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

---
This email has been checked for viruses by AVG.
http://www.avg.com

Bob Klahn

unread,
Nov 19, 2017, 12:33:21 PM11/19/17
to wxpytho...@googlegroups.com
On 11/19/2017 12:42 AM, Steve Barnes wrote:
> On 18/11/2017 23:38, Bob Klahn wrote:
>> How does one create a dialog that allows one field in that dialog to be
>> validated (presumably using PyValidator) against a different field in
>> that same dialog?  Possible?
>>
>> If that is possible, would someone please point me to a simple example
>> that does that?
>>
>> I'm using wxPython 3.0.2.0 msw (classic) with Python 2.7.13.
>>
>> Bob
>>
> Bob,
>
> I can't think of any specific examples out there but I have done similar
> in the past and IIRC the trick was to, in the Validate method:
>
> ctrl = self.GetWindow() # Get the control to validate
> dlg = ctrl.GetParent() # Get the dialogue it is a part of
> option = dlg.SomeOtherControl.GetValueOrSelection()
>
> Then validate based on option, note that depending on the layout of your
> dialogue you may have to do more than one GetParent and you will need to
> know, (or check for the presence of), the name of the control that you
> are deciding how to validate, etc.
>
> Hope that is some help.
Aargh!  I've done this kind of thing many, many times, just not with a
validator.  Major brain failure!  Feeling my age.  :-(
Thanks, Steve.

Bob

Reply all
Reply to author
Forward
0 new messages