5
## This demo uses most features of the table widget
7
## ( based on 'debug.tcl' included source archive of tktable extension )
10
require 'tkextlib/tktable'
13
ary = TkVariable.new_hash
18
((-(rows))..rows).each{|x|
19
((-(cols))..cols).each{|y|
20
ary[x,y] = "r#{x},c#{y}"
24
lbl = TkLabel.new(:text=>"TkTable v2 Example")
26
table = Tk::TkTable.new(:rows=>rows, :cols=>cols, :variable=>ary,
27
:width=>6, :height=>6,
28
:titlerows=>1, :titlecols=>2,
29
:roworigin=>-5, :colorigin=>-2,
30
:coltagcommand=>proc{|col|
32
(col>0 && col%2 == 1)? 'OddCol': ''
34
:selectmode=>:extended, :flashmode=>true,
35
:rowstretch=>:unset, :colstretch=>:unset,
36
:selecttitles=>false, :drawmode=>:single)
38
sx = table.xscrollbar(TkScrollbar.new)
39
sy = table.yscrollbar(TkScrollbar.new)
41
btn = TkButton.new(:text=>'Exit', :command=>proc{exit})
43
Tk.grid(lbl, '-', :sticky=>:ew)
44
Tk.grid(table, sy, :sticky=>:news)
45
Tk.grid(sx, :sticky=>:ew)
46
Tk.grid(btn, :sticky=>:ew, :columnspan=>2)
48
Tk.root.grid_columnconfig(0, :weight=>1)
49
Tk.root.grid_rowconfig(1, :weight=>1)
51
table.tag_configure('OddCol', :bg=>'brown', :fg=>'pink')
52
table.tag_configure('title', :bg=>'red', :fg=>'green', :relief=>:sunken)
53
table.tag_configure('dis', :state=>:disabled)
55
first = table[:colorigin]
56
%w(n s e w nw ne sw se c).each_with_index{|anchor, idx|
57
table.tag_configure(anchor, :anchor=>anchor)
58
table.tag_row(anchor, idx)
59
table.set([idx,first], anchor)
61
courier = TkFont.new(:family=>'Courier', :size=>10)
62
table.tag_configure('s', :font=>courier, :justify=>:center)
64
logo = TkPhotoImage.new(:file=>File.join(File.dirname(File.expand_path(__FILE__)), 'tcllogo.gif'))
65
table.tag_configure('logo', :image=>logo, :showtext=>true)
66
table.tag_cell('logo', [1,2], [2,3], [4,1])
67
table.tag_cell('dis', [2,1], [1,-1], [3,0])
68
table.set_width([-2,8], [-1,9], [0, 12], [4, 14])
70
table.set([1,1], "multi-line\ntext\nmight be\ninteresting",
71
[3,2], "more\nmulti-line\nplaying\n",
74
# This is in the row span
75
l = TkLabel.new(table, :text=>'Window s', :bg=>'yellow')
76
table.window_configure([6,0], :sticky=>:s, :window=>l)
78
# This is in the row titles
79
l = TkLabel.new(table, :text=>'Window ne', :bg=>'yellow')
80
table.window_configure([4,-1], :sticky=>:ne, :window=>l)
82
# This will get swallowed by a span
83
l = TkLabel.new(table, :text=>'Window ew', :bg=>'yellow')
84
table.window_configure([5,3], :sticky=>:ew, :window=>l)
86
# This is in the col titles
87
l = TkLabel.new(table, :text=>'Window news', :bg=>'yellow')
88
table.window_configure([-5,1], :sticky=>:news, :window=>l)
90
l = TkLabel.new(table.winfo_parent, :text=>'Sibling l', :bg=>'orange')
91
table.window_configure([5,1], :sticky=>:news, :window=>l)
93
if table.span_list.empty?
94
table.set_spans([-1,-2], [0,3], [1,2], [0,5], [3,2], [2,2], [6,0], [4,0])
97
puts "Table is #{table.path} with array #{(table['variable'])}"
99
# table.postscript(:file=>'out.ps', :first=>:origin, :last=>[2,2])