Debian Codegraph @

TixGrid/tgdemo_simple

raw
1 #!/perl -w
2
3 # A very simple demonstration of the tixGrid widget
4
5 use strict;
6 use vars qw($mw $g);
7 use Tk ();
8 use Tk::TixGrid;
9
10 my $hadMW = 0;
11 $hadMW= 1 if defined $mw; #(Tk::Exists($mw));
12
13 $mw = Tk::MainWindow->new() unless $hadMW;
14 $mw->optionAdd('*selectBackground' => 'lightblue');
15 MakeGrid($mw);
16 Tk::MainLoop unless $hadMW;
17
18 # This command is called whenever the background of the grid needs to
19 # be reformatted. The x1, y1, x2, y2 specifies the four corners of the area
20 # that needs to be reformatted.
21 #
22 # area:
23 # x-margin: the horizontal margin
24 # y-margin: the vertical margin
25 # s-margin: the overlap area of the x- and y-margins
26 # main: The rest
27 #
28
29 sub SimpleFormat
30 {
31 my ($w, $area, @entbox) = @_;
32 my %bg = (
33 's-margin' => 'gray65',
34 'x-margin' => 'gray65',
35 'y-margin' => 'gray65',
36 'main' => 'gray20',
37 );
38
39 if ($area eq 'main')
40 {
41 # The "grid" format is consecutive boxes without 3d borders
42 #
43 #$w->formatGrid(@entbox, -bordercolor=>$bg{$area},
44 $w->format('grid', @entbox, -bordercolor=>$bg{$area},
45 qw( -relief raised -bd 1
46 -filled 0 -bg red
47 -xon 1 -yon 1 -xoff 0 -yoff 0 -anchor se
48 ) );
49 }
50 elsif ($area =~ /^(x|y|s)-margin$/)
51 {
52 # border specifies consecutive 3d borders
53 #
54 #$w->formatBorder(@entbox, -bg=>$bg{$area},
55 $w->format('border', @entbox, -bg=>$bg{$area},
56 qw( -fill 1 -relief raised -bd 1
57 -selectbackground gray80
58 ) );
59 }
60 }
61
62 sub MakeGrid
63 {
64 my ($w) = @_;
65
66 #$g = $w->TixGrid(qw(-bd 0));
67 $g = $w->Scrolled('TixGrid', -bd=>0);
68
69 $g->pack(qw/-expand yes -fill both -padx 3 -pady 3/);
70
71 $g->configure(-formatcmd=>[\&SimpleFormat, $g]);
72
73
74 # Set the size of the columns
75 #
76 $g->size(qw/col 0 -size 10char/);
77 $g->size(qw/col 1 -size auto/);
78 $g->size(qw/col 2 -size auto/);
79 $g->size(qw/col 3 -size auto/);
80 $g->size(qw/col 4 -size auto/);
81
82 # set the default size of the column and rows. these sizes will be used
83 # if the size of a row or column has not be set via the "size col ?"
84 # command
85 $g->size(qw/col default -size 5char/);
86 $g->size(qw/row default -size 1.1char -pad0 3/);
87
88 for my $x (0..9)
89 {
90 for my $y (0..9)
91 {
92 $g->set($x,$y, -itemtype=>'text', -text=>"($x,$y)" );
93 }
94 }
95 $g->configure(-selectunit=>(shift @ARGV)) if @ARGV and $ARGV[0] =~/^(?:row|column|cell)/;
96 }
97
98 1;
99 __END__