ruby/ext/tk/sample/tkextlib/iwidgets/sample/tabset.rb
nagai ce1b23b7a5 * 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
2004-07-15 01:18:57 +00:00

34 lines
961 B
Ruby

#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'
# Create a listbox with two items (one and two)
l = TkListbox.new(:selectmode=>:single, :exportselection=>false).pack
l.insert('end', 'one')
l.insert('end', 'two')
l.selection_set(0)
# Define a proc that knows how to select an item
# from a list given an index from the tabset -command callback.
selectItem = proc{|item|
l.selection_clear(l.curselection)
l.selection_set(item)
l.see(item)
}
# Create a tabset, set its -command to call selectItem
# Add two labels to the tabset (one and two).
ts = Tk::Iwidgets::Tabset.new(:command=>selectItem)
ts.add(:label=>1)
ts.add(:label=>2)
ts.select(0)
ts.pack(:fill=>:x, :expand=>true)
# Define a proc that knows how to select a tab
# given a y pixel coordinate from the list..
selectTab = proc{|y| ts.select(l.nearest(y)) }
# bind button 1 press to the selectTab procedure.
l.bind('ButtonPress-1', proc{|y| selectTab.call(y) }, '%y')
Tk.mainloop