Can I alter when a bind is used or is that something 'deep' in the tablematrix code?

Yes, there are a couple of ways to do it. Some sample code is shown in the ReadMore below.

The first method, is a bit crude, and requires a no warnings "redefine";. You just copy in the sub(s) you want to redefine, obtained from perldoc -m Tk::TableMatrix, into your script, and rewrite the sub(s) anyway you want.

The second, better method, is to create a custom package widget, which allows you to redefine any sub, without generating warnings.

I'm not sure which sub would need to be redefined, or if redefining it may break something else, like possibly the action of hitting the Enter key on a cell. A second package method using ClassInit is also shown, and may be needed to catch $mw bindings.

Redefining a sub:
#!/usr/bin/perl use warnings; no warnings "redefine"; use Tk; use Tk::TableMatrix; sub Tk::TableMatrix::Paste { print "start\n"; my $w = shift; my $cell = shift || ''; ## Perltk not sure if translated correctly my $data; if ($cell ne '') { eval{ $data = $w->GetSelection(); }; return if($@); } else { eval{ $data = $w->GetSelection('CLIPBOARD'); }; return if($@); $cell = 'active'; } $w->PasteHandler($w->index($cell),$data); $w->focus if ($w->cget('-state') eq 'normal'); print "end\n"; } my $top = MainWindow->new; my $arrayVar = {}; foreach my $row (0..20){ foreach my $col (0..10){ $arrayVar->{"$row,$col"} = "r$row, c$col"; } } my $t = $top->Scrolled('TableMatrix', -rows => 21, -cols => 11, -width => 6, -height => 6, -titlerows => 1, -titlecols => 1, -variable => $arrayVar, -selectmode => 'extended', -resizeborders => 'both', -titlerows => 1, -titlecols => 1, -bg => 'white', # -state => 'disabled' # -colseparator => "\t", # -rowseparator => "\n" ); $t->tagConfigure('active', -bg => 'gray90', -relief => 'sunken'); $t->tagConfigure( 'title', -bg => 'gray85', -fg => 'black', -relief => + 'sunken'); # $t->bind("<Any-Enter>", sub { $t->focus }); $t->pack(-expand => 1, -fill => 'both'); Tk::MainLoop;

Creating a custom package: (shown with a Tk::Text widget as example ) which allows you to redefine a sub, without warnings.

#!/usr/bin/perl use warnings; use strict; use Tk; package Tk::MyText; require Tk::Text; use base qw/Tk::Text/; Construct Tk::Widget 'MyText'; sub InsertKeypress { my($w, $char) = @_; if (ord($char) < 27) { print chr(ord($char) | 0x40), "\n"; # only Control-G/J/L/M/Q/R/S/U/W/Y/Z are making it to here } else { $w->SUPER::InsertKeypress($char); } } package main; my $top = tkinit; my $text = $top->MyText->pack; $text->eventAdd('<<Bogus>>' => '<Control-Key-G>','<Control-Key-g>'); $text->bind('<<Bogus>>', sub { $text->insert('end'," <-- How do I supress this?\n") }); print $text->eventInfo('<<Bogus>>'); MainLoop;
and a second package version, which uses ClassInit to gain access to the $mw bindings too.
#!/usr/bin/perl use warnings; use strict; use Tk; package Tk::MyText; require Tk::Text; use base qw/Tk::Text/; Construct Tk::Widget 'MyText'; sub ClassInit { print "ClassInit [@_]\n"; my($class,$mw) = @_; $class->SUPER::ClassInit($mw); $mw->bind($class,'<Control-KeyPress>','NoOp'); $class; } ##################################################### package main; my $top = tkinit; my $text = $top->MyText->pack; $text->eventAdd('<<Bogus>>' => '<Control-Key-G>','<Control-Key-g>'); $text->bind('<<Bogus>>', sub { $text->insert('end'," <-- How do I supress this?\n") }); print $text->eventInfo('<<Bogus>>'); MainLoop;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re^7: Table matrix suspected selected cell discrepancy by zentara
in thread Table matrix suspected selected cell discrepancy by merrymonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.