I am updating a data entry application in which the user can key in
arbitary data into a multi-column form. TableMatrix seems to be the way
to do this in Perl/Tk. In the existing application, the user can either
enter data, or they can prefix the data with a symbol, which then calls
a lookup routine. A drop-down is unsuitable, as the user must be able
to enter data in the application, and at the end, the program creates
the lookup automatically (based on criteria - not all data is indexed).
Thanks!
--
Trog Woolley | trog at trogwoolley dot com
Isis Astarte Diana Hecate Demeter Kali Inanna
Jack
You can use -browsecmd option.
Switch: -browsecommand or -browsecmd
Name: browseCommand
Class: BrowseCommand
Specifies a command (callback) which will be evaluated anytime the
active cell changes. The Previous Index and the Current index is
passed to this command as arguments.
Then, you can passe your code to check the previous active cell.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::TableMatrix;
my $top = MainWindow->new;
my $arrayVar = {};
for my $r ( 0 .. 7 ) {
for my $c ( 0 .. 7 ) {
$arrayVar->{"$r,$c"} = 'test';
}
}
my $t = $top->Scrolled(
'TableMatrix',
-variable => $arrayVar,
-selectmode => 'extended',
-bg => 'white',
-fg => 'black',
);
$t->configure(
-browsecmd => sub {
my ( $previous_index, $current_index ) = @_;
if ( $previous_index =~ m{^\d+,\d+$} ) {
my $value_previous_cell = $t->get($previous_index);
# check and validation
if ( $value_previous_cell =~ s{^(\d+)/(\d+)$}{$1/$2/2010} ) {
$t->activate($previous_index);
$t->curvalue($value_previous_cell);
$t->activate($current_index);
}
}
},
);
$t->pack( -expand => 1, -fill => 'both' );
MainLoop;
Djibril