Text() ignored bind("<Tab>") 
Author Message
 Text() ignored bind("<Tab>")

Hi,

well, why is Tab ignored?

[code]

use Tk;
$mw = MainWindow->new();
&bug4();
&Tk::MainLoop();

sub bug4 {
  $frame = $mw->Frame()->pack(-side => "top");
  $text = $frame->Text(-width => 60, -height => 10, -wrap => "word")->
   pack(-side => "left");
  $sb = $frame->Scrollbar(-command => ["yview", $text])->pack(
   -side => "right", -fill => "y");
  $text->configure(-yscrollcommand => ["set", $sb]);
  $button = $mw->Button(-text => "...")->pack(-side => "top");

  ## IMPACT: Neither works (uncomment max. one)
  $text->bind("<Tab>", sub { $button->focus(); });
  #$text->bind("<Tab>", ["focus", $button]);

Quote:
}

[/code]

*Jan Engelhardt



Sun, 12 Sep 2004 21:57:13 GMT  
 Text() ignored bind("<Tab>")

Quote:

> use Tk;
> $mw = MainWindow->new();
> &bug4();
> &Tk::MainLoop();

> sub bug4 {
>   $frame = $mw->Frame()->pack(-side => "top");
>   $text = $frame->Text(-width => 60, -height => 10, -wrap => "word")->
>    pack(-side => "left");
>   $sb = $frame->Scrollbar(-command => ["yview", $text])->pack(
>    -side => "right", -fill => "y");
>   $text->configure(-yscrollcommand => ["set", $sb]);
>   $button = $mw->Button(-text => "...")->pack(-side => "top");

>   ## IMPACT: Neither works (uncomment max. one)
>   $text->bind("<Tab>", sub { $button->focus(); });
>   #$text->bind("<Tab>", ["focus", $button]);
> }

What about using strict, -w option and minimizing your example code as
much as possible? ;-)
I can recommend man Tk::bingtags, may be man Tk::callbacks

P.

#!/usr/bin/perl -w
use strict;
use Tk;

my $main = MainWindow->new();
my $text = $main->Text->pack;
my $button = $main->Button->pack;

# SOLUTION: Both works (uncomment max. one) ### NOTE: the second one
differs!
#$text->bind('Tk::Text', "<Tab>", sub { $button->focus(); });
$text->bind('Tk::Text', "<Tab>", [$button, "focus"]);

Tk::MainLoop;



Sun, 12 Sep 2004 23:02:40 GMT  
 Text() ignored bind("<Tab>")

Quote:
>> use Tk;
>> $mw = MainWindow->new();
>> &bug4();
>> &Tk::MainLoop();

>> sub bug4 {
>>   $frame = $mw->Frame()->pack(-side => "top");
>>   $text = $frame->Text(-width => 60, -height => 10, -wrap => "word")->
>>    pack(-side => "left");
>>   $sb = $frame->Scrollbar(-command => ["yview", $text])->pack(
>>    -side => "right", -fill => "y");
>>   $text->configure(-yscrollcommand => ["set", $sb]);
>>   $button = $mw->Button(-text => "...")->pack(-side => "top");

>>   ## IMPACT: Neither works (uncomment max. one)
>>   $text->bind("<Tab>", sub { $button->focus(); });
>>   #$text->bind("<Tab>", ["focus", $button]);
>> }

>What about using strict,

strict is to strict for my style.
"Global variable $x needs explicit" blah blah blah... aw damn that.

Quote:
> -w option

yea... -w shows me some stuff, but no errors.

Quote:
> and minimizing your example code as
>much as possible? ;-)

It is a snippet from my collection of Tk bugs, thus unoptimized.

Quote:
>I can recommend man Tk::bingtags, may be man Tk::callbacks

Well then, why does Tk::bind not work (in the way I did it)?

Quote:
># SOLUTION: Both works (uncomment max. one) ### NOTE: the second one
>differs!
>#$text->bind('Tk::Text', "<Tab>", sub { $button->focus(); });
>$text->bind('Tk::Text', "<Tab>", [$button, "focus"]);

Differs in what?... well one is a callback and one is a sub, but both do the
same.

_EVEN_ in this case (BTW: why?)

[code]
use Tk;
$m=Tk::MainWindow->new();
$m->Label(-text => "heh");
$m->Button(-text => "hitme", -command => \&subme);
&Tk::MainLoop(); # to be "strict" ;-)
sub subme {
  my $g = $m->Toplevel(); # notice the "my"
  $g->grab();
  $g->Button(-text => "hit me 2", -command =>
    sub {
      # why-T.H. is $g set (and can be destroyed) although we "my"ed it?
      $g->destroy();
    }
  );

Quote:
}

