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

Discussion in 'Ruby' started by mdiam, Jan 6, 2009.

  1. mdiam

    mdiam Guest

    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
     
    mdiam, Jan 6, 2009
    #1
    1. Advertising

  2. Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)

    From: mdiam <>
    Subject: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
    Date: Tue, 6 Jan 2009 18:15:01 +0900
    Message-ID: <>
    > 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 ()
     
    Hidetoshi NAGAI, Jan 7, 2009
    #2
    1. Advertising

  3. mdiam

    mdiam Guest

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

    On 7 jan, 05:08, Hidetoshi NAGAI <> 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
     
    mdiam, Jan 8, 2009
    #3
  4. Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)

    From: mdiam <>
    Subject: Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
    Date: Thu, 8 Jan 2009 17:09:54 +0900
    Message-ID: <>
    > 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 ()
     
    Hidetoshi NAGAI, Jan 8, 2009
    #4
  5. Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)

    From: Hidetoshi NAGAI <>
    Subject: Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
    Date: Thu, 8 Jan 2009 17:32:56 +0900
    Message-ID: <>
    > 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 ()
     
    Hidetoshi NAGAI, Jan 9, 2009
    #5
  6. mdiam

    mdiam Guest

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

    comp.lang.ruby


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

    From: mdiam <>
    Subject: Re: Bug with Ruby/Tk encoding (ruby-1.9.1-rc1)
    Date: Sat, 10 Jan 2009 01:10:09 +0900
    Message-ID: <>
    > 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 ()
     
    Hidetoshi NAGAI, Jan 12, 2009
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john peter
    Replies:
    0
    Views:
    91
    john peter
    Apr 4, 2006
  2. john peter
    Replies:
    0
    Views:
    99
    john peter
    Apr 4, 2006
  3. Huw Collingbourne

    [ANN] Ruby In Steel Personal Edition RC1

    Huw Collingbourne, Jan 2, 2007, in forum: Ruby
    Replies:
    0
    Views:
    110
    Huw Collingbourne
    Jan 2, 2007
  4. KUBO Takehiro

    [ANN] ruby-oci8 1.0.0-rc1

    KUBO Takehiro, Jan 20, 2007, in forum: Ruby
    Replies:
    0
    Views:
    115
    KUBO Takehiro
    Jan 20, 2007
  5. Jian Lin
    Replies:
    1
    Views:
    145
    Luis Lavena
    Dec 9, 2009
Loading...

Share This Page