5
## This demos shows the use of the validation mechanism of the table
6
## and uses the table's cache (no -command or -variable) with a cute
7
## dynamic row routine.
9
## ( based on 'dynarows.tcl' included source archive of tktable extension )
12
require 'tkextlib/tktable'
14
def table_validate(w, idx)
15
return unless idx =~ /^(\d+),(\d+)$/
22
return if row == nrows - 1 && val == ''
25
time = Tk.tk_call('clock', 'scan', val)
27
Tk.tk_call('clock', 'format', time,
28
:format=>'%m %d %Y').split(' ').each{|item|
29
date << item.sub(/^\s*0*/,'')
31
w.set(idx, date.join('/'))
33
if w.get([row,1]) != '' && w.get([row,2]) != ''
38
w.configure(:rows=>nrows)
39
w.tag_row('unset', row)
49
w.selection_set(:active)
55
lbl = TkLabel.new(:text=>"Dynamic Date Validated Rows")
57
table = Tk::TkTable.new(:rows=>2, :cols=>3, :cache=>1, :selecttype=>:row,
58
:titlerows=>1, :titlecols=>1, :height=>5,
59
:colstretch=>:unset, :rowstretch=>:unset,
62
proc{|w,s| table_validate(w, s)},
65
table.set([0,1], 'Begin', [0,2], 'End', [1,0], '*')
66
table.tag_configure('unset', :fg=>'#008811')
67
table.tag_configure('title', :fg=>'red')
68
table.tag_row('unset', 1)
71
sx = table.xscrollbar(TkScrollbar.new)
72
sy = table.yscrollbar(TkScrollbar.new)
74
Tk.grid(lbl, '-', :sticky=>:ew)
75
Tk.grid(table, sy, :sticky=>:news)
76
Tk.grid(sx, :sticky=>:ew)
78
Tk.root.grid_columnconfig(0, :weight=>1)
79
Tk.root.grid_rowconfig(1, :weight=>1)
82
r = w.row_index(:active)
83
c = w.col_index(:active)
96
table.bind('Return', rtn_proc, '%W')
97
table.bind('KP_Enter', rtn_proc, '%W')