From: Marcus <li...@wo...> - 2002-07-05 12:11:16
|
I think the vaildators are a good idea. If I understand the concept correctly, then this is how Perl/Tk works, only you have no choice. The downside is that when you "bind" a variable to a control, then any changes while you are working with the variable appear immediately in the GUI. An example that caused me and my beta tester many many hours of grief is the following. I had to escape backslashes when storing paths in a config file, in the GUI they were unescaped. As you can imagine unescaped backslashes can cause amazing problems when let loose. The only workaround was to keep copying variables back and forth, and making lots of temp variables. Only a word of warning, which should be at the top of the docs, in form of a "When to use..". Otherwise, I am in favour of the validators, since they can be very useful. Marcus |
From: Mark W. <ma...@ne...> - 2003-03-20 07:13:37
|
Hi, Please help, I am getting nowehere with these validators!! - Does anyone have any more information on them or working source? - Why was the PlValidator implemented instead of the Wx::Validator? - How do I actually pass data To and From the window controls? - Do I have to manually code the TransferDataToWindow for every panel in a notebook or can I call InitDialog for the dialog containing the notebook sizer? I tried this but no luck (nothing happened). I have attached my simple version of a validator. TIA Mark Wardell -------------------------------------------------------------------- package My::Validator; use vars qw(@ISA); @ISA = qw( Wx::PlValidator ); sub new { my $class = shift; my $self = $class->SUPER::new; $self->{data} = shift; return $self; } # see the docs for the three following functions sub TransferFromWindow { my $self = shift; print "TransferFromWindow called\n"; return 1; } sub TransferToWindow { my $self = shift; print "[TransferToWindow] data=${$self->{data}}\n"; #print "TransferToWindow called\n"; return ${$self->{data}}; } sub OnChar { my $self = shift; print "[Validator] OnChar called\n"; return 1; } sub Validate { my $self = shift; print "Validate called\n"; return 1; } sub Clone { my $self = shift; #print "Clone called\n"; # clone by creating a new object, which should, in the real class, have copies of all # properties of $this # could/should we use something like Storable::dclone here?? my $tmp = MOM::Validator->new($self->{data}); return $tmp; } #--------------------------------------------------------------------------- --- 1; # always return this |
From: Mattia B. <mb...@ds...> - 2003-03-20 08:40:45
|
On Thu, 20 Mar 2003, Mark Wardell wrote: >Hi, > >Please help, I am getting nowehere with these validators!! >- Does anyone have any more information on them or working source? >- Why was the PlValidator implemented instead of the Wx::Validator? Implementation details. I caould explain in more detail, but I don't think they are interesting for users. >- How do I actually pass data To and From the window controls? It depends from the control... for a Wx::TextCtrl you use GetValue/SetValue, for other controls, other methods. >- Do I have to manually code the TransferDataToWindow for every panel in a >notebook or can I call InitDialog for the dialog containing the notebook >sizer? I tried this but no luck (nothing happened). my $dlg = MyDialog->new( ... ); $dlg->SetExtraStyle( $dlg->GetExtraStyle | wxWS_EX_VALIDATE_RECURSIVELY ); This is off the top of my head, sorry if it is wrong. >I have attached my simple version of a validator. It looks correct to me (but I haven't wxPerl to test it, here). Regards Mattia |
From: James L. <jl...@bi...> - 2002-07-05 15:59:25
|
Hi Marcus, Validators are similar to, but not the same as, Perl/Tk. As you say, in Perl/Tk, changes to the underlying variable immediately appear in the Tk widget - a great feature but also a source of problems, as you have found. However, I think that Wx validators only transfer the data to the control when $window->TransferDataToWindow is called, and back again when $window->TransferDataFromWindow is called. (I'll check this out with some trials). For wxDialogs, these are both called automatically as part of Dialog initialisation and dismissal (TransferDataFromWindow is only called when the modal result is wxID_OK, I think). Hence, using wxValidators we have an inbuilt mechanism whereby our variables are only updated when the user OK's the window (and validation is implemented, too!). I ended up having to wrap my Tk widgets and windows in my own objects to achieve this sort of functionality for a large (200 screens plus) system I've been developing/supporting. If only I'd known about wxWindows at the time... It's so much more consistent in its approach than Tk... One feature I'm thinking of implementing is the ability to supply a callback for the TransferToWindow and TransferFromWindow wxValidator methods, so that we can supply data from object methods and pump data back into object methods, rather than having to rely on variable addresses. (Most of my Perl code is OO, and so I want to be able to use property accessors, rather than property addresses). Enough jabbering from me.... James ----- Original Message ----- From: "Marcus" <li...@wo...> To: <wxp...@li...> Sent: 05 July 2002 13:11 Subject: [wxperl-users] Validators > I think the vaildators are a good idea. If I understand the concept > correctly, then this is how Perl/Tk works, only you have no choice. > > The downside is that when you "bind" a variable to a control, then any > changes while you are working with the variable appear immediately in > the GUI. An example that caused me and my beta tester many many hours > of grief is the following. I had to escape backslashes when storing > paths in a config file, in the GUI they were unescaped. As you can > imagine unescaped backslashes can cause amazing problems when let > loose. The only workaround was to keep copying variables back and > forth, and making lots of temp variables. > > Only a word of warning, which should be at the top of the docs, in form > of a "When to use..". Otherwise, I am in favour of the validators, > since they can be very useful. > > Marcus > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Bringing you mounds of caffeinated joy. > http://thinkgeek.com/sf > _______________________________________________ > wxperl-users mailing list > wxp...@li... > https://lists.sourceforge.net/lists/listinfo/wxperl-users |