[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

mdiam

1/6/2009 9:13:00 AM

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

6 Answers

Hidetoshi NAGAI

1/7/2009 4:09:00 AM

0

From: mdiam <Maurice.Diamantini@gmail.com>
Subject: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
Date: Tue, 6 Jan 2009 18:15:01 +0900
Message-ID: <dca4d3eb-f842-48cb-9627-f9f0231ded13@r37g2000prr.googlegroups.com>
> 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,
------------------------------------------------------
DEFAULT_TK_ENCODING = __ENCODING__
require 'tk'
------------------------------------------------------
or
------------------------------------------------------
require 'tk'
Tk.encoding = __ENCODING__
------------------------------------------------------
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

mdiam

1/8/2009 8:06:00 AM

0


On 7 jan, 05:08, Hidetoshi NAGAI <na...@ai.kyutech.ac.jp> wrote:

> > 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
> ------------------------------------------------------
>

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




Hidetoshi NAGAI

1/8/2009 8:33:00 AM

0

From: mdiam <Maurice.Diamantini@gmail.com>
Subject: Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
Date: Thu, 8 Jan 2009 17:09:54 +0900
Message-ID: <761cba1a-8f93-4d25-b110-7bcc80a60b92@z27g2000prd.googlegroups.com>
> 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.
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Hidetoshi NAGAI

1/9/2009 5:13:00 AM

0

From: Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Subject: Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
Date: Thu, 8 Jan 2009 17:32:56 +0900
Message-ID: <20090108.173314.104043405.nagai@ai.kyutech.ac.jp>
> 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'
--------------------------------------------------------------
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

mdiam

1/9/2009 4:05:00 PM

0

comp.lang.ruby
nagai@ai.kyutech.ac.jp

On Jan 9, 6:12 am, Hidetoshi NAGAI <na...@ai.kyutech.ac.jp> wrote:
> From: Hidetoshi NAGAI <na...@ai.kyutech.ac.jp>
> Subject: Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
> Date: Thu, 8 Jan 2009 17:32:56 +0900
> Message-ID: <20090108.173314.104043405.nagai@ai.kyutech.ac.jp>
>
> > 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.
> ...

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


Hidetoshi NAGAI

1/12/2009 5:29:00 PM

0

From: mdiam <Maurice.Diamantini@gmail.com>
Subject: Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
Date: Sat, 10 Jan 2009 01:10:09 +0900
Message-ID: <df254d96-4af1-4afb-90b1-f57781c672eb@g3g2000pre.googlegroups.com>
> 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.
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)