Tk and Tile with Tk8.5

  • Thread starter László Földes
  • Start date
L

László Földes

I want to use Ruby 1.9.1 (Ubuntu 10.10) with Tk8.5 Tile, but this samle
code:

require 'tk'
require 'tkextlib/tile'

root = TkRoot.new { title "Ex1" }

Tk::Tile::Button.new(root) {
text "Ok"
command proc { print "Hello, World!"; exit }
pack('side'=>'left', 'padx'=>10, 'pady'=>10)
}

Tk.mainloop()

fails with:
$ ruby tk_test.rb
/usr/lib/ruby/1.9.1/tkextlib/tile.rb:46:in `rescue in <top (required)>':
undefined method `__cannot_find_tk_package_for_widget_set__' for
Tk:Module (NoMethodError)
from /usr/lib/ruby/1.9.1/tkextlib/tile.rb:31:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from tk_test.rb:2:in `<main>'


Googleing for "__cannot_find_tk_package_for_widget_set__" is one of
those rare moments when Google gives back only 1 hit.
Am I doing something wrong? I'm not a source code compiler type, I
installed everything from aptitude (Ruby 1.9.1, Tk8.4, Tk8.5, Tcl8.4,
Tcl8.5)
 
H

Hidetoshi NAGAI

Hi, =


Thank you for your report.

From: L=E1szl=F3 F=F6ldes <[email protected]>
Subject: Tk and Tile with Tk8.5
Date: Sat, 2 Apr 2011 09:45:24 +0900
Message-ID: said:
I want to use Ruby 1.9.1 (Ubuntu 10.10) with Tk8.5 Tile, but this sam= le
(snip)
fails with:
$ ruby tk_test.rb
/usr/lib/ruby/1.9.1/tkextlib/tile.rb:46:in `rescue in <top (required)=
':
undefined method `__cannot_find_tk_package_for_widget_set__' for
Tk:Module (NoMethodError)

I'm very sorry. It's a bug which should be fixed.
But it is not a primary problem for your trouble.
If tile extension is installed (or Tcl/Tk is 8.5 or later), =

Ruby/Tk doesn't use the bugged routine.
Am I doing something wrong? I'm not a source code compiler type, I
installed everything from aptitude (Ruby 1.9.1, Tk8.4, Tk8.5, Tcl8.4,=

Probably, your ruby's tcltklib.so is linked with Tcl/Tk8.4.
Please check the result of 'ruby -r tk -e "p Tk::TK_PATCHLEVEL"'.
If it shows 8.4.x, your tcltklib.so uses libraries of Tcl/Tk8.4.

To fix it, please install tile extension for your Tcl/Tk8.4, =

or re-compile your ruby's tcltklib.so with Tcl/Tk8.5.
I'm not familiar with Ubuntu. So, I don't know which is better.
If igonore it, I recommend you to re-compile tcltklib.so, =

because Tcl/Tk8.5 is better than Tcl/Tk8.4.
-- =

Hidetoshi NAGAI ([email protected])
Department of Artificial Intelligence, Kyushu Institute of Technology
 
L

László Földes

Please check the result of 'ruby -r tk -e "p Tk::TK_PATCHLEVEL"'.
If it shows 8.4.x, your tcltklib.so uses libraries of Tcl/Tk8.4.
And indeed it is:
$ ruby -r tk -e "p Tk::TK_PATCHLEVEL"
"8.4.19"
or re-compile your ruby's tcltklib.so with Tcl/Tk8.5.

Back to the "I'm not a source code compiler type", can you give me some
hint, how to do this? (not the 'make install' entry, but can it be
independently recompiled from source or only together with other files
or I need to recompile the whole Ruby package. And most importantly,
what are the parameters that make it link to Tk8.5?)

Thanks

I tried to replace tcltklib.so with your
tcltklib.so-tk8.5.7-ruby192dev_20100313rev26900_i686-linux but that .so
introduced other unsatisfied dependencies (like libstdc++.so.5)
 
H

Hidetoshi NAGAI

From: L=E1szl=F3 F=F6ldes <[email protected]>
Subject: Re: Tk and Tile with Tk8.5
Date: Sun, 3 Apr 2011 06:38:47 +0900
Message-ID: said:
And indeed it is:
$ ruby -r tk -e "p Tk::TK_PATCHLEVEL"
"8.4.19"

Are there tk-tile package for Tcl/Tk8.4 on Ubuntu 10.10 ?
If it exists, please try to install the package.
Back to the "I'm not a source code compiler type", can you give me so=
me =
hint, how to do this? (not the 'make install' entry, but can it be =
independently recompiled from source or only together with other file=
s =
or I need to recompile the whole Ruby package. And most importantly, =
what are the parameters that make it link to Tk8.5?)

First of all, I'm not familiar with Debian packages.
So, I can't tell you how to create your own Ruby/Tk package with Tcl/Tk=
8.5.

In general, extconf.rb of tcltklib (<ruby-src-dir>/ext/tk/extconf.rb)
searches automatically the latest version of Tcl/Tk on the system.
If you are luky ;-), you'll be able to make a new ruby by =

"cd <ruby-src-dir>; ./configure; make". =

# Of course, it requires Tcl/Tk dev packages.

Please check the messages of make steps.
tcltklib's extconf.rb shows the status of searching Tcl/Tk libraries.
If it shows fail messages, you must give configure options.
Please see <ruby-src-dir/ext/tk/README.tcltklib. It describes
configure options to teach position of Tcl/Tk libs to extconf.rb.
Although there are many combinations of options to match several env, =

please try to give --with-tclConfig-file=3D<path of tclConfig.sh> and =

--with-tkConfig-file=3D<path of tkConfig.sh> at first.

If you have some trouble, please tell me the fail messages and the
position of your Tcl/Tk headers and libraries.
I tried to replace tcltklib.so with your =
tcltklib.so-tk8.5.7-ruby192dev_20100313rev26900_i686-linux but that .=
so =
introduced other unsatisfied dependencies (like libstdc++.so.5)

Sorry. It was compiled on an old environment (gcc-3.3).
Even if it is available, I don't recommnd partial replace of package fi=
les.
It may break the package management system.
-- =

Hidetoshi NAGAI ([email protected])
Department of Artificial Intelligence, Kyushu Institute of Technology
 
A

Albert Schlef

L=C3=A1szl=C3=B3 F=C3=B6ldes wrote in post #990509:
I want to use Ruby 1.9.1 (Ubuntu 10.10) with Tk8.5 Tile, but this samle=
code:
[...]
I'm not a source code compiler type, I
installed everything from aptitude (Ruby 1.9.1, Tk8.4, Tk8.5, Tcl8.4,
Tcl8.5)

Hi!

I'm using Ubuntu 10.04.1, but it probably isn't different than yours.

You need install tile:

$ sudo apt-get install tk-tile

Note that Ruby will still use the ugly Tk 8.4. If you want it to use Tk
8.5 (but you don't have to), follow these steps:

http://drx.rubyforge.org/ubuntu-new-tk.html

BTW, your program works on my system: I tried it with both Tk 8.4 and Tk
8.5 (I have a script that toggles between them).

-- =

Posted via http://www.ruby-forum.com/.=
 
A

Albert Schlef

L=C3=A1szl=C3=B3 F=C3=B6ldes wrote in post #990721:
Albert Schlef wrote in post #990613:

Thanks, that solved it! (although the solution at the link has some
serious =C3=BCberbug, although not irreparable).

What's the "=C3=BCberbug"? Tell us, so that page (ubuntu-new-tk.html) cou=
ld =

be fixed.
Just for curiosity, how do you toggle between the two? As I saw it the
Tk version is compiled into the tcltklib.so.

Right. I copy the 8.4 version into "tcltklib.so.84", and the 8.5 version =

into "tcltklib.so.85", and my script simply copies the desired version =

into "tcltklib.so". (To do this it uses the 'sudo' command because the =

/usr/lib/ruby/1.8/i486-linux/ directory is writable for root only.)

-- =

Posted via http://www.ruby-forum.com/.=
 
H

Hidetoshi NAGAI

From: Albert Schlef <[email protected]>
Subject: Re: Tk and Tile with Tk8.5
Date: Mon, 4 Apr 2011 21:57:34 +0900
Message-ID: said:
Right. I copy the 8.4 version into "tcltklib.so.84", and the 8.5 version
into "tcltklib.so.85", and my script simply copies the desired version
into "tcltklib.so". (To do this it uses the 'sudo' command because the
/usr/lib/ruby/1.8/i486-linux/ directory is writable for root only.)

The following depend on an unofficial feature of ruby's dll loading.
At present, it will work. But I don't recomment it.

# I asked about the feature on ruby-dev ML. But I didn't discuss it.
# Because I didn't have enough time for discussion and I thought
# that there are not many people who requires such feature.

In the following, <dll-dir> denotes ruby's dll directory
(.e.g /usr/lib/ruby/1.8/i486-linux).

(1) Copy the 8.4 version to <dll-dir>/tcltklib.8.4.so, and the 8.5
version to <dll-dir>/tcltklib.8.5.so.
Filenames must start by "tcltklib" + dot, and end by dot + "so".
For example, "tcltklib.84.so" or "tcltklib.8.4.19.so" is OK,
but "tcltklib_84.so" or "tcltklib.so.84" is NG.

(2) Create loader script "tcltklib.rb" at ruby's library directory
(.e.g /usr/lib/ruby/1.8).
For example,
----- tcltklib.rb -----------------------------------------
ver = ENV['RUBYTK_VERSION']
if ver && !ver.empty?
require "tcltklib.#{ver}.so"
else
require "tcltklib.so"
end
-----------------------------------------------------------
This exmaple selects the dll based on the environment variable.
There are many way to decide the target dll.
Please create your tcltklib.rb as you like.

(3) If you use tcltklib.rb at step (2),
$ RUBYTK_VERSION=8.4 ruby -r tk -e 'p Tk::TK_PATCHLEVEL'
will use tcltklib.8.4.so (Tcl/Tk8.4 version), and
$ RUBYTK_VERSION=8.5 ruby -r tk -e 'p Tk::TK_PATCHLEVEL'
will use tcltklib.8.5.so (Tcl/Tk8.5 version)
 
A

Albert Schlef

Hidetoshi NAGAI wrote in post #990904:
The following depend on an unofficial feature of ruby's dll loading.
At present, it will work. But I don't recomment it.
[...]
(2) Create loader script "tcltklib.rb" at ruby's library directory
(.e.g /usr/lib/ruby/1.8).
For example,
----- tcltklib.rb -----------------------------------------
ver = ENV['RUBYTK_VERSION']
if ver && !ver.empty?
require "tcltklib.#{ver}.so"
else
require "tcltklib.so"
end

Hey, that's a nice trick. Thanks!
The following depend on an unofficial feature of ruby's dll loading.
At present, it will work. But I don't recomment it.

BTW, what's here isn't an official feature? I do "ri Kernel#require" and
(I think) it describes everything needed to make this work: Ruby first
looks for an .rb file (this enables us to inject our loader script), and
then it's possible to explicitly load a .so (or .dll). So why isn't your
trick future-proof?
 
H

Hidetoshi NAGAI

From: Albert Schlef <[email protected]>
Subject: Re: Tk and Tile with Tk8.5
Date: Tue, 5 Apr 2011 23:13:53 +0900
Message-ID: said:
BTW, what's here isn't an official feature? I do "ri Kernel#require" and
(I think) it describes everything needed to make this work: Ruby first
looks for an .rb file (this enables us to inject our loader script), and
then it's possible to explicitly load a .so (or .dll). So why isn't your
trick future-proof?

It depends on "how to find an entry point function of a DLL".
Ruby's current DLL loader decides a name from a filename of DLL,
that is, cuts a left most string from a DLL filename before first dot
and links it after a string "Init_".
So, for "tcltklib.so", "tcltklib.84.so", "tcltklib.8.5.9.so" and so
on, the loader calls a function "Init_tcltklib()".
But for "tcltklib_84.so" (and others), the loader tries and fails to
call a function "Init_tcltklib_84".
This is the reason of why a DLL filename is limitted on my trick.

The rule about "first dot" is NOT a specification of Ruby's DLL loader.
It may be changed in the future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top