Count Down wrote:
Hi all,
I'm trying to understand Validators in the context of wxPython. I've
been rummaging around the web without much success. I took a look at
the wxPython2.5 Validator demo. Here's what I found:1) A proper Validator needs to implement the Clone,
TransferFromWindow, TransferToWindow, and Validate methods.2) The Validator demo presents a subclass of PyValidator that
implements the Clone and Validate method, but not the other methods.3) The Validate method is never called by the demo. In particular,
all the work is being done by the OnChar method which is bound to
wx.EVT_CHAR.Given all the above, it seems the Validator demo does not demonstrate
Validators, but rather event catching. Am I missing something? It
would help me if someone could explain when and why each of the
required Validator methods is called in a real application.
Validators can have a few different roles:
* formatting or altering what is typed by manipulating the control in repsonse to the key/char events.
* character by character validation
* End of input validation
* transfering data values to/from the control when the dialog has been validated.
The first two would be implemented by handling the key/char events in the validator class, the others are done by calling Validate or Transfer[To|From]Window on the parent class. For wxDialog parents then Validate is called when the OK button is pressed and if it returns False then the dialog will not be dismissed. If it returns True then TransferFromWindow is called. Also TransferToWindow will be called when the dialog is initially shown.
ยทยทยท
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!