in reply to Re^2: Tk ::TableMatrix
in thread Tk ::TableMatrix
you can do the disabling too, but it is a little tricky, because you have to raise the 'dis' tag over the 'OddCol' tag. You don't have this problem if you don't use the -coltagcommand option.# table option -browsecommand => \&brscmd, sub brscmd { my ($previous_index, $actual_index) = @_; my ($row, $col) = split ',', $actual_index; print "r$row c$col\n"; # popup if row,col meets some criteria }
#!/usr/bin/perl use Tk; use Tk::TableMatrix; my $mw = MainWindow->new; my $arrayVar = {}; print "Filling Array...\n"; my ($rows,$cols) = (10, 10); foreach my $row (0..($rows-1)){ foreach my $col (0..($cols-1)){ $arrayVar->{"$row,$col"} = 2*$row + 3*$col; } } print "Creating Table...\n"; ## Test out the use of a callback to define tags on rows and columns sub colSub{ my $col = shift; return "OddCol" if( $col > 0 && $col%2) ; } my $t = $mw->Scrolled('TableMatrix', -rows => $rows, -cols => $cols, -width => 10, -height => 10, -titlerows => 1, -titlecols => 1, -variable => $arrayVar, -coltagcommand => \&colSub, -browsecommand => \&brscmd, -colstretchmode => 'last', -rowstretchmode => 'last', -selectmode => 'extended', -selecttitles => 0, -drawmode => 'slow', -scrollbars=>'se' ); $mw->Button(-text => "Update", -command => \&update_table) ->pack(-side => 'bottom',-anchor => 'w'); $mw->Button(-text => "Disable", -command => \&dis_table) ->pack(-side => 'bottom',-anchor => 'w'); # hideous Color definitions here: $t->tagConfigure('active', -bg => 'white', -relief => 'sunken'); $t->tagConfigure('OddCol', -bg => 'lightyellow', -fg => 'black'); $t->tagConfigure('title', -bg => 'lightblue', -fg => 'black', -relief +=> 'sunken'); $t->tagConfigure('dis', -state => 'disabled', -bg => 'black'); $t->pack(-expand => 1, -fill => 'both'); $t->focus; Tk::MainLoop; sub update_table { print "1\n"; $t->tagCell('dis', '1,1' ); $t->tagRaise('dis', 'OddCol'); # only needed if coltagcommand used $t->activate('2,2'); $t->tagRow('active',3); # $t->configure(-padx =>( $t->cget(-padx))); # a trick needed sometimes to update } sub brscmd { my ($previous_index, $actual_index) = @_; my ($row, $col) = split ',', $actual_index; print "r$row c$col\n"; } sub dis_table{ print "2\n"; foreach my $col (1..4){ if ($arrayVar->{"6,$col"} >= 1) { print "col->$col\n"; $t->tagCell('dis',"7,$col"); $t->tagCell('dis',"8,$col"); $t->tagCell('dis',"9,$col"); } } $t->tagRaise('dis', 'OddCol'); # only needed if coltagcommand used }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Tk ::TableMatrix
by lil_v (Sexton) on Jul 02, 2008 at 19:00 UTC | |
by zentara (Cardinal) on Jul 02, 2008 at 19:53 UTC | |
|
Re^4: Tk ::TableMatrix
by lil_v (Sexton) on Jul 15, 2008 at 15:05 UTC | |
by zentara (Cardinal) on Jul 15, 2008 at 16:28 UTC | |
by lil_v (Sexton) on Jul 17, 2008 at 15:41 UTC | |
by zentara (Cardinal) on Jul 17, 2008 at 17:19 UTC |