Can anyone give me a step-by-step method of using TkTree on Win32? I
don’t know how to make tcltk-ext work, so any help would be
appreciated.
Hi,
···
From: dejaspam@batkins.com (Bill Atkins)
Subject: Using TkTree - Desperately need help
Date: Wed, 5 May 2004 01:18:56 +0900
Message-ID: e6056acc.0405040815.1f2b1b3c@posting.google.com
Can anyone give me a step-by-step method of using TkTree on Win32? I
don’t know how to make tcltk-ext work, so any help would be
appreciated.
If the ‘TkTree’ which you said is the script at http://wiki.tcl.tk/10615,
you will not need to use tcltk-ext because there are only 5 commands
introduced by the library.
Although I think you can write a library script for TkTree widgets,
I append a sample library at the end of this mail.
To install,
step1: make TkTree work on Tcl/Tk
(1) save Tcl source script (e.g. ‘tktree.tcl’).
(2) copy the script file to Tcl/Tk library directory.
(3) start wish or tclsh, and do ‘auto_mkindex ’.
(4) restart wish, and do the test script at http://wiki.tcl.tk/10615.
step2: try on Ruby/Tk
(1) save the following library script as ‘tktree.rb’.
(2) /ruby tktree.rb
(3) move tktree.rb to your ruby library path.
(4) ‘require “tktree”’ on your script.
---------------------------------------------------
##########################################################################
TkTree widget class
see tktree
Note: optional argument ‘-font’ of the Tcl library is changed to
‘itemfont’ on this Ruby library, because of avoiding font
operation trouble in ‘initialize’ method ( see the following
test script ).
##########################################################################
require ‘tk’
class TkTree < TkCanvas
def create_self(keys)
if keys.kind_of?(Hash)
font = keys.delete(‘itemfont’)
keys[‘font’] = font if font
tk_call(‘::tktree::treecreate’, @path, *hash_kv(keys))
else
tk_call(‘::tktree::treecreate’, @path)
end
end
def newitem(itempath, keys = nil)
if keys.kind_of?(Hash)
keys = _symbolkey2str(keys)
font = keys.delete(‘itemfont’)
keys[‘font’] = font if font
tk_call(‘::tktree::newitem’, @path, itempath, *hash_kv(keys))
else
tk_call(‘::tktree::newitem’, @path, itempath)
end
end
def delitem(itempath)
tk_call(‘::tktree::delitem’, @path, itempath)
end
def labelat(xpos, ypos)
tk_call(‘::tktree::delitem’, @path, xpos, ypos)
end
def getselection
tk_call(‘::tktree::getselection’, @path)
end
def setselection(itempath)
tk_call(‘::tktree::getselection’, @path, itempath)
end
end
##########################################################################
test script
##########################################################################
if FILE == $0
items = %w(/group1/item1 /group1/item2 /group1/subgroup/item1 /group2/item1 /item1)
tr1 = TkTree.new.pack(:expand=>true, :fill=>:both)
tr1.focus
items.each{|item|
tr1.newitem(item,
:command=>proc{Tk.messageBox(:message=>“#{item} executed”)})
}
f = TkFrame.new.pack(:expand=>true, :fill=>:both)
tr2 = TkTree.new(f, :bg=>‘black’, :itemfont=>{:family=>‘Times’, :size=>14},
:textcolor=>‘red’, :bd=>4, :relief=>:ridge,
:selectbackground=>‘darkBlue’, :selectforeground=>‘yellow’,
:selectborderwidth=>3, :linecolor=>‘yellow’) {
yscrollbar(TkScrollbar.new(f, :width=>10).pack(:side=>:right, :fill=>:y))
xscrollbar(TkScrollbar.new(f, :width=>10).pack(:side=>:bottom, :fill=>:x))
pack(:expand=>true, :fill=>:both)
}
items.each{|item|
tr2.newitem(item, :textcolor=>‘green’, :image=>‘’,
:itemfont=>{:family=>‘Times’, :size=>10},
:command=>proc{Tk.messageBox(:message=>“#{item} executed”)})
}
Tk.mainloop
end
---------------------------------------------------
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
Hi,
···
From: Hidetoshi NAGAI nagai@ai.kyutech.ac.jp
Subject: Re: Using TkTree - Desperately need help
Date: Thu, 6 May 2004 13:41:17 +0900
Message-ID: 20040506.134115.41644100.nagai@ai.kyutech.ac.jp
To install,
step1: make TkTree work on Tcl/Tk
(1) save Tcl source script (e.g. ‘tktree.tcl’).
(2) copy the script file to Tcl/Tk library directory.
(3) start wish or tclsh, and do ‘auto_mkindex ’.
(4) restart wish, and do the test script at http://wiki.tcl.tk/10615.step2: try on Ruby/Tk
(1) save the following library script as ‘tktree.rb’.
(2) /ruby tktree.rb
(3) move tktree.rb to your ruby library path.
(4) ‘require “tktree”’ on your script.
I’d forgotten other solutions.
The followings don’t request you to work on Tcl/Tk.
(Ans.1)
(1) call Tk.load_tclscript()
(2) require “tktree” (or some wrapper library)
(Ans.2)
(1) store Tcl script as a string,
and call Tk.ip_eval()
ex1: Tk.ip_eval(IO.read(<Tcl script file>))
ex2: Tk.ip_eval(IO.read(<<EOT))
... Tcl script text ...
EOT
(2) require “tktree” (or some wrapper library)
If you must load Tcl/Tk’s dynamic libraries,
please use ‘Tk.load_tcllibrary()’.
–
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
I tried that but I get these errors when I run tktree.rb
C:/Program Files/Arachno Ruby IDE/ruby/lib/ruby/1.8/tk.rb:1036:in
tk_call': invalid command name
::tktree::treecreate’ (NameError)
from tktree.rb:21:in create_self' from C:/Program Files/Arachno Ruby IDE/ruby/lib/ruby/1.8/tk.rb:3985:in
initialize’
from tktree.rb:60:in `new’
from tktree.rb:60
Hidetoshi NAGAI nagai@ai.kyutech.ac.jp wrote in message news:20040507.115427.41647208.nagai@ai.kyutech.ac.jp…
···
Hi,
From: Hidetoshi NAGAI nagai@ai.kyutech.ac.jp
Subject: Re: Using TkTree - Desperately need help
Date: Thu, 6 May 2004 13:41:17 +0900
Message-ID: 20040506.134115.41644100.nagai@ai.kyutech.ac.jpTo install,
step1: make TkTree work on Tcl/Tk
(1) save Tcl source script (e.g. ‘tktree.tcl’).
(2) copy the script file to Tcl/Tk library directory.
(3) start wish or tclsh, and do ‘auto_mkindex ’.
(4) restart wish, and do the test script at http://wiki.tcl.tk/10615.step2: try on Ruby/Tk
(1) save the following library script as ‘tktree.rb’.
(2) /ruby tktree.rb
(3) move tktree.rb to your ruby library path.
(4) ‘require “tktree”’ on your script.I’d forgotten other solutions.
The followings don’t request you to work on Tcl/Tk.(Ans.1)
(1) call Tk.load_tclscript()
(2) require “tktree” (or some wrapper library)(Ans.2)
(1) store Tcl script as a string,
and call Tk.ip_eval()ex1: Tk.ip_eval(IO.read(<Tcl script file>)) ex2: Tk.ip_eval(IO.read(<<EOT)) ... Tcl script text ... EOT
(2) require “tktree” (or some wrapper library)
If you must load Tcl/Tk’s dynamic libraries,
please use ‘Tk.load_tcllibrary()’.
Hi,
···
From: dejaspam@batkins.com (Bill Atkins)
Subject: Re: Using TkTree - Desperately need help
Date: Sat, 15 May 2004 05:18:52 +0900
Message-ID: e6056acc.0405141215.17b7bb2@posting.google.com
I tried that but I get these errors when I run tktree.rb
C:/Program Files/Arachno Ruby IDE/ruby/lib/ruby/1.8/tk.rb:1036:in
tk_call': invalid command name
::tktree::treecreate’ (NameError)
from tktree.rb:21:increate_self' from C:/Program Files/Arachno Ruby IDE/ruby/lib/ruby/1.8/tk.rb:3985:in
initialize’
from tktree.rb:60:in `new’
from tktree.rb:60
It shows that your Tcl/Tk libraries linked with Ruby don’t load
(or fail to load) the tktree library (or definitions).
Or your Tcl/Tk libraries are too old and don’t support namespaces.
If your Tcl/Tk cannot autoload the tktree library, you must load
the library to Tcl/Tk interpreter working under Ruby/Tk when
requiring tktree.rb.
I intended the way to load in my last mail.
> (Ans.1)
> (1) call Tk.load_tclscript()
> (Ans.2)
> (1) store Tcl script as a string,
> and call Tk.ip_eval()
>
> ex1: Tk.ip_eval(IO.read())
>
> ex2: Tk.ip_eval(IO.read(<<EOT))
> … Tcl script text …
> EOT
Of cource, is your tktree.tcl file.
~~~
–
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)