summaryrefslogtreecommitdiff
path: root/ext/tk/sample/tkextlib/tktable/buttons.rb
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-15 01:18:57 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-15 01:18:57 +0000
commitce1b23b7a5a496f4b6d3ad4627a161b1dc6945fe (patch)
treed7dca8b035286a8a852c021318fa04a4efa43aa8 /ext/tk/sample/tkextlib/tktable/buttons.rb
parent6c6a24826c5fda68e04e71ac17620b0e70bca265 (diff)
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@6630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/tkextlib/tktable/buttons.rb')
-rw-r--r--ext/tk/sample/tkextlib/tktable/buttons.rb76
1 files changed, 76 insertions, 0 deletions
diff --git a/ext/tk/sample/tkextlib/tktable/buttons.rb b/ext/tk/sample/tkextlib/tktable/buttons.rb
new file mode 100644
index 0000000000..b6995bb54b
--- /dev/null
+++ b/ext/tk/sample/tkextlib/tktable/buttons.rb
@@ -0,0 +1,76 @@
+#!/usr/bin/env ruby
+##
+## buttons.rb
+##
+## demonstrates the simulation of a button array
+##
+## ( based on 'buttons.tcl' included source archive of tktable extension )
+##
+require 'tk'
+require 'tkextlib/tktable'
+
+# create the table
+tab = TkVariable.new_hash
+rows = 20
+cols = 20
+
+table = Tk::TkTable.new(:rows=>rows + 1, :cols=>cols + 1,
+ :variable=>tab, :titlerows=>1, :titlecols=>1,
+ :roworigin=>-1, :colorigin=>-1,
+ :colwidth=>4, :width=>8, :height=>8,
+ :cursor=>'top_left_arrow', :borderwidth=>2,
+ :flashmode=>false, :state=>:disabled)
+
+sx = table.xscrollbar(TkScrollbar.new)
+sy = table.yscrollbar(TkScrollbar.new)
+
+Tk.grid(table, sy, :sticky=>:news)
+Tk.grid(sx, :sticky=>:ew)
+
+Tk.root.grid_columnconfig(0, :weight=>1)
+Tk.root.grid_rowconfig(0, :weight=>1)
+
+# set up tags for the various states of the buttons
+table.tag_configure('OFF', :bg=>'red', :relief=>:raised)
+table.tag_configure('ON', :bg=>'green', :relief=>:sunken)
+table.tag_configure('sel', :bg=>'gray75', :relief=>:flat)
+
+# clean up if mouse leaves the widget
+table.bind('Leave', proc{|w| w.selection_clear_all}, '%W')
+
+# highlight the cell under the mouse
+table.bind('Motion', proc{|w, x, y|
+ Tk.callback_break if w.selection_include?(TkComm._at(x,y))
+ w.selection_clear_all
+ w.selection_set(TkComm._at(x,y))
+ Tk.callback_break
+ ## "break" prevents the call to tkTableCheckBorder
+ }, '%W %x %y')
+
+# mousebutton 1 toggles the value of the cell
+# use of "selection includes" would work here
+table.bind('1', proc{|w, x, y|
+ #rc = w.curselection[0]
+ rc = w.index(TkComm._at(x,y))
+ if tab[rc] == 'ON'
+ tab[rc] = 'OFF'
+ w.tag_cell('OFF', rc)
+ else
+ tab[rc] = 'ON'
+ w.tag_cell('ON', rc)
+ end}, '%W %x %y')
+
+
+# inititialize the array, titles, and celltags
+0.step(rows){|i|
+ tab[i,-1] = i
+ 0.step(cols){|j|
+ if i == 0
+ tab[-1,j] = j
+ end
+ tab[i,j] = "OFF"
+ table.tag_cell('OFF', "#{i},#{j}")
+ }
+}
+
+Tk.mainloop