Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)

M

mdiam

Bonjour à tous,

I have a script starting like this :

#!/usr/bin/env ruby
# encoding: iso8859-1

When I lauch it, the following error occurs:

..../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb:3028:in `find':
unknown encoding name - (ArgumentError)
from /.../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb:3028:in `<top (required)
from ./gotic:1565:in `require'
from ./gotic:1565:in `test_tk'
...

The test_tk top method is the following:

def test_tk
require 'tk'
root = TkRoot.new { title "Test de Tk sous Ruby" }
TkLabel.new(root) {
text 'Essai de Ruby/Tk !'
pack { padx 15 ; pady 15; side 'left' }
}
TkButton.new(root) {
text 'Quitter'
pack { padx 15 ; pady 15; side 'bottom' }
command 'exit'
}
Tk.mainloop
end #def test_tk


Also, is there any online doc on all the encoding feature from
ruby-1.9.1???
For sample, can we specifiy anywhere in the toplevel pplication file
(and not in **all* file
the encoding?

Thank you very much.
-- Maurice
 
H

Hidetoshi NAGAI

From: mdiam <[email protected]>
Subject: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
Date: Tue, 6 Jan 2009 18:15:01 +0900
Message-ID: said:
I have a script starting like this :

#!/usr/bin/env ruby
# encoding: iso8859-1

When I lauch it, the following error occurs:

I can't regenerate the error.
.../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb:3028:in `find':
unknown encoding name - (ArgumentError)
from /.../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb:3028:in `<top (required)>'

Probably, the error occurs on Encoding.find(),
but tk.rb:3028 doesn't include the method.
On my archive, tk.rb:3028 is a comment line.

Please check your '.../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb' file.
tk.rb included ruby-1.9.1-rc1 has the following line (line:5553).
------------------------------------------------------
RELEASE_DATE = '2008-12-21'.freeze
------------------------------------------------------
Also, is there any online doc on all the encoding feature from
ruby-1.9.1???

Not all, but about Ruby/Tk, its default rules are the followings.

* Use Encoding.default_external for terminal outputs of Tcl/Tk libraries.
It can be referd/changed with Tk.encoding_system/encoding_system=.

* Use Encoding.default_internal for strings passed from Tcl/Tk libraries
to Ruby. It can be referd/changed with Tk.encoding/encoding=. However,
if the constant DEFAULT_TK_ENCODING is defined before 'require "tk"',
Ruby/Tk use it instead of Encoding.default_internal.
If DEFAULT_TK_ENCODING is not defined and Encoding.default_internal
is nil, use Encoding.default_external.

It may be better that Ruby/Tk returns strings by caller's script encoding.
But, if I'm right, libraries (e.g. tk.rb) can't know caller's script
encoding (at least, by low cost).
So, Ruby/Tk supports the global status (Tk.encoding) only.

Well, you can get current script encoding by __ENCODING__.
If you want to use it for Ruby/Tk, for example,
 
M

mdiam

I can't regenerate the error.


Probably, the error occurs on Encoding.find(),
but tk.rb:3028 doesn't include the method.
On my archive, tk.rb:3028 is a comment line.

Please check your '.../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb' file.
tk.rb included ruby-1.9.1-rc1 has the following line (line:5553).

Your are right, I had inserted some comments for debugging
(without success).
So I have the same version as yours (standard ruby-1.9.1-rc1)

The problem occurs while calling the require "tk".
So the Tk.encoding cannot be used.

Here is a minimalist full sample

#!/usr/bin/env ruby
# encoding: iso8859-1 # because of the puts "éléphant"
#
puts "Encoding.default_external=#{Encoding.default_external}"
puts "Encoding.default_internal=#{Encoding.default_internal}"
puts "Encoding.__ENCODING__=#{__ENCODING__}"

Encoding.default_external="iso-8859-15"
Encoding.default_internal="iso-8859-15"

puts "Encoding.default_external=#{Encoding.default_external}"
puts "Encoding.default_internal=#{Encoding.default_internal}"
puts "Encoding.__ENCODING__=#{__ENCODING__}"

puts "Bonjour l'éléphant !"

# Simple création d'un bouton avec "quitter" comme action
DEFAULT_TK_ENCODING=__ENCODING__
def tktest
require 'tk'
root = TkRoot.new { title "Test de Tk sous Ruby" }
TkLabel.new(root) {
text 'Essai de Ruby/Tk !'
pack { padx 15 ; pady 15; side 'left' }
}
TkButton.new(root) {
text 'Quitter'
pack { padx 15 ; pady 15; side 'bottom' }
command 'exit'
}
Tk.mainloop
end
tktest

And here are the full result:

ruby -version
ruby 1.9.1 (2008-12-30 patchlevel-0 revision 21203) [powerpc-
darwin9.6.0]


../tktest.rb
Encoding.default_external=ASCII-8BIT
Encoding.default_internal=
Encoding.__ENCODING__=ISO-8859-1
Encoding.default_external=ISO-8859-15
Encoding.default_internal=ISO-8859-15
Encoding.__ENCODING__=ISO-8859-1
Bonjour l'éléphant !
/home/.../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb:3022:in `find':
unknown encoding name - (ArgumentError)
from /home/.../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb:3022:
in `<top (required)>'
from ./tktest.rb:19:in `require'
from ./tktest.rb:19:in `tktest'
from ./tktest.rb:33:in `<main>'

(the standard Tk window appears just before the error)

-- Maurice Diamantini at ensta.fr
 
H

Hidetoshi NAGAI

From: mdiam <[email protected]>
Subject: Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
Date: Thu, 8 Jan 2009 17:09:54 +0900
Message-ID: said:
Your are right, I had inserted some comments for debugging
(without success).

I see.
/home/.../ruby-1.9.1-rc1/lib/ruby/1.9.1/tk.rb:3022:in `find':
unknown encoding name - (ArgumentError)

The line is
-------------------------------------------------------------
loc_enc_obj = ::Encoding.find:):Encoding.locale_charmap)
-------------------------------------------------------------

