RE: [wxperl-users] Re: wxValidator available via wxPerl

Dear Mattia (or others, if they can help),
I've been delving into how to use wxValidators, and I think I understand the
concept (and I like it!).

However, I'm having real trouble deriving my own validator (called,
unimaginitively, myValidator) from Wx::PlValidator.

>From the wxWindows documentation, all validators must implement a Clone
method.  I have tried implementing a Clone method, which I can see getting
called, but myValidator's Validate, TransferFromWindow, and TransferToWindow
never seem to get called.

Here is my code (with the methods apart from Clone doing nothing useful
apart from printing to STDOUT):

VVVVVVVVVVVVVVVVVVVV
use Wx;

package myValidator;

use vars qw(@ISA); @ISA = qw(Wx::PlValidator);

sub new {
 my $class = shift;
 my $this = $class->SUPER::new();

    return $this;
}

# see the docs for the three following functions
sub TransferFromWindow {

    print "TransferFromWindow called\n";
    return 1;
}

sub TransferToWindow {

    print "TransferToWindow called\n";
    return 1;

}

sub Validate {

    print "Validate called\n";

    return 1;
}

sub Clone {

    my $this= 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 = myValidator->new;
    return $tmp;

}
1;

^^^^^^^^^^^^

A code snip from my main program, where I'm trying to test the validator,
looks like this:

vvvvvvvvvvvvvvvvvv
    # add wxValidator for the raw text, using the getter generated by
wxDesigner
    my $objText = $this->txtRaw;

    my $sText = 'Hello';

    # note that the constructor for myValidator does nothing with arguments
yet
    my $vldTmp = myValidator->new(0,\$sText);

    $objText->SetValidator($vldTmp);

    # various attempts to get the validator to kick in!
    $this->TransferDataToWindow();
    $this->TransferDataFromWindow();
    $objText->Validate();
^^^^^^^^^

However, I do not see the validator's methods being invoked.

Could you post a very simple example of how to create a validator class in
Perl, and how to create a frame which uses it, please?

Thanks a lot,

James Lavery
MicroSec Ltd/Monthtwo Systems Ltd


0
james
1/23/2014 1:01:01 AM
perl.wxperl.users 3070 articles. 0 followers. Follow

1 Replies
665 Views

Similar Articles

[PageSpeed] 9

--Message-Boundary-29577
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body

> Dear Mattia (or others, if they can help),
> I've been delving into how to use wxValidators, and I think I understand the
> concept (and I like it!).
> 
> However, I'm having real trouble deriving my own validator (called,
> unimaginitively, myValidator) from Wx::PlValidator.
> 
> >From the wxWindows documentation, all validators must implement a Clone
> method.  I have tried implementing a Clone method, which I can see getting
> called, but myValidator's Validate, TransferFromWindow, and TransferToWindow
> never seem to get called.
> 
> Here is my code (with the methods apart from Clone doing nothing useful
> apart from printing to STDOUT):
> 
> VVVVVVVVVVVVVVVVVVVV
> use Wx;
> 
> package myValidator;
This is OK ( in fact the sample I sant uses this code )

> ^^^^^^^^^^^^
> 
 
> Could you post a very simple example of how to create a validator class in
> Perl, and how to create a frame which uses it, please?
Here is your example ( modified minimal sample, use Help->About to
show the validator dialog )

I am getting a "Attempt to free unreferenced scalar at 
C:/Developement/wxPerl/wxPerl/blib/lib/Wx.pm line 61.", 
which I was not getting when I first tested Validators.
It is obviously something I am doing wrong with reference
counting in wxPerl; will fix.

A caveat: do not use a validator after you did
->SetValidator(); for implementation reasons,
once you do ->SetValidator() it is no more valid.

Regards
Mattia




--Message-Boundary-29577
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Text from file 'minimal.pl'

#!/usr/bin/perl
#############################################################################
## Name:        minimal.pl
## Purpose:     Minimal wxPerl sample
## Author:      Mattia Barbon
## Modified by:
## Created:     29/10/2000
## RCS-ID:      
## Copyright:   (c) 2000 Mattia Barbon
## Licence:     This program is free software; you can redistribute it and/or
##              modify it under the same terms as Perl itself
#############################################################################

use Wx;

# every program must have a Wx::App-derive class
use Wx;

package myValidator;

use vars qw(@ISA); @ISA = qw(Wx::PlValidator);

sub new {
  my $class = shift;
  my $this = $class->SUPER::new();

  return $this;
}

