Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Tab Order for Widgets in HList

by Anonymous Monk
on Oct 19, 2011 at 14:59 UTC ( #932428=note: print w/ replies, xml ) Need Help??


in reply to Re: Tab Order for Widgets in HList
in thread Tab Order for Widgets in HList

I'm not sure what is going on, but its something :)

tab x 5, enter x 10

#!/usr/bin/perl -- use Tk; use strict; use warnings; #changes focus on Return(Enter) key but not Tab my $win = MainWindow->new(); my $foo = $win->Entry(qw' -text $foo ')->pack; my $bar = $win->Entry(qw' -text $bar ')->pack; my $baz = $win->Entry(qw' -text $baz ')->pack; my $boo = $win->Entry(qw' -text $boo ')->pack; my $baa = $win->Entry(qw' -text $baa ')->pack; &defineOrder($foo,$baa,$bar,$boo,$baz); DumpBindtags($win, $foo,$baa,$bar,$boo,$baz); print " $win = \$win $foo = \$foo $bar = \$bar $baz = \$baz $boo = \$boo $baa = \$baa "; sub DumpBindtags { for my $o ( @_ ) { print "$o bindtags ( ", join ' , ' , $o->bindtags, " )\n"; } } sub defineOrder { my $widget; for (my $i=0; defined( $_[$i+1] ); $i++) { $_[$i]->bind('<Key-Return>', [\&focus, $_[$i+1]]); # won't work with Tab $_[$i]->bind('all', '<Tab>', [\&focus, $_[$i+1]]); #~ $_[$i]->bind( '<Tab>', [\&focus, $_[$i+1]]); ## in order tra +versal } # Uncomment this line if you want to wrap around $_[$#_]->bind('<Key-Return>', [\&focus, $_[0]]); $_[0]->focus; } sub focus { warn "focus @_\n"; my ($tk, $self) = @_; $self->focus; Tk::break(); } MainLoop(); __END__
MainWindow=HASH(0xe911ac) bindtags ( MainWindow , . , all , ) Tk::Entry=HASH(0xed9414) bindtags ( Tk::Entry , .entry , . , all , ) Tk::Entry=HASH(0xed96b4) bindtags ( Tk::Entry , .entry4 , . , all , ) Tk::Entry=HASH(0xed95f4) bindtags ( Tk::Entry , .entry1 , . , all , ) Tk::Entry=HASH(0xed9664) bindtags ( Tk::Entry , .entry3 , . , all , ) Tk::Entry=HASH(0xed9644) bindtags ( Tk::Entry , .entry2 , . , all , ) MainWindow=HASH(0xe911ac) = $win Tk::Entry=HASH(0xed9414) = $foo Tk::Entry=HASH(0xed95f4) = $bar Tk::Entry=HASH(0xed9644) = $baz Tk::Entry=HASH(0xed9664) = $boo Tk::Entry=HASH(0xed96b4) = $baa focus Tk::Entry=HASH(0xed9414) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9414) focus Tk::Entry=HASH(0xed9414) Tk::Entry=HASH(0xed96b4) focus Tk::Entry=HASH(0xed96b4) Tk::Entry=HASH(0xed95f4) focus Tk::Entry=HASH(0xed95f4) Tk::Entry=HASH(0xed9664) focus Tk::Entry=HASH(0xed9664) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9414) focus Tk::Entry=HASH(0xed9414) Tk::Entry=HASH(0xed96b4) focus Tk::Entry=HASH(0xed96b4) Tk::Entry=HASH(0xed95f4) focus Tk::Entry=HASH(0xed95f4) Tk::Entry=HASH(0xed9664) focus Tk::Entry=HASH(0xed9664) Tk::Entry=HASH(0xed9644)

This works

sub defineOrder { my $widget; for (my $i=0; defined( $_[$i+1] ); $i++) { $_[$i]->bind( '<Key-Return>', [\&focus, $_[$i+1]]); $_[$i]->bind( '<Tab>', [\&focus, $_[$i+1]]); } # Uncomment this line if you want to wrap around $_[ $#_ ]->bind('<Key-Return>', [\&focus, $_[0]]); $_[ $#_ ]->bind('<Tab>', [\&focus, $_[0]]); $_[0]->focus; }

Using defineOrder($win, $foo,$baa,$bar,$boo,$baz); eliminates the need for the wraparound portion


Comment on Re^2: Tab Order for Widgets in HList
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://932428]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2015-07-31 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls