From 4b90fcc22fba45704d6875ea657ff785416fcc89 Mon Sep 17 00:00:00 2001 From: nagai Date: Thu, 15 Jul 2004 01:18:57 +0000 Subject: * ext/tk/, ext/tcltklib/: bug fix * ext/tk/lib/tk.rb: better operation for SIGINT when processing callbacks. * ext/tk/lib/tk/msgcat.rb: ditto. * ext/tk/lib/tk/variable.rb: ditto. * ext/tk/lib/tk/timer.rb: ditto. * ext/tk/lib/tk/validation.rb: add Tk::ValidateConfigure.__def_validcmd() to define validatecommand methods easier * ext/tk/lib/tk.rb (_genobj_for_tkwidget): support autoload Tk ext classes * ext/tk/lib/tk/canvas.rb and so on: remove the parent widget type check for items (e.g. canvas items; depends on the class) to avoid some troubles on Tk extension widget class definition. * ext/tk/lib/tkextlib/: add Iwidget and TkTable extension support * ext/tk/sample/tkextlib/: add samples of Iwidget and TkTable git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/sample/tkextlib/tktable/basic.rb | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 ext/tk/sample/tkextlib/tktable/basic.rb (limited to 'ext/tk/sample/tkextlib/tktable/basic.rb') diff --git a/ext/tk/sample/tkextlib/tktable/basic.rb b/ext/tk/sample/tkextlib/tktable/basic.rb new file mode 100644 index 000000000..a7dfe2a78 --- /dev/null +++ b/ext/tk/sample/tkextlib/tktable/basic.rb @@ -0,0 +1,60 @@ +#!/usr/bin/env ruby +## +## 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) + return 'OddRow' if row>0 && row%2 == 1 + }, + :coltagcommand=>proc{|col| + col = Integer(col) + return 'OddCol' if col>0 && col%2 == 1 + }, + :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 -- cgit