Here is a start. If you look at the TableMatrix.pm code, you will find the sub called Paste. You can modify it and put a start and end into it, like
sub 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";
}
Now the question becomes how to make that change part of your code, without permanently altering the module for everyone. The easiest method( but clunkiest) is to copy TableMatrix.pm to a subdir called Tk in your script's working directory. Then you can modify your TableMatrix.pm's Paste sub, and put
use lib '.';
at the top of your script. The better way, is to just redefine the sub, but you get a redefine warning.
#!/usr/bin/perl
use warnings;
no warnings "redefine";
use Tk;
use Tk::TableMatrix;
sub Tk::TableMatrix::Paste
{
print "start paste\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 paste\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;
The best way is to subclass TableMatrix.pm, but you can search how to do that yourself. Search for making a "Tk megawidget".
It's basically the same thing as I shown above, but you create a "MyTableMatrix" widget, based on TableMatrix.pm. This avoids the "redefined" warnings.
|