strat has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
when I use -validate with Tk::Entry, I get unexpected behaviour in combination with -textvariable and changing the variable. For this example, I used a button to change the variable $entryText which should succeed until the value of 3 and fail for bigger values.
#! /usr/bin/perl use warnings; use strict; use Tk; my $entryText = 1; print "Perl-Version: $]\nTk-Version: $Tk::VERSION\n"; my $mw = MainWindow->new(); my $entry = $mw->Entry( -textvariable => \$entryText, -validate => 'all', -validatecommand => \&ValidateCmd, ) ->pack( -side => 'left' ); $mw->Button( -text => 'increase', -command => sub { $entryText++ }, ) ->pack( -side => 'right' ); MainLoop; sub ValidateCmd { my( $newValue ) = @_; { local $" = '] ['; no warnings 'uninitialized'; print "ARGS: [@_]\n"; } # return error if value > 3 and don't change the content if( $newValue > 3 ) { print "Error: Too big: $newValue\n"; return 0; } # if return 1; } # ValidateCmd
With Perl 5.008008 and Tk 804.024:
Perl-Version: 5.008003 Tk-Version: 800.024 ARGS: [1] [] [] [-1] [-1] ARGS: [2] [] [1] [-1] [-1] ARGS: [3] [] [2] [-1] [-1] ARGS: [4] [] [3] [-1] [-1] Error: Too big: 4 ARGS: [4] [] [3] [-1] [-1] Error: Too big: 4 ARGS: [4] [] [3] [-1] [-1] Error: Too big: 4
everything works fine, but with Perl-Versions >= 5.008008 and Tk Version 800.027 the validation stops when the first 0 is returned and so bigger values than 3 can be inserted via $entryText:
Perl-Version: 5.008008 Tk-Version: 804.027 ARGS: [1] [] [] [-1] [6] ARGS: [2] [] [1] [-1] [6] ARGS: [3] [] [2] [-1] [6] ARGS: [4] [] [3] [-1] [6] Error: Too big: 4
and the variable may become bigger than 3 since the validation stops. Additionally, the interface of validatecommand is changed (-1 vs. 6 for the same type of action which could break a lot of existing apps).
From perldoc Tk::Entry:
The validateCommand will turn itself off by setting validate to none when an error occurs, for example when the validateCommand or invalidCommand encounters an error in its script while evaluating, or validateCommand does not return a valid boolean value.
But returning 0 (or undef or nothing) is no error in my eyes.
Is this a bug, or am I the bug?
Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Bug: Tk::Entry 804.027 validate?
by graff (Chancellor) on Jul 02, 2007 at 11:52 UTC | |
Re: Bug: Tk::Entry 804.027 validate?
by zentara (Archbishop) on Jul 02, 2007 at 13:27 UTC | |
by strat (Canon) on Jul 07, 2007 at 09:39 UTC | |
by zentara (Archbishop) on Jul 07, 2007 at 15:41 UTC |