2004-07-15 01:18:57 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
##
|
|
|
|
## basic.rb
|
|
|
|
##
|
|
|
|
## This demo shows the basic use of the table widget
|
2009-03-06 03:56:38 +00:00
|
|
|
##
|
2004-07-15 01:18:57 +00:00
|
|
|
## ( based on 'basic.tcl' included source archive of tktable extension )
|
|
|
|
##
|
|
|
|
require 'tk'
|
|
|
|
require 'tkextlib/tktable'
|
|
|
|
|
|
|
|
ary = TkVariable.new_hash
|
|
|
|
rows = 8
|
|
|
|
cols = 8
|
|
|
|
|
|
|
|
# fill table variable
|
|
|
|
((-(rows))..rows).each{|x|
|
|
|
|
((-(cols))..cols).each{|y|
|
|
|
|
ary[x,y] = "r#{x},c#{y}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lbl = TkLabel.new(:text=>"TkTable v1 Example")
|
|
|
|
|
2009-03-06 03:56:38 +00:00
|
|
|
table = Tk::TkTable.new(:rows=>rows, :cols=>cols, :variable=>ary,
|
|
|
|
:width=>6, :height=>6,
|
|
|
|
:titlerows=>1, :titlecols=>2,
|
|
|
|
:roworigin=>-1, :colorigin=>-2,
|
2004-10-11 04:51:21 +00:00
|
|
|
:rowstretchmode=>:last, :colstretchmode=>:last,
|
|
|
|
:rowtagcommand=>proc{|row|
|
|
|
|
row = Integer(row)
|
2005-03-30 08:44:19 +00:00
|
|
|
(row>0 && row%2 == 1)? 'OddRow': ''
|
2009-03-06 03:56:38 +00:00
|
|
|
},
|
2004-10-11 04:51:21 +00:00
|
|
|
:coltagcommand=>proc{|col|
|
|
|
|
col = Integer(col)
|
2005-03-30 08:44:19 +00:00
|
|
|
(col>0 && col%2 == 1)? 'OddCol': ''
|
2009-03-06 03:56:38 +00:00
|
|
|
},
|
2004-10-11 04:51:21 +00:00
|
|
|
:selectmode=>:extended, :sparsearray=>false)
|
2004-07-15 01:18:57 +00:00
|
|
|
|
|
|
|
sx = table.xscrollbar(TkScrollbar.new)
|
|
|
|
sy = table.yscrollbar(TkScrollbar.new)
|
|
|
|
|
|
|
|
btn = TkButton.new(:text=>'Exit', :command=>proc{exit})
|
|
|
|
|
|
|
|
Tk.grid(lbl, '-', :sticky=>:ew)
|
|
|
|
Tk.grid(table, sy, :sticky=>:news)
|
|
|
|
Tk.grid(sx, :sticky=>:ew)
|
|
|
|
Tk.grid(btn, :sticky=>:ew, :columnspan=>2)
|
|
|
|
|
|
|
|
Tk.root.grid_columnconfig(0, :weight=>1)
|
|
|
|
Tk.root.grid_rowconfig(1, :weight=>1)
|
|
|
|
|
|
|
|
table.tag_configure('OddRow', :bg=>'orange', :fg=>'purple')
|
|
|
|
table.tag_configure('OddCol', :bg=>'brown', :fg=>'pink')
|
|
|
|
|
|
|
|
table.set_width([-2, 7], [-1, 7], [1, 5], [2, 8], [4, 14])
|
|
|
|
|
|
|
|
puts "Table is #{table.path} with array #{(table['variable'])}"
|
|
|
|
|
|
|
|
Tk.mainloop
|