Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.perl.misc > Newsgroup comp.lang.perl.tk

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 06-07-2009, 08:39 PM
Sean
Guest
 
Posts: n/a
Default Need help with JBrowseEntry "-validatecommand"

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








Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 06-07-2009, 09:54 PM
Lamprecht
Guest
 
Posts: n/a
Default Re: Need help with JBrowseEntry "-validatecommand"

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.
Reply With Quote
  #3 (permalink)  
Old 06-07-2009, 10:14 PM
Marc Dashevsky
Guest
 
Posts: n/a
Default Re: Need help with JBrowseEntry "-validatecommand"

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.
Reply With Quote
  #4 (permalink)  
Old 06-08-2009, 12:52 AM
Sean
Guest
 
Posts: n/a
Default Re: Need help with JBrowseEntry "-validatecommand"

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.



Reply With Quote
 
Reply

Popular Tags in the Forum
jbrowseentry, validatecommand

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 12:00 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.