[/code]

*Jan Engelhardt
use Tk;
$m=Tk::MainWindow->new();
$m->Label(-text => "heh")->pack;
$m->Button(-text => "hitme", -command => \&subme)->pack;
&Tk::MainLoop(); # to be "strict" ;-)
sub subme {
  my $g = $m->Toplevel(); # notice the "my"
  $g->grab();
  $g->Button(-text => "hit me 2", -command =>
    sub {
      # wth is $g set (and can be destroyed) although we "my"ed it?
      $g->destroy();
    }
  )->pack;

- Show quoted text -

Quote:
}



Mon, 13 Sep 2004 05:04:42 GMT  
 Text() ignored bind("<Tab>")


Quote:
> >>   ## IMPACT: Neither works (uncomment max. one)
> >>   $text->bind("<Tab>", sub { $button->focus(); });
> >>   #$text->bind("<Tab>", ["focus", $button]);
> Well then, why does Tk::bind not work (in the way I did it)?

> ># SOLUTION: Both works (uncomment max. one) ### NOTE: the second one
> >differs!
> >#$text->bind('Tk::Text', "<Tab>", sub { $button->focus(); });
> >$text->bind('Tk::Text', "<Tab>", [$button, "focus"]);

> Differs in what?... well one is a callback and one is a sub, but both do
the
> same.

The difference is that this is a 'class' binding on 'Tk::Text'. There is an
order to the sequence that bind works for an event.
If you print out

$text->bindtags();

it will display the order that will be invoked. Normally, the 'class' one is
first. However, the Text widget has already created a class binding for
<Tab> which is to actually insert a "\t" in the text area. It then calls
'break' at the end which stops any further processing for that event ...
which is why your original bind never got called!

So your options are to redefine the 'class' binding (as Pavel has done) or
to remove the class binding (in which case your original version will be
called) or you can even change the order in which the binds will work for an
event (using bindtags).

--
Chris Eustace.



Mon, 13 Sep 2004 08:33:34 GMT  
 Text() ignored bind("<Tab>")

Quote:

>>and minimizing your example code as much as possible? ;-)

> It is a snippet from my collection of Tk bugs, thus unoptimized.

I'm afraid these "unoptimized" examples can take more time to understand
them so if one post such an example he/she risk that there will be less
people willing to understand and answer. But it's only my point of view. :-)

Quote:
>>I can recommend man Tk::bingtags, may be man Tk::callbacks

> Well then, why does Tk::bind not work (in the way I did it)?

Explained by Chris, I hope.

Quote:
> Differs in what?... well one is a callback and one is a sub, but both do the
> same.

I'm sorry, it was not too understandable - I meant the second line
differed from your one in reverting the order of $button and "focus" as
it is described in man Tk::callbacks

Quote:
> sub subme {
>   my $g = $m->Toplevel(); # notice the "my"
>   $g->grab();
>   $g->Button(-text => "hit me 2", -command =>
>     sub {
>       # why-T.H. is $g set (and can be destroyed) although we "my"ed it?
>       $g->destroy();
>     }
>   );
> }

And why not? May be I don't understand your question (and may be I do,
but I am not able to explain it in English ;-) May man perlsub and
searching Private Variables via my could explain it better to you.


Mon, 13 Sep 2004 18:32:14 GMT  
 Text() ignored bind("<Tab>")
And it ain't working, still:

use Tk;
$mw = Tk::MainWindow->new();

$frame = $mw->Frame()->pack(-side => "top");
$text = $frame->Text(-width => 50, -height => 10)->pack(-side => "left");
foreach $_ ("A".."Z") { $text->insert("end", $_ x 20 ."\n"); }
$scroll = $frame->Scrollbar(-command => ["yview", $text])->pack(-side =>
 "right", -fill => "y");
$text->configure(-ys => ["set", $scroll]);

$btn = $mw->Button(-text => "Exit", -command => ["destroy", $mw])->
 pack(-side => "top");
$text->bind("Tk::Text", "<Key-Tab>", \&focus);
$text->bind("Tk::Text", "<Tab>", \&focus);
$text->bind("<Key-Tab>", \&focus);
$text->bind("<Tab>", \&focus);
$mw->bind("Tk::MainWindow", "<Key-Tab>", \&focus);
$mw->bind("Tk::MainWindow", "<Tab>", \&focus);
$mw->bind("<Key-Tab>", \&focus);
$mw->bind("<Tab>", \&focus);

sub focus {
  $btn->focus();

Quote:
}

sub NULL { }

#EOF
None of those binds does it job.



Sun, 19 Sep 2004 19:11:10 GMT  
 Text() ignored bind("<Tab>")

