Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TableMatrix vcmd assistance

33 views
Skip to first unread message

Trog Woolley

unread,
Aug 17, 2010, 6:51:37 AM8/17/10
to
When entering data into a cell of TableMatrix, the callback specified
by vcmd is called for every character. How do you use this to validate
enetered data? The Entry widget has the ability to run the callback
only on FocusOut, so that when the user has finished entering data,
you can validate and/or manipulate this. For example, a date entered
as 3/4 could be expanded to 03/04/2010 by a simple piece of coding.
Is there something similar for TableMatrix?

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 D

unread,
Aug 17, 2010, 9:46:58 PM8/17/10
to

"Trog Woolley" <tr...@email.fake> wrote in message
news:ZQtao.84508$y_2.17048@hurricane...
I have had excellent results with Rob's JComboBox for data entry. It allows
search capabilities as well as data entry on-the-fly (does not need to be in
the list like an optionmenu or browseentry. The validation options are the
same as for the entry widget. Other neat options are the various
callbacks -matchcommand -popupmodify etc. You have total control in what
does and does not get displayed.

Jack

perlgenome

unread,
Aug 18, 2010, 4:44:30 PM8/18/10
to

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


0 new messages