Fellow Monks,
I'm trying to build myself a handy little define-the-keyboard-traversal-path method for a Tk-app i'm doing right now that i may call like this:
&defineOrder(\$widget1, \$widget2, \$widget3)
my first brainstorm produced this:
sub defineOrder
{
for (my $i = 0; defined($_[$i+1]); $i++)
{
${$_[$i]}->bind('<Return>', sub { ${$_[$i+1]}->focus } );
}
${$_[0]}->focus;
}
...which - of course - wont do, because my forgetful, confused program of course doesn't remember what @_ looked like the moment i binded that anon-sub to this event.
so i tried this: (methinks this is ugly)
&defineOrder(qw/$widget1 $lwidget2 $widget3/);
sub defineOrder
{
for (my $i = 0; defined($_[$i+1]); $i++)
{
my $evalString = $_[$i]."->bind( '<Return>', sub { ".$_[$i+1].
+"->focus } );";
print "$evalString\n";
eval $evalString;
print "$@\n" if $@;
}
}
...which, in turn, wont do since the widgets seem to be out of scope inside the sub (as they should be).
anybody have an idea what i can do about this?
i'm not really into using $widget->focusNext since i simply don't like the notion of the focusorder being defined by the order i pack-ed or place-ed the widgets.
(or is there any way to re-shuffle the stacking order?)
wanting to see the light of knowledge, but feeling as if he were inside a black hole,
-schweini
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.