|
From: James L. <jl...@bi...> - 2003-04-11 06:00:34
|
Dear Mark,
Attached should be the validator stuff I got working.
There are three classes:
base class Validator
derived class TextValidator
derived class GenericValidator
The base class provides the basic methods needed - including the
all-important Clone method.
The TextValidator provides basic validation for text controls. It allows
validation either by specifying a regexp pattern, or a reference to a
subroutine to call at runtime like this:
$this->GetTextDateFormat->SetValidator(Wx::Perl::TextValidator->new(variable
=> \$TFFC_main::aSettings{general}{date_format},
validate => \&main::validate_date,
));
so that we don't have to create lots of different subclassed Validators for
each type of validation (i.e. one for date validation, one for zip code,
etc). This works very well.
The GenericValidator is a start on, well, a generic validator. It handles
Wx::TextCtrl, Wx::CheckBox, Wx::Choice, and Wx::RadioBox so far. The
property choice_value determines whether the string value of the control or
its selected item is returned/set - I think! (It's a long time since I
looked at all this).
I'm afraid the pod/documentation is sparse if not non-existent. However,
here's a synopsis:
use Wx::Perl::GenericValidator;
use Wx::Perl::TextValidator;
...
# set up validators for the filter checkboxes
$this->GetCheckboxQif->SetValidator(Wx::Perl::GenericValidator->new(variable
=> \$aFilters{qif}));
$this->GetCheckboxDelimited->SetValidator(Wx::Perl::GenericValidator->new(va
riable => \$aFilters{delimited}));
$this->GetCheckboxMT940->SetValidator(Wx::Perl::GenericValidator->new(variab
le => \$aFilters{MT940}));
# a generic validator returning the index for a Wx::Choice
$this->FindWindow( $main::ID_CHOICE_ACCOUNT_TYPE )
->SetValidator(Wx::Perl::GenericValidator->new(variable =>
\$this->{qifDef}->{nAcct_type},
choice_value
=>'index'));
Note that I'm using wxDesigner, so this generates the ->Get... routines.
If you have any questions, please let me know. It would be great if you
could progress the development on this - I've been sidetracked onto other
projects at the moment, so have not got the time. I'm happy to review/help
with what you do.
Regards,
James
|