| 1 |
## version2.tcl |
| 2 |
## |
| 3 |
## This demo uses most features of the table widget |
| 4 |
## |
| 5 |
## [email protected] |
| 6 |
## Converted to perl/tk by John Cerney |
| 7 |
|
| 8 |
|
| 9 |
use Tk; |
| 10 |
|
| 11 |
use Tk::TableMatrix; |
| 12 |
|
| 13 |
my ($rows,$cols) = (25,20); # number of rows/cols |
| 14 |
my $top = MainWindow->new; |
| 15 |
|
| 16 |
# Sub to fill the array variable |
| 17 |
sub fill{ |
| 18 |
|
| 19 |
my ($array,$x,$y) = @_; |
| 20 |
my ($i,$j); |
| 21 |
for( $i = -$x; $i<$x; $i++){ |
| 22 |
for( $j = -$y; $j<$y; $j++){ |
| 23 |
$array->{"$i,$j"} = "r$i,c$j"; |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
## Test out the use of a callback to define tags on rows and columns |
| 31 |
sub colSub{ |
| 32 |
my $col = shift; |
| 33 |
return "OddCol" if( $col > 0 && $col%2) ; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
my $label = $top->Label(-text => "TableMatrix v2 Example"); |
| 38 |
|
| 39 |
|
| 40 |
my $arrayVar = {}; |
| 41 |
|
| 42 |
fill($arrayVar, $rows,$cols); # fill up the array variable |
| 43 |
|
| 44 |
|
| 45 |
my $t = $top->Scrolled('TableMatrix', -rows => $rows, -cols => $cols, |
| 46 |
-variable => $arrayVar, |
| 47 |
-width => 6, -height => 8, |
| 48 |
-titlerows => 1, -titlecols => 2, |
| 49 |
-roworigin => -5, -colorigin => -2, |
| 50 |
-coltagcommand => \&colSub, |
| 51 |
-selectmode => 'extended', |
| 52 |
-selecttitles => 0, |
| 53 |
-drawmode => 'single', |
| 54 |
|
| 55 |
); |
| 56 |
|
| 57 |
my $button = $top->Button( -text => "Exit", -command => sub{ $top->destroy}); |
| 58 |
$label->pack( -expand => 1, -fill => 'both'); |
| 59 |
|
| 60 |
$t->pack(-expand => 1, -fill => 'both'); |
| 61 |
$button->pack(-expand => 1, -fill => 'both'); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
# hideous Color definitions here: |
| 66 |
$t->tagConfigure('OddCol', -bg => 'brown', -fg => 'pink'); |
| 67 |
$t->tagConfigure('title', -bg => 'red', -fg => 'blue', -relief => 'sunken'); |
| 68 |
$t->tagConfigure('dis', -state => 'disabled'); |
| 69 |
|
| 70 |
my $i = -1; |
| 71 |
my $first = $t->cget(-colorigin); |
| 72 |
my $anchor; |
| 73 |
foreach $anchor( qw/ n s e w nw ne sw se c /){ |
| 74 |
$t->tagConfigure($anchor, -anchor => $anchor); |
| 75 |
$t->tagRow($anchor, ++$i); |
| 76 |
$t->set( "$i,$first",$anchor); |
| 77 |
} |
| 78 |
$top->fontCreate('courier', -family => 'courier', -size => 10); |
| 79 |
$t->tagConfigure('s', -font => 'courier', -justify => 'center'); |
| 80 |
|
| 81 |
# $initWindow->Label(-image => $top->Photo(-file => Tk->findINC('Xcamel.gif')))->pack; |
| 82 |
|
| 83 |
|
| 84 |
my $perltkLogo = $top->Photo(-file => Tk->findINC('Xcamel.gif')); |
| 85 |
|
| 86 |
$t->tagConfigure('logo', -image => $perltkLogo, -showtext => 1); |
| 87 |
$t->tagCell('logo', '1,2', '2,3', '4,1'); |
| 88 |
$t->tagCell('dis', '2,1', '1,-1', '3,0'); |
| 89 |
$t->colWidth(qw/ -2 8 -1 9 0 12 4 14/); |
| 90 |
|
| 91 |
|
| 92 |
$t->set( '1,1' => "multi-line\ntext\nmight be\ninteresting" , |
| 93 |
'3,2' => "more\nmulti-line\nplaying\n" , |
| 94 |
'2,2' => "null\0byte" ); |
| 95 |
|
| 96 |
|
| 97 |
$i = -1; |
| 98 |
|
| 99 |
# This is in the row span |
| 100 |
my $l = $top->Label(-text => "Window s", -bg => 'yellow'); |
| 101 |
$t->windowConfigure("6,0", -sticky => 's', -window => $l); |
| 102 |
|
| 103 |
# This is in the row titles |
| 104 |
$l = $top->Label(-text => "Window ne", -bg => 'yellow'); |
| 105 |
$t->windowConfigure("4,-1", -sticky => 'ne', -window => $l); |
| 106 |
|
| 107 |
# This will get swallowed by a span |
| 108 |
$l = $top->Label(-text => "Window ew", -bg => 'yellow'); |
| 109 |
$t->windowConfigure("5,3", -sticky => 'ew', -window => $l); |
| 110 |
|
| 111 |
|
| 112 |
# This is in the col titles |
| 113 |
$l = $top->Label(-text => "Window nsew", -bg => 'yellow'); |
| 114 |
$t->windowConfigure("-5,1", -sticky => 'nsew', -window => $l); |
| 115 |
|
| 116 |
$l = $t->parent->Label(-text => "Sibling l", -bg => 'orange'); |
| 117 |
$t->windowConfigure("5,1", -sticky => 'nsew', -window => $l); |
| 118 |
|
| 119 |
$t->spans( '-1,-2' => '0,3', '1,2' => '0,5','3,2' => '2,2', '6,0' => '4,0'); |
| 120 |
|
| 121 |
|
| 122 |
Tk::MainLoop; |