Overriding default bindings... 
Author Message
 Overriding default bindings...

I fear that this is simply a stupid question (one of many I ask, I'm
sure), but I'm executing the code


        $self->{$_}->bind("<Tab>", sub {\&TabNext($self, 1);});
        $self->{$_}->bind("<Shift-Tab>", sub {\&TabNext($self, -1);});
    }

By the lights of the documentation that I see, that should replace the
default bindings for any item in TabOrder.... Listboxes hate me, and
they seem to execute the default binding after mine has been executed.
Any clues on what I'm doing wrong?

For that matter, my question about getting rid of the underline
attribute on the active element in a list box is still open.... (I'm
about to offer free beer for that one.... You might want to wait if
you have an answer :))


-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2
mQCNAzGsmRcAAAEEAMZ8xr2CXGIWBPECBLD8LGWr3Yh7Gy49L0T76NgjCwUexCiW
fwF1b1GjR1flwjAGhQ6l+ktn5/JJvY7ZbYZQOFBUeQsfLz3N/MeC2HM61Hxj+qFr
F61D9A/wozvO5s+AUX7O6oIZHKavdg5UJaULiwIAGMUJHKt8f+/FO4KjJAn9AAUR
tB9CcmVudCBCLiBQb3dlcnMgPHBvd2Vyc0BtbC5jb20+
=4gxx
-----END PGP PUBLIC KEY BLOCK-----
==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the

--




Thu, 19 Nov 1998 03:00:00 GMT  
 Overriding default bindings...


Quote:
>I fear that this is simply a stupid question (one of many I ask, I'm
>sure), but I'm executing the code


>    $self->{$_}->bind("<Tab>", sub {\&TabNext($self, 1);});
>    $self->{$_}->bind("<Shift-Tab>", sub {\&TabNext($self, -1);});
>    }

>By the lights of the documentation that I see, that should replace the
>default bindings for any item in TabOrder.... Listboxes hate me, and
>they seem to execute the default binding after mine has been executed.
>Any clues on what I'm doing wrong?

Not sending complete examples for a start...


are stored in the widgets' hashes.

There are _no_ default bindings on widget objects, only default class bindings.
In perl/Tk bindtag order (not same as Tcl/Tk) is class,object,toplevel,all so
class binding  should trigger _before_ widget binding. That said Tab bindings
are on  the 'all' tag, which is indeed _after_ object bindings.

Thus if you want to inhibit default tab-traversal you need to :

A) Remove 'all' from bindtags list

or

B) Sub-class your widget(s) and override focusNext/focusPrev methods
   so that default 'all' binding calls your version of these methods.

I prefer (B) it is the OO way - "this widget is just like an Xxxx except..."

Quote:

>For that matter, my question about getting rid of the underline
>attribute on the active element in a list box is still open.... (I'm
>about to offer free beer for that one.... You might want to wait if
>you have an answer :))

You can't turn it off, and I don't want to as without it keyboard
traversal of list box (which is what active is _for_) is near impossible.

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

--




Fri, 20 Nov 1998 03:00:00 GMT  
 Overriding default bindings...

Quote:
>>>Nick Ing-Simmons said:


 > >I fear that this is simply a stupid question (one of many I ask, I'm
 > >sure), but I'm executing the code
 > >
 > >

 > >      $self->{$_}->bind("<Tab>", sub {\&TabNext($self, 1);});
 > >      $self->{$_}->bind("<Shift-Tab>", sub {\&TabNext($self, -1);});
 > >    }
 > >
 > >By the lights of the documentation that I see, that should replace the
 > >default bindings for any item in TabOrder.... Listboxes hate me, and
 > >they seem to execute the default binding after mine has been executed.
 > >Any clues on what I'm doing wrong?
 >
 > Not sending complete examples for a start...
 >

 > are stored in the widgets' hashes.
 >
 > There are _no_ default bindings on widget objects, only default class bindings.
 > In perl/Tk bindtag order (not same as Tcl/Tk) is class,object,toplevel,all so
 > class binding  should trigger _before_ widget binding. That said Tab bindings
 > are on  the 'all' tag, which is indeed _after_ object bindings.

Is there a special reason by ptk follows the tk7.4 beta binding order?
There were long discussions in the tcl news group about class,widget,...
(tcl/tk beta) and widget,class,... (final tcl/tk). If one really wants a widget
specific behaviour it much easier with widget,class,...

 > Thus if you want to inhibit default tab-traversal you need to :
 >
 > A) Remove 'all' from bindtags list

I have not used bind in ptk but wouldn't a Tk::break (sp?) in TabNext
ensure that the 'all' bindings are not invoked?

 > or
 >
 > B) Sub-class your widget(s) and override focusNext/focusPrev methods
 >    so that default 'all' binding calls your version of these methods.
 >
 > I prefer (B) it is the OO way - "this widget is just like an Xxxx except..."
                                         ^^^^^^
Isn't subclassing for one widget a bit of overkill? If one needs many
instances of a class subclassing is okay but would it hurt in this case if the
(by default empty) widget specific bindings would be looked up before class?

Achim

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

--




Fri, 20 Nov 1998 03:00:00 GMT  
 Overriding default bindings...

Quote:

>Is there a special reason by ptk follows the tk7.4 beta binding order?

Yes. For most cases it is beneficial to have class binding occur
first. Then object binding can use selected items etc.

Quote:
>There were long discussions in the tcl news group about class,widget,...
>(tcl/tk beta) and widget,class,... (final tcl/tk). If one really wants a widget
>specific behaviour it much easier with widget,class,...

I know I contributed. If you don't like default you have ->bindtags to change
it. That is easy.

However in perl/Tk sub-classing is easy and the 'right' way to change
class behaviour.

Quote:

> > Thus if you want to inhibit default tab-traversal you need to :

> > A) Remove 'all' from bindtags list

>I have not used bind in ptk but wouldn't a Tk::break (sp?) in TabNext
>ensure that the 'all' bindings are not invoked?

Okay yes $widget->break would do as well.

Quote:

> > or

> > B) Sub-class your widget(s) and override focusNext/focusPrev methods
> >    so that default 'all' binding calls your version of these methods.

> > I prefer (B) it is the OO way - "this widget is just like an Xxxx except..."
>                                         ^^^^^^
>Isn't subclassing for one widget a bit of overkill?

I don't think so.

Quote:
>If one needs many
>instances of a class subclassing is okay but would it hurt in this case if the
>(by default empty) widget specific bindings would be looked up before class?

Not at all; if you want to change bindtags for the single widget you
are at liberty to do so (as I said on c.l.tcl during debate on ordering).

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

--




Sat, 21 Nov 1998 03:00:00 GMT  
 Overriding default bindings...

The following script creates a 3x10 table of entries with a 3x5 viewing
area.  For entries in the left column, the Return key shifts focus one
entry to the right.  For the middle column, the Return key shifts focus
to the left entry on the next row down.  

So far so good.  Now the problem.  Any autoload attempts made after
Tk::Table::see in find() gets executed by the Return callback fail.  Eg.

  require(1) auto/Tk/Entry/Backspace.al failed - auto/Tk/Entry/Backspace.al d
  id not return a true value at /home/local/lib/perl5/AutoLoader.pm line 27.

The same autoloads done before Tk::Table::see gets executed work fine.
The easiest way to replicate the problem is to run the script, avoid
touching the scrollbar and click in an entry in the middle column, hit
Return, now try to backspace or use the scrollbar.  It should fail.

Now rerun the script, wave your cursor over the scrollbar, click in an
entry in the middle column, backspace, and hit return.  Now try backspace
and he scrollbar again.  It should work.

It may be helpfull to put a print or two in AutoLoader::AUTOLOAD to see
what's getting loaded when.

Any suggestions?

Mike

---8<------------------------------------------------------------------------
#!/home/local/bin/perl -w

use Tk;
use Tk::Table;
use Tk::Entry;

sub Foo::new {
    return bless {}

Quote:
}

$MAX_ITEMS = 10;  
$VIEWED_ITEMS = 5;

$f = new Foo;  # Used later for callback setup.

$top = new MainWindow();

my $t  = $top->Table(-scrollbars => 'e',
                      -rows => $VIEWED_ITEMS,
                      -columns => 3,
                      -highlightthickness => 0,
                      );
$t->pack(-expand => 1,
         -fill => 'both'
         );

### Set up the entries and bindings.

foreach $r (0..$MAX_ITEMS-1) {
    $c = 0;
    $tmp = ["0,$r","1,$r","2,$r"];

        $e = $t->Entry(-width => 5,
                       -relief => 'sunken',
                       -highlightthickness => 0,
                       -borderwidth => 1,
                       -textvariable => \$_);
        $t->put($r, $c++, $e);      
    }

    $t->get($r, 0)->bind('<Return>' => [$f, 'recalc', $r]);
    $t->get($r, 1)->bind('<Return>' => [$f, 'find', $r]);

Quote:
}

MainLoop();
exit;

sub recalc {

    print "In recalc on row $r\n";

    my $w = $t->get($r,1);
    $w->focus() ;

Quote:
}

sub find {

    print "In find on row $r\n";

    if (1 && $r < $MAX_ITEMS) {
        my $w = $t->get($r+1,0);
        $w->focus() ;
        $t->see($w);
    }

Quote:
}

-----------------------------------------------------------------------------
Mike Fisher                                     | Phone: 813-530-2732
Engineering Services Computing Environment Team |   FAX: 813-532-5244

Largo, Florida                                  |

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

--




Sun, 22 Nov 1998 03:00:00 GMT  
 Overriding default bindings...

Quote:

> The following script creates a 3x10 table of entries with a 3x5 viewing
> area.  For entries in the left column, the Return key shifts focus one
> entry to the right.  For the middle column, the Return key shifts focus
> to the left entry on the next row down.

> So far so good.  Now the problem.

Almost forgot the details.  :)

  perl 5.005
  Tk b11.02
  Solaris 2.5

Mike

-----------------------------------------------------------------------------
Mike Fisher                                     | Phone: 813-530-2732
Engineering Services Computing Environment Team |   FAX: 813-532-5244

Largo, Florida                                  |

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

--




Mon, 23 Nov 1998 03:00:00 GMT  
 Overriding default bindings...

Quote:

>The following script creates a 3x10 table of entries with a 3x5 viewing
>area.  For entries in the left column, the Return key shifts focus one
>entry to the right.  For the middle column, the Return key shifts focus
>to the left entry on the next row down.  

>So far so good.  Now the problem.  Any autoload attempts made after
>Tk::Table::see in find() gets executed by the Return callback fail.  Eg.

It is just 'see' which won't auto-load. Table's 'pod' gets auto-split
into see.al and =cut is in wrong place, so the 1; that gets added
never gets parsed so AUTOLOAD's 'require' says see.al does not return a true
value.  Here is a patch.

*** Table.pm.old        Thu Jun  6 08:58:39 1996
--- Table.pm    Thu Jun  6 09:00:22 1996
***************
*** 527,533 ****
   return $see;
  }

- =cut

  =head1 NAME

--- 527,532 ----
***************
*** 604,609 ****
--- 603,609 ----

  =back

+ =cut

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

--




Mon, 23 Nov 1998 03:00:00 GMT  
 Overriding default bindings...


Quote:

>Almost forgot the details.  :)

>  perl 5.005

            ^
Wow ! no wonder your program doesn't work, b11.02 is positively ancient.
Are you running 5.002, 5.002_01, or another patched variant thereof ?

Quote:
>  Tk b11.02
>  Solaris 2.5

--
[nosave]<http://www.eleves.ens.fr:8080/home/espie/index.html>
microsoft network is EXPLICITLY forbidden to redistribute this message.
`Seiza no matataki kazoe, uranau koi no yuku e.'



Mon, 23 Nov 1998 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. overriding tkperl default key bindings?

2. overriding default right mouse button binding for text widget

3. Overriding a certain default binding???

4. Overriding shift-tab binding..

5. Bug overriding button bindings

6. How to control default bindings?

7. tkperl default binding question !!

8. listbox default bindings

9. Changing default menubutton bindings

10. Removing default bindings?

11. Text Widget turning off default bindings

12. Changing a default binding

 

 
Powered by phpBB® Forum Software