5
## This demo shows the use of the table widget's -command options
7
## ( based on 'command.tcl' included source archive of tktable extension )
10
require 'tkextlib/tktable'
13
data = TkVariable.new_hash
18
((-(rows))..rows).each{|x|
19
((-(cols))..cols).each{|y|
20
data[x,y] = "#{x} x #{y}"
24
lbl = TkLabel.new(:text=>"TkTable :command Example")
25
cur_var = TkVariable.new
26
current = TkLabel.new(:textvariable=>cur_var, :width=>5)
27
ent_var = TkVariable.new
28
entry = TkEntry.new(:textvariable=>ent_var)
30
table = Tk::TkTable.new(:rows=>rows, :cols=>cols,
31
:command=>[proc{|mode, cell, val|
42
:width=>6, :height=>6,
43
:titlerows=>1, :titlecols=>1,
44
:roworigin=>-1, :colorigin=>-1,
45
:rowstretchmode=>:last, :colstretchmode=>:last,
46
:rowtagcommand=>proc{|row|
48
(row>0 && row%2 == 1)? 'OddRow': ''
50
:coltagcommand=>proc{|col|
52
(col>0 && col%2 == 1)? 'OddCol': ''
54
:selectmode=>:extended, :flashmode=>true,
55
:rowstretch=>:unset, :colstretch=>:unset,
56
:browsecommand=>[proc{|w, s|
58
ent_var.value = w.get(s)
61
:validatecommand=>proc{|e|
62
ent_var.value = e.new_value; true
67
ent_var.value = s; true
71
sx = table.xscrollbar(TkScrollbar.new)
72
sy = table.yscrollbar(TkScrollbar.new)
74
entry.bind('Return', proc{|w| table.curvalue = w.value}, '%W')
76
Tk.grid(lbl, '-', '-', :sticky=>:ew)
77
Tk.grid(current, entry, '-', :sticky=>:ew)
78
Tk.grid(table, '-', sy, :sticky=>:news)
79
Tk.grid(sx, '-', :sticky=>:ew)
81
Tk.root.grid_columnconfig(1, :weight=>1)
82
Tk.root.grid_rowconfig(2, :weight=>1)
84
table.tag_configure('OddRow', :bg=>'orange', :fg=>'purple')
85
table.tag_configure('OddCol', :bg=>'brown', :fg=>'pink')
87
puts "Table is #{table.path}"