It means that "Encoding.locale_charmap" returns an empty string.
Though I believed that this line gets current locale information,
it may be wrong.
I'll ask M17N maintainers about Encoding.locale_charmap.
Please give me a few days.
 
H

Hidetoshi NAGAI

From: Hidetoshi NAGAI <[email protected]>
Subject: Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
Date: Thu, 8 Jan 2009 17:32:56 +0900
Message-ID: said:
It means that "Encoding.locale_charmap" returns an empty string.

It may be abnormal. However, Ruby/Tk will rescue it.
Please try the following patch.
--------------------------------------------------------------
Index: ext/tk/lib/tk.rb
===================================================================
--- ext/tk/lib/tk.rb (revision 21405)
+++ ext/tk/lib/tk.rb (working copy)
@@ -3019,7 +3019,7 @@
end

else ### Ruby 1.9 !!!!!!!!!!!!
- loc_enc_obj = ::Encoding.find:):Encoding.locale_charmap)
+ loc_enc_obj = :):Encoding.find:):Encoding.locale_charmap) rescue Tk::Encoding::UNKNOWN)
ext_enc_obj = ::Encoding.default_external
int_enc_obj = ::Encoding.default_internal || ext_enc_obj
tksys_enc_name = Tk::Encoding::ENCODING_TABLE.get_name(Tk.encoding_system)
@@ -5550,7 +5550,7 @@
#Tk.freeze

module Tk
- RELEASE_DATE = '2008-12-21'.freeze
+ RELEASE_DATE = '2009-01-09'.freeze

autoload :AUTO_PATH, 'tk/variable'
autoload :TCL_PACKAGE_PATH, 'tk/variable'
 
M

mdiam

comp.lang.ruby
(e-mail address removed)

From: Hidetoshi NAGAI <[email protected]>
Subject: Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
Date: Thu, 8 Jan 2009 17:32:56 +0900


It may be abnormal. However, Ruby/Tk will rescue it.
Please try the following patch.
...

I've done the following (manually):

# loc_enc_obj = ::Encoding.find:):Encoding.locale_charmap)
loc_enc_obj = :):Encoding.find:):Encoding.locale_charmap) rescue
Tk::Encoding::UNKNOWN)

Now, the
require "tk"
works: the Tk main window appears and is start to resize (like the
expected button size).
So the encoding problem seems solved: *** thank you very much
Hidetoshi!! *** ...

....but I don't see any button and the Tk windows blocks.

Perhaps, it's a problem with bad version of tk, or a bad compil
options:
irb
require "tk"
=> true
irb(main):007:0* Tk.info :lib
=> "/System/Library/Frameworks/Tcl.framework/Versions/8.4/Resources/
Scripts"

But I remember I tried to compile ruby with a personnal tcl/tk version
(8.5.5 with x11)
in a specific location, which don't seems used at runtime.

So, is there a mean to tell Ruby (at runtime) to use a particular tcl/
tk version (something witch could be name "RUBY_TCLTK_LIB")?

Or better question:
This problem arise because ruby doesn't integrate tk in itself.
So is there a mean to tell ruby at compile time:
"I want to use **that** tcl/tk sources, and
compile it as a special tcltklib version
with all specific options you need for
it to work with ruby!"

I know this will make a "big" ruby distribution, but it will be much
(MUCH) easier
to install and to maintain !
I think that such a compil option would help people make a robust ruby/
tk
comparable to (ideally) the tcl/tk version

-- Maurice
 
H

Hidetoshi NAGAI

From: mdiam <[email protected]>
Subject: Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
Date: Sat, 10 Jan 2009 01:10:09 +0900
Message-ID: said:
So, is there a mean to tell Ruby (at runtime) to use a particular tcl/
tk version (something witch could be name "RUBY_TCLTK_LIB")?

Please use Tk::TK_PATCHLEVEL
Or better question:
This problem arise because ruby doesn't integrate tk in itself.
So is there a mean to tell ruby at compile time:
"I want to use **that** tcl/tk sources, and
compile it as a special tcltklib version
with all specific options you need for
it to work with ruby!"

Please read "<ruby-src>/ext/tk/README.tcltklib" about configure options.
 

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

Similar Threads

Ruby TK 2
Tk and Tile with Tk8.5 9
Ruby 1.9.1 build and Tk 1
ruby/tk : hide TkFrame 1
Ruby/Tk 10
Ruby/Tk? 1
A "How to" about installing Ruby/TK for the Windows RubyInstaller 0
Ruby/tk Help Please 19

Members online

No members online now.

Forum statistics

Threads
473,913
Messages
2,570,027
Members
46,421
Latest member
WaylonBran

Latest Threads

Top