# see the docs for the three following functions
sub TransferFromWindow {

    print "TransferFromWindow called\n";
    return 1;
}

sub TransferToWindow {

    print "TransferToWindow called\n";
    return 1;

}

sub Validate {

    print "Validate called\n";

    return 1;
}

sub Clone {

    my $this= 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 = myValidator->new;
    return $tmp;

}

package MyApp;

use strict;
use vars qw(@ISA);

@ISA=qw(Wx::App);

# this is called automatically on object creation
sub OnInit {
  my( $this ) = @_;

  # create new MyFrame
  my( $frame ) = MyFrame->new( "Minimal wxPerl app",
			       Wx::Point->new( 50, 50 ),
			       Wx::Size->new( 450, 350 )
                             );

  # set it as top window (so the app will automatically close when
  # the last top window is closed)
  $this->SetTopWindow( $frame );
  # show the frame
  $frame->Show( 1 );

  1;
}

package MyDialog;

use strict;
use vars qw(@ISA); @ISA = qw(Wx::Dialog);

use Wx qw(wxID_OK wxID_CANCEL);

sub new {
  my $class = shift;
  my $this = $class->SUPER::new( undef, -1, "MyDialog", [20,20],[200,200] );

  my $text = Wx::TextCtrl->new( $this, -1, "ABC",[10,10] );

  $text->SetValidator( myValidator->new );
  Wx::Button->new( $this, wxID_OK, "OK",[10,40] );
  Wx::Button->new( $this, wxID_CANCEL, "Cancel",[100,40] );
  $this->TransferDataToWindow;

  return $this;
}

package MyFrame;

use strict;
use vars qw(@ISA);

@ISA=qw(Wx::Frame);

use Wx::Event qw(EVT_MENU);
use Wx qw(wxBITMAP_TYPE_ICO wxMENU_TEAROFF);

# Parameters: title, position, size
sub new {
  my( $class ) = shift;
  my( $this ) = $class->SUPER::new( undef, -1, $_[0], $_[1], $_[2] );

  # load an icon and set it as frame icon
  $this->SetIcon( Wx::GetWxPerlIcon() );

  # create the menus
  my( $mfile ) = Wx::Menu->new( undef, wxMENU_TEAROFF );
  my( $mhelp ) = Wx::Menu->new();

  my( $ID_ABOUT, $ID_EXIT ) = ( 1, 2 );
  $mhelp->Append( $ID_ABOUT, "&About...\tCtrl-A", "Show about dialog" );
  $mfile->Append( $ID_EXIT, "E&xit\tAlt-X", "Quit this program" );

  my( $mbar ) = Wx::MenuBar->new();

  $mbar->Append( $mfile, "&File" );
  $mbar->Append( $mhelp, "&Help" );

  $this->SetMenuBar( $mbar );

  # declare that events coming from menu items with the given
  # id will be handled by these routines
  EVT_MENU( $this, $ID_EXIT, \&OnQuit );
  EVT_MENU( $this, $ID_ABOUT, \&OnAbout );

  # create a status bar (note that the status bar that gets created
  # has three panes, see the OnCreateStatusBar callback below
  $this->CreateStatusBar( 2 );
  # and show a message
  $this->SetStatusText( "Welcome to wxWindows!", 1 );

  $this;
}

# this is an addition to demonstrate virtual callbacks...
# it ignores all parameters and creates a status bar with three fields
sub OnCreateStatusBar {
  my( $this ) = shift;
  my( $status ) = Wx::StatusBar->new( $this, -1 );

  $status->SetFieldsCount( 3 );

  $status;
}

# called when the user selects the 'Exit' menu item
sub OnQuit {
  my( $this, $event ) = @_;

  # closes the frame
  $this->Close( 1 );
}

use Wx qw(wxOK wxICON_INFORMATION wxVERSION_STRING);

# called when the user selects the 'About' menu item
sub OnAbout {
  my( $this, $event ) = @_;

  my $dlg = MyDialog->new;
  $dlg->ShowModal;
  $dlg->Destroy;
  # display a simple about box
  Wx::MessageBox( "This is the about dialog of minimal sample.\n" .
		  "Welcome to wxPerl " . $Wx::VERSION . "\n" .
		  wxVERSION_STRING,
		  "About minimal", wxOK | wxICON_INFORMATION,
		  $this );
}

package main;

# create an instance of the Wx::App-derived class
my( $app ) = MyApp->new();
# start processing events
$app->MainLoop();

# Local variables: #
# mode: cperl #
# End: #

--Message-Boundary-29577--

0
mbarbon
1/23/2014 1:01:01 AM
Reply:

Similar Artilces:

RE: [wxperl-users] Re: wxValidator available via wxPerl
Mattia, Thanks, as usual, for the to-the-point and quick support! If/when I manage to produce a useful validator, I would be more than happy to submit it. Currently I'm still getting my head round how everything fits together! James > -----Original Message----- > From: Mattia Barbon [mailto:mbarbon@dsi.unive.it] > Sent: 13 December 2001 11:04 > To: wxperl-users@lists.sourceforge.net > Subject: [wxperl-users] Re: wxValidator available via wxPerl >=20 >=20 > > Dear Mattia, > > I would like to use validators in my Perl application, but=20 ...

RE: [wxperl-users] Re: wxValidator available via wxPerl #2
Dear Mattia, Thanks - this works a treat! I was so close... Anyway, now I'm up and running. I had noticed the 'Attempt to free unreferenced...' error - will await a fix. Now that I've got things working, what do you suggest/would you like? I feel that validators are the way to go when it comes to transferring data to/from controls (rather than explicit GetValue/SetValue calls all over the place) - I have had to implement a similar concept (though not as elegant) in a very large Perl/Tk application which we have developed. I see that you think we should create...

RE: [wxperl-users] Re: wxValidator available via wxPerl #4
Mattia, > > Yes, I think a Perl-implemented GenericValidator can just take the > > address of the variable to/from which to deposit/get data, and can > > handle it appropriately internally by checking the reference type. > the trouble is that in perl you can only have scalar references, > so you need a flag to tell the class you want a number/string/bool > transferred Good point. I think I'll use the 'flag' approach. This has approach has been used elsewhere (in Win32::API, I think), so I'll try to be consistent with other modules. =20 ...

RE: [wxperl-users] Re: wxValidator available via wxPerl #3
> wxTextValidator is OK for Perl, while wxGenericValidator does > 1 - use overloading > wxGV construtor takes one of a int/bool/string/integer array > (C++) pointer ( think Perl references ), but in Perl > int/string/bool map to scalar. Yes, I think a Perl-implemented GenericValidator can just take the address of the variable to/from which to deposit/get data, and can handle it appropriately internally by checking the reference type. > 2 - there is no NumericValidator ( or whatever you want to call it ) > one that does a text->number conversio...

Re: [wxperl-users] Re: wxperl
yes !! its really time to help more mattia. things i could offer are beside bug reports is to help to buil a better brwosable doku, this is one of my long time wish so are so. herbert "Graciliano M. P." <gmpowers@terra.com.br> schrieb am 11.12.04 03:29:27: > > > hey all, > > > > I just tried downloading the cvs snapshot, Wx-0.20, Wx-0.19, and Wx-0.18 > > and trying to install them on solaris (without luck). I tried both > wxAll-2.4.2 > > and wxWidgets-2.5.3. > > > > Furthermore, I went to the wikis for more in...

[wxperl-users] wxValidator available via wxPerl
Dear Mattia, I would like to use validators in my Perl application, but am not clear whether they have been wrapped. Are they available? Thanks, James Lavery MicroSec Ltd > -----Original Message----- > From: Mattia Barbon [mailto:mbarbon@dsi.unive.it] > Sent: 08 December 2001 13:31 > To: wxperl-users@lists.sourceforge.net > Subject: Re: [wxperl-users] wxPerl tutorial at the German=20 > Perl Workshop >=20 >=20 > > As you might have heard already I will be giving a half-day=20 > tutorial on > > wxPerl at the German Perl Workshop. Th...

Fwd: wxPerl on the Mac; was: [wxperl-users] Re: problems with wxPerl
>To: Jouke Visser <jouke@pvoice.org>, wxperl-users@lists.sourceforge.net >From: Christian Jaeger <christian.jaeger@sl.ethz.ch> >Subject: wxPerl on the Mac; was: [wxperl-users] Re: problems with wxPerl >Date: Sun, 30 Sep 2001 23:08:19 +0100 > >Hello, > >I'm crossposting this reply to the macosx-perl mailing list because >there is some interest, too. Actually I forgot to put the macosx-perl adress on it. >At 14:02 Uhr +0200 24.9.2001, Jouke Visser wrote: >>I wondered if anyone yet tried to compile wxPerl on a Mac. If not, I'...

Re:[wxperl-users] Re: wxPerl 0.23 release
> Mattia Barbon <mattia.barbon@libero.it> writes: > > > On Tue, 28 J= un 2005 22:44:29 +0200 Johan Vromans <jvromans@squirrel.nl> wrote:=0D = > > Under Windows the change in the default font is to > > be expected= .. > > I'm using Fedora Core 2... :-) I suppose I could not be m= ore wrong... Anyway: the font change looks like a GTK+ 1.2 vs 2.x ch= ange. For the button width you should try the wxBU_EXACTFIT style fo= r the buttons that need to be smaller than standard buttons. HTH=0D = Mattia =0A=0A=0A...

RE: Re: [wxperl-users] Re: Re: EVT_QUERY_END_SESSION
you putted the EVT_CLOSE to the wrong place... or do you have a reason why you need it to be there? $app ist not the window, but you could use EVT_CLOSE on $frame too. i changed your minimal sample that it works. hope it helps greeting Marco ---- use Wx; ########################### package MyApp; use strict; use vars qw(@ISA); @ISA=qw(Wx::App); sub OnInit { my( $this ) = @_; my( $frame ) = MyFrame->new( "Minimal wxPerl app", Wx::Point->new( 50, 50 ), Wx::Size->new( 450, 350 ) ); ...

RE: Re[4]: [wxperl-users] [OT, or maybe not?] wxPerl T-Shirt?
What about an ASCII art camel on top (assuming O'Reilly gives a thumbs = up). Then a "use Wx;" Then a very nice graphical camel below. Then "It's _almost_ that easy!" (or something like that). --Toby Ovod-Everett -----Original Message----- From: Marcus [mailto:lists@wordit.com] Sent: Sunday, July 27, 2003 3:53 PM To: wxperl-users@lists.sourceforge.net Subject: Re[4]: [wxperl-users] [OT, or maybe not?] wxPerl T-Shirt? Sunday, July 27, 2003, 9:18:13 PM, you wrote: DH> checkout DH> http://www.cafeshops.com/wxwindows ...

Re: [wxperl-users] wxPerl on Gentoo
we both assumed too negative, please look here: http://www.gentoo.org/doc/en/ebuild-submit.xml this information you should also give on your site regards herbert ...

RE: [wxperl-users] wxPerl and Printing
VB users would rate things like Active Reports and VPE (Virtual Print = Engine). Both very capable systems and better than Crystal for many = uses, but obviously depends on your ability to use ActiveX controls in = your project. =20 Ed W -----Original Message----- From: Mark Wardell [mailto:mark@netcontrol.co.za] Sent: 13 August 2003 11:42 To: wxperl-users@lists.sourceforge.net Subject: [wxperl-users] wxPerl and Printing Hi All, This is a fairly broad topic, but I am interested to hear what experiences other users have had with printing from wxPerl applications, as well...

RE: [wxperl-users] MozEmbed and WxPerl
I have tested the Mozilla ActiveX plugin using the Wx::ActiveX module = and it works (have google in a Wx right now). =20 =20 Since I haven't gotten around to fixing the Wx::ActiveX module (as per a = discussion some time ago), you would need to use the Win32::OLE = compatible object from GetOLE() for some of the method and property = calls. =20 Unfortunately, as with all things ActiveX, it is Windows centric and may = not be what you are looking for. =20 Anyway, the Wx::ActiveX::Mozilla package would look something like this: =20 package Wx::ActiveX::Mozilla; use Wx::ActiveX...

Re: [wxperl-users] wxperl on MacOSX
> Hello Hello > Tough I'm a bit in doubt > whether wxperl will work on the mac (primarily MacOSX, MacOS9 would > be cool too)? There are various problems: 1 - I don't have a Mac, so someone else shoild work on it ( any takers? ;-) ) 2 - wxWindows on MacOS X is still not as stable as the Windows/GTK ports, though it is progressing steadily, and the developers are generally very responsive WRT bugreports; on MacOS 9 it should be pretty stable though 3 - On MacOS 9 you need to use Codewarrior which isn't free If you want to give it a tr...

Web resources about - RE: [wxperl-users] Re: wxValidator available via wxPerl - perl.wxperl.users

O'Reilly Open Source Convention 2007 • July 23-27, 2007 • Portland, Oregon
O'Reilly Open Source Convention 2007 - July 23-27, 2007 - Portland, Oregon

Resources last updated: 12/26/2015 1:22:08 AM