Quote:
> And it ain't working, still:

Would you be more explicit.  I went back through this thread and I'm
not sure what you believe is the problem.  But ....

Quote:
> use Tk;
> $mw = Tk::MainWindow->new();
> $frame = $mw->Frame()->pack(-side => "top");
> $text = $frame->Text(-width => 50, -height => 10)->pack(-side => "left");
> foreach $_ ("A".."Z") { $text->insert("end", $_ x 20 ."\n"); }
> $scroll = $frame->Scrollbar(-command => ["yview", $text])->pack(-side =>
>  "right", -fill => "y");
> $text->configure(-ys => ["set", $scroll]);
> $btn = $mw->Button(-text => "Exit", -command => ["destroy", $mw])->
>  pack(-side => "top");
> $text->bind("Tk::Text", "<Key-Tab>", \&focus);
> $text->bind("Tk::Text", "<Tab>", \&focus);
> $text->bind("<Key-Tab>", \&focus);
> $text->bind("<Tab>", \&focus);
> $mw->bind("Tk::MainWindow", "<Key-Tab>", \&focus);
> $mw->bind("Tk::MainWindow", "<Tab>", \&focus);
> $mw->bind("<Key-Tab>", \&focus);
> $mw->bind("<Tab>", \&focus);
> sub focus {
>   $btn->focus();

Does it work with the following line added?

    $btn->break;

Quote:
> }
> sub NULL { }
> #EOF
> None of those binds does it job.

Steve

'other perl hacker';$z='createText';$c=$m->Canvas(-wi,$_[1],-he,25)->grid;$c->$
En'.
'ter>',sub{$y=int(rand($m->screenheight));$m->geometry("+$y+$y")});MainLoop;


Sun, 19 Sep 2004 20:42:01 GMT  
 Text() ignored bind("<Tab>")

Quote:
>Does it work with the following line added?

>    $btn->break;

Yes; what does that break do?

*Jan Engelhardt



Mon, 20 Sep 2004 01:17:26 GMT  
 Text() ignored bind("<Tab>")

Quote:

>> Does it work with the following line added?

>>    $btn->break;

> Yes; what does that break do?

It's halts Tk's search through the bindtags list.  Explained fully in the
perldoc docs and MPTK.  Essentially, it keeps the class tab binding from
being invoked.

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Mon, 20 Sep 2004 02:16:32 GMT  
 Text() ignored bind("<Tab>")

Quote:

>> Does it work with the following line added?

>>    $btn->break;

> Yes; what does that break do?

As a follow up to my previous answer, the tab binding is *not* a class
binding.

Continuing my Tk::bindDump discussion from the InsertKeypress() thread,
here's the end of the binding dump of a Text widget. We can see the event
descriptors for the last three binding tags - note that tab is in the 'all'
  list, which follows the instance binding(s) you made.  break()
short-circuits the bindtags search such that the Toplevel and 'all' binding
tags are bypassed ...

Quote:
>                                    'NoOp'
>                      <<Paste>> : Tk::Callback=SCALAR(0xa8296c)
>                                    'clipboardPaste'
>                        <<Cut>> : Tk::Callback=SCALAR(0xa82954)
>                                    'clipboardCut'
>                       <<Copy>> : Tk::Callback=SCALAR(0xa8293c)
>                                    'clipboardCopy'

> 2. Binding tag '.text' has no bindings.

> 3. Binding tag '.' has no bindings.

> 4. Binding tag 'all' has these bindings:
>                      <Key-F10> : Tk::Callback=SCALAR(0x8678e4)
>                                    'FirstMenu'
>                      <Alt-Key> : Tk::Callback=ARRAY(0x8677b8)
>                                    'TraverseToMenu'

> Tk::Ev=SCALAR(0x860ae0)                 : 'K'
>                    <<LeftTab>> : Tk::Callback=SCALAR(0x8678a8)
>                                    'focusPrev'
>                      <Key-Tab> : Tk::Callback=SCALAR(0x867884)
>                                    'focusNext'

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Mon, 20 Sep 2004 02:28:02 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Binding the <Tab> key in Text

2. Tk::Dialog "text width" Please Ignore

3. One question about useage "<>"

4. My <!--#exec cgi="\scripts\script.pl"-->command will not work

5. system("ed <stuff>")

6. About <SCRIPT language="PerlScript">

7. <input type="text" value="$string"> problems

8. <input type="text" value="$string"> problems

9. libwww Accept->"text/plain"

10. perl -pe "s/<er>/<er>\n"/g": memory efficient version?

11. <<<<<< HELP >>>>>>>>

 

 
Powered by phpBB® Forum Software