The continuing adventures of 'cluelessman':
Again, using the wxValidator.py file in the demo directory -- I
simplified the Validate method as shown below:
def Validate(self, win):
"""
If the indicated line is commented out
the bell rings four times and the result
of the call is the integer 1. If left in,
the bell rings once and the integer 0 is
the result. (no error is signalled)
"""
tc = wxPyTypeCast(win, "wxTextCtrl")
wxBell()
val = tc.GetValue() #<----This fails---
wxBell()
wxBell()
wxBell()
return true
This is the new sticking point.
Review of old sticking point: per Robin's note, a validator's
Validate() method is called by wxPython when the parent window's
Validate() method is invoked (that is, the parent window of the
control to which the validator is attached -- not the control itself).
My original goal was to be able to validate the syntactic integrity of
the contents of a control such as a 'positive real number control'. A
toy version would only accept numerals and decimal point
characters. While the text is being entered, an OnChar handler could
reject any characters which were not part of the desired 'blessed
eleven characters'. However, such a handler could not verify the
presence of no more than one decimal point character in the
string. One could envision a straightforward manner of providing this
check using a slight variation of the code in the example Validate
function provided in the demo. Except, a crucial part -- extracting
the complete string from the text control -- doesn't work.
So, validating character by character works like a charm, validating
the overall contents of the control doesn't work anyway, and invoking the
validation of a given control requires asking the parent window of the
control to validate all of it's child controls.
As I say, I am clueless concerning meaningfull application of
wxValidators. Barring revelation it appears the way to proceed is to
write methods attached to EVT_KILL_FOCUS hooks on the individual
controls. By the way, when I did that I always get two consecutive events --
whether activating another control by tabbing or by mouse clicking.
Robin Dunn writes:
> > Is the Validate method of a wxPyValidator ever called?
> > I modified the demo wxValidator.py file as follows:
> >
>
> The validator's Validate method is called when the parent window's Validate
> method is called. I think this is called automatically from the handler for
> the Okay button on dialogs, but you must call it yourself elsewhere.
>
> --
> Robin Dunn
> Software Craftsman
> robin@AllDunn.com
> http://wxpython.org Java give you jitters?
> http://wxpros.com Relax with wxPython!
>
>
>
>
> _______________________________________________
> wxPython-users mailing list wxPython-users@wxwindows.org
> http://wxwindows.org/mailman/listinfo/wxpython-users
Mark Millikan