1
##########################################################################
4
# see <http://wiki.tcl.tk/10615>
6
# Note: optional argument '-font' of the Tcl library is changed to
7
# 'itemfont' on this Ruby library, because of avoiding font
8
# operation trouble in 'initialize' method ( see the following
11
##########################################################################
14
class TkTree < TkCanvas
15
TCL_SCRIPT_PATH = File.join(File.dirname(__FILE__), 'tktree.tcl')
19
if keys.kind_of?(Hash)
20
font = keys.delete('itemfont')
21
# font = hash_kv(font) if font.kind_of?(Hash)
22
keys['font'] = font if font
23
# args.concat(hash_kv(keys))
27
tk_call('::tktree::treecreate', *args)
28
rescue NameError, RuntimeError
29
Tk.load_tclscript(TkTree::TCL_SCRIPT_PATH)
30
tk_call('::tktree::treecreate', *args)
34
def newitem(itempath, keys = nil)
35
if keys.kind_of?(Hash)
36
keys = _symbolkey2str(keys)
37
font = keys.delete('itemfont')
38
# font = hash_kv(font) if font.kind_of?(Hash)
39
keys['font'] = font if font
40
# tk_call('::tktree::newitem', @path, itempath, *hash_kv(keys))
41
tk_call('::tktree::newitem', @path, itempath, keys)
43
tk_call('::tktree::newitem', @path, itempath)
48
tk_call('::tktree::delitem', @path, itempath)
51
def labelat(xpos, ypos)
52
tk_call('::tktree::delitem', @path, xpos, ypos)
56
tk_call('::tktree::getselection', @path)
59
def setselection(itempath)
60
tk_call('::tktree::getselection', @path, itempath)
65
##########################################################################
67
##########################################################################
69
TkLabel.new(:text=><<EOL, :relief=>:ridge, :justify=>:left).pack
71
This is a sample to use a Tcl library script on Ruby/Tk.
72
This sample loads tktree.tcl (see <http://wiki.tcl.tk/10615>)
73
and calls functions of the Tcl script.
76
items = %w(/group1/item1 /group1/item2 /group1/subgroup/item1 /group2/item1 /item1)
78
tr1 = TkTree.new.pack(:expand=>true, :fill=>:both)
83
:command=>proc{Tk.messageBox(:message=>"#{item} executed")})
86
f = TkFrame.new.pack(:expand=>true, :fill=>:both)
87
tr2 = TkTree.new(f, :bg=>'black', #:itemfont=>{:family=>'Times', :size=>14},
88
:textcolor=>'red', :bd=>4, :relief=>:ridge,
89
:selectbackground=>'darkBlue', :selectforeground=>'yellow',
90
:selectborderwidth=>3, :linecolor=>'yellow') {
91
yscrollbar(TkScrollbar.new(f, :width=>10).pack(:side=>:right, :fill=>:y))
92
xscrollbar(TkScrollbar.new(f, :width=>10).pack(:side=>:bottom, :fill=>:x))
93
pack(:expand=>true, :fill=>:both)
97
tr2.newitem(item, :textcolor=>'green', :image=>'',
98
:itemfont=>{:family=>'Times', :size=>10},
99
:command=>proc{Tk.messageBox(:message=>"#{item} executed")})