File: spreadsheet

package info (click to toggle)
libtk-tablematrix-perl 1.22-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,624 kB
  • ctags: 1,274
  • sloc: ansic: 15,026; perl: 3,376; makefile: 156; sh: 16
file content (137 lines) | stat: -rwxr-xr-x 3,365 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/perl

## spreadsheet.tcl
##
## This demos shows how you can simulate a 3D table
## and has other basic features to begin a basic spreadsheet
##
## jeff.hobbs@acm.org
##  Converted to perl/tk by John Cerney


use Tk;

use Tk::TableMatrix;

my ($rows,$cols) = (10,10); # number of rows/cols
my $page = 'AA';
my $oldPage = '';

my $tableColors = { default => 'pink',AA => 'orange', BB => 'blue', CC => 'green'};

my $top = MainWindow->new;

sub colorize{
	my ($num) = @_;
	return 'colored' if( $num > 0 && $num%2);
	return '';
}

# Sub to fill the array variable
sub fill{

	my ($name, $array,$r,$c) = @_;
	my ($i,$j);
	$r ||= $rows;
	$c ||= $cols;
	for( $i = 0; $i<$r; $i++){
		for( $j = 0; $j<$c; $j++){
			if( $j && $i){
				$array->{"$i,$j"} = "$name $i,$j";
			}
			elsif( $i ){
				$array->{"$i,$j"} = "$i";
			}
			elsif( $j ){
				$array->{"$i,$j"} = sprintf("%c",($j+64));
			}
		}
	}
}

my $arrayVar = { AA => {},
		 BB => {},
		 CC => {}};

fill('AA',$arrayVar->{AA}, $rows,$cols); # fill up the array variable
fill('BB',$arrayVar->{BB}, $rows/2,$cols/2); # fill up the array variable

my $t = $top->Scrolled('TableMatrix', -rows => $rows, -cols => $cols, 
                              -width => 5, -height => 5,
			      -titlerows => 1, -titlecols => 1,
			      -coltagcommand => \&colorize,
			      -selectmode => 'extended',
			      -flashmode => 'on',
			      -variable => $arrayVar->{$page},		      				

                    );


my $label = $top->Label(-text => "TableMatrix vs Spreadsheet Example");

# Label the changes with the value of currentTest
my $currentText = '';
my $currentLabel = $top->Label(-textvariable => \$currentText);

# Entry that changes with the value of activeText
my $activeText = '';
my $activeEntry = $top->Entry(-textvariable => \$activeText);

my $pageLabel = $top->Label(-text => 'PAGE:', -width => 6, -anchor => 'e');
my $pageSelect = $top->Optionmenu( -options => [ qw/ AA BB CC/], 
		-variable => \$page,
		-command => [ \&changepage]);



sub changepage{

	my ($newPage) = @_;
	
	if( $newPage ne $oldPage){
		
		$t->selectionClear('all');
		$t->activate(''); # unactivate anything
		$t->configure(-variable => $arrayVar->{$newPage});
	        # $e config -textvar ${i}(active)
		$t->activate('origin');
		if( exists $tableColors->{$newPage}){
			$t->tagConfigure('colored', -bg => $tableColors->{$newPage});
		}
		else{
			$t->tagConfigure('colored', -bg => $tableColors->{'default'});
		}
		$t->see('active');
		$oldPage = $newPage;
	}
}

$t->configure( -browsecommand => sub{
					my ($oldindex,$index) = @_;
					$currentText = $index;
					$activeText = $t->get($index);
				});



# hideous Color definitions here:
$t->tagConfigure('colored', -bg => $tableColors->{$page});
$t->tagConfigure('title', -fg => 'red', -relief => 'groove');
$t->tagConfigure('blue', -bg => 'blue');
$t->tagConfigure('green', -bg => 'green');

$t->tagCell('green', '6,3','5,7','4,9');
$t->tagCell('blue', '8,8');
$t->tagRow('blue', 7);
$t->tagCol('blue', 6,8);

$t->colWidth( 0 => 3, 2 => 7);

$label->grid(				'-',		'-',		'-',		'-',	'-sticky' => 'ew');
$currentLabel->grid(		$currentLabel,	$activeEntry, 	$pageLabel, 	$pageSelect, 	'-',	'-sticky' => 'ew');
$t->grid( 				'-',		'-',		'-',		'-',	'-sticky' => 'nsew');
$top->gridColumnconfigure(1, -weight => 1);
$top->gridRowconfigure(2, -weight => 1);


Tk::MainLoop;