1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/tk/sample/tkextlib/tktable/basic.rb
naruse c4fdfabcc8 handle ext/ as r53141
g -L frozen_string_literal ext/**/*.rb|xargs ruby -Ka -e'ARGV.each{|fn|puts
fn;open(fn,"r+"){|f|s=f.read.sub(/\A(#!.*\n)?(#.*coding.*\n)?/,"\\&#
frozen_string_literal: false\n");f.rewind;f.write s}}'

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16 05:31:54 +00:00

61 lines
1.8 KiB
Ruby

#!/usr/bin/env ruby
# frozen_string_literal: false
##
## basic.rb
##
## This demo shows the basic use of the table widget
##
## ( 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")
table = Tk::TkTable.new(:rows=>rows, :cols=>cols, :variable=>ary,
:width=>6, :height=>6,
:titlerows=>1, :titlecols=>2,
:roworigin=>-1, :colorigin=>-2,
:rowstretchmode=>:last, :colstretchmode=>:last,
:rowtagcommand=>proc{|row|
row = Integer(row)
(row>0 && row%2 == 1)? 'OddRow': ''
},
:coltagcommand=>proc{|col|
col = Integer(col)
(col>0 && col%2 == 1)? 'OddCol': ''
},
:selectmode=>:extended, :sparsearray=>false)
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