|
|||
|
Hi Folks,
I am using Tk::JBrowseEntry in my script and am having a difficult time implementing the "-validatecommand" to validate the user input. What I need to do: 1- Ignore the user input, if is not an integer in the range 1 to 4 2- In the case were the user choice results a duplicate choice in the two boxes, blank the "other" input box. Below is my code ----------------------------- use Tk; use Tk::LabFrame; use Tk::JBrowseEntry; use warnings; use strict; my $mw = MainWindow->new(); $mw->optionAdd('*font', 'Tahoma 8'); my $f1 = $mw->Frame()->pack(); my @JB = ( 1, 2 ); my $dash_len = 35; $f1->JBrowseEntry( -label => 'P', -variable => \$JB[0], -choices => [qw(1 2 3 4)], -width => 2, -textbackground => 'white', -labelPack=>[-side=>'left'], -validatecommand => sub{ return $JB[0] =~ /(1|2|3|4)/o; }, )->pack( -side => 'left'); $f1->Label( -text => 'O'.'-'x$dash_len .'O',-fg => 'red2' )->pack( -side => 'left'); $f1->JBrowseEntry( -label => 'P', -variable => \$JB[1], -choices => [qw(1 2 3 4)], -width => 2, -textbackground => 'white', -labelPack=>[-side=>'right'], -validate => 'key', -validatecommand => sub{ return $JB[1] =~ /(1|2|3|4)/o; }, )->pack( -side => 'left'); MainLoop; ---------------------- Regards, -Sean |
|
|
||||
|
||||
|
|
|
|||
|
Sean wrote:
> Hi Folks, > > I am using > Tk::JBrowseEntry in my script and am having a difficult time implementing > the "-validatecommand" to validate the user input. > > What I need to do: > 1- Ignore the user input, if is not an integer in the range 1 to 4 > 2- In the case were the user choice results a duplicate choice in the two > boxes, blank the "other" input box. Hi, here is a suggestion for 2: -browsecmd => sub{ if ($JB[0] == $JB[1]){$JB[1] = ''} } > > $f1->JBrowseEntry( -label => 'P', > -variable => \$JB[1], > -choices => [qw(1 2 3 4)], > -width => 2, > -textbackground => 'white', > -labelPack=>[-side=>'right'], > -validate => 'key', > -validatecommand => sub{ return $JB[1] =~ /(1|2|3|4)/o; }, -browsecmd => sub{ if ($JB[0] == $JB[1]){$JB[0] = ''} } > )->pack( -side => 'left'); What are you trying to do? Cheers, Christoph -- Tk::EntrySet display/edit a list of values in a Set of Widgets. Tk::ChoicesSet display/edit a list of choices in a Set of single-selection Widgets. |
|
|||
|
In article <JzVWl.25349$as4.22863@nlpi069.nbdc.sbc.com>, imfeaw5672@pacbell.net says...
> Hi Folks, > > I am using > Tk::JBrowseEntry in my script and am having a difficult time implementing > the "-validatecommand" to validate the user input. > > What I need to do: > 1- Ignore the user input, if is not an integer in the range 1 to 4 > 2- In the case were the user choice results a duplicate choice in the two > boxes, blank the "other" input box. Here's one way: The first JBrowseEntry widget needs the following options: -validate => 'all', -validatecommand => [\&NoDups, 0], The second JBrowseEntry widget needs the following options: -validate => 'all', -validatecommand => [\&NoDups, 1], Create the following sub: sub NoDups { my($id, $proposed, $added, $current, $index, $type) = @_; # note that "" is now valid and that ^ and $ are now included return 0 unless $proposed =~ /^(|1|2|3|4)$/o; my $other = !$id; $JB[$other] = '' if $JB[$other] eq $proposed; return 1; } > Below is my code > ----------------------------- > use Tk; > use Tk::LabFrame; > use Tk::JBrowseEntry; > > use warnings; > use strict; > > my $mw = MainWindow->new(); > $mw->optionAdd('*font', 'Tahoma 8'); > > my $f1 = $mw->Frame()->pack(); > > my @JB = ( 1, 2 ); > my $dash_len = 35; > > $f1->JBrowseEntry( -label => 'P', > -variable => \$JB[0], > -choices => [qw(1 2 3 4)], > -width => 2, > -textbackground => 'white', > -labelPack=>[-side=>'left'], > -validatecommand => sub{ return $JB[0] =~ /(1|2|3|4)/o; }, > )->pack( -side => 'left'); > > $f1->Label( -text => 'O'.'-'x$dash_len .'O',-fg => 'red2' )->pack( -side => > 'left'); > > $f1->JBrowseEntry( -label => 'P', > -variable => \$JB[1], > -choices => [qw(1 2 3 4)], > -width => 2, > -textbackground => 'white', > -labelPack=>[-side=>'right'], > -validate => 'key', > -validatecommand => sub{ return $JB[1] =~ /(1|2|3|4)/o; }, > )->pack( -side => 'left'); > > > MainLoop; > > ---------------------- > > Regards, > > -Sean > > > > > > > > > -- Go to http://MarcDashevsky.com to send me e-mail. |
|
|||
|
Hi Christoph,
This is small part of a UI that can manipulate multiple multi port touchstone files and extend the port count of the resulting data. Regards, -Sean "Lamprecht" <ch.l.ngre-nospam@online.de> wrote in message news:h0hcu6$15j$1@online.de... > Sean wrote: >> Hi Folks, >> >> I am using >> Tk::JBrowseEntry in my script and am having a difficult time implementing >> the "-validatecommand" to validate the user input. >> >> What I need to do: >> 1- Ignore the user input, if is not an integer in the range 1 to 4 >> 2- In the case were the user choice results a duplicate choice in the two >> boxes, blank the "other" input box. > > > > Hi, > > > here is a suggestion for 2: > > -browsecmd => sub{ > if ($JB[0] == $JB[1]){$JB[1] = ''} > } > > > > > $f1->JBrowseEntry( -label => 'P', > > -variable => \$JB[1], > > -choices => [qw(1 2 3 4)], > > -width => 2, > > -textbackground => 'white', > > -labelPack=>[-side=>'right'], > > -validate => 'key', > > -validatecommand => sub{ return $JB[1] =~ /(1|2|3|4)/o; }, > -browsecmd => sub{ > if ($JB[0] == $JB[1]){$JB[0] = ''} > } > > )->pack( -side => 'left'); > > > What are you trying to do? > > Cheers, Christoph > > -- > Tk::EntrySet > display/edit a list of values in a Set of Widgets. > Tk::ChoicesSet > display/edit a list of choices in a Set of single-selection Widgets. |
|
|
![]() |
| Popular Tags in the Forum |
| jbrowseentry, validatecommand |
| Thread Tools | |
| Display Modes | |
|
|