Assorted Ruby/Tk Questions/Comments

Discussion in 'Ruby' started by Bill Atkins, Apr 7, 2004.

  1. Bill Atkins

    Bill Atkins Guest

    I'm looking into using Ruby/Tk for a major project. Maybe I'm crazy,
    but I find its interface cleaner than that of FOX. I'm very
    experienced with Perl/Tk, but I'm just getting started with the Ruby
    port. Here are some questions and observations:


    1. There appears to be a bug in TkRoot.new (or possibly TkWindow.new).
    On my Win2K box, the following code:

    require 'tk'

    TkRoot.new do
    puts "test"
    end

    produces:
    test
    test

    The block is being called twice. This can be prevented with the
    following code:

    TkRoot.new do
    return if @here
    @here = true

    ...
    end

    This looks like a bug to me.

    2. Do I have to install Tcl on *NIX boxes to use Ruby/Tk? I know I
    can just redistribute the DLL's on Windows, but how does this work on
    NIX? Does Ruby/Tk come with everything it needs to run right out of
    the box?

    3. How can I use TkTree? It looks like it's in the tcltk-ext
    package, but I'm not sure how to use this on Windows. Or Linux for
    that matter. Does this also require Tcl to be installed?

    4. pack doesn't accept a block, even though Programming Ruby implies
    that this is so. I've written the following code to allow pack to
    accept a block. It's hackish, so maybe someone more familiar with the
    Ruby/Tk internals can improve it:

    class TkWindow
    class PackContext
    attr_reader :args

    def initialize
    @args = {}
    end

    def method_missing(sym, *args)
    name = sym.id2name
    @args[name] = args[0]
    end
    end

    alias_method :eek:ld_pack, :pack

    def pack(*args, &b)
    if block_given?
    pc = PackContext.new
    pc.instance_eval(&b)
    params = pc.args
    else
    params = *args
    end
    old_pack(params)
    end
    end

    Then you can do things like

    label.pack do
    expand 1
    fill "both"
    end

    which is kind of useful to me.

    5. Are there any special reasons not to use Tk? I need a toolkit
    with a clean interface and small footprint.

    Thanks in advance for your help,
    Bill Atkins
    Bill Atkins, Apr 7, 2004
    #1
    1. Advertising

  2. Hi,

    From: (Bill Atkins)
    Subject: Assorted Ruby/Tk Questions/Comments
    Date: Thu, 8 Apr 2004 05:24:18 +0900
    Message-ID: <>
    > The block is being called twice. This can be prevented with the

    (snip)
    > This looks like a bug to me.


    Yes. It's a bug. Thank you for your report.
    This problem will be fixed by the following patch.

    --- tk.rb.orig 2004-04-08 11:49:48.000000000 +0900
    +++ tk.rb 2004-04-08 11:50:01.000000000 +0900
    @@ -4532,7 +4532,7 @@
    def TkRoot.new(keys=nil, &b)
    unless TkCore::INTERP.tk_windows['.']
    TkCore::INTERP.tk_windows['.'] =
    - super:)without_creating=>true, :widgetname=>'.')
    + super:)without_creating=>true, :widgetname=>'.'){}
    end
    root = TkCore::INTERP.tk_windows['.']
    if keys # wm commands


    > 2. Do I have to install Tcl on *NIX boxes to use Ruby/Tk? I know I
    > can just redistribute the DLL's on Windows, but how does this work on
    > NIX? Does Ruby/Tk come with everything it needs to run right out of
    > the box?


    Yes. You must install Tcl/Tk libraries.
    Ruby/Tk calls functions of Tcl/Tk library.

    The Ancient Ruby/Tk used interp process communication
    between Ruby and Wish. It's too slow!!
    But current Ruby/Tk loads Tcl/Tk libraries into Ruby.

    It's an important difference between Ruby/Tk and Perl/Tk.
    Because of controlling pure Tcl/Tk libraries,
    Ruby/Tk can use almost all of Tcl/Tk extentions.
    Of course, before using a extention from Ruby,
    you must make your Tcl/Tk can use the extention.

    However, to control Tcl/Tk extentions conveniently,
    you will define classes and methods for the extentions.
    The 'tcltk-ext' library creates the base of definition automatically.

    > 3. How can I use TkTree? It looks like it's in the tcltk-ext
    > package, but I'm not sure how to use this on Windows. Or Linux for
    > that matter. Does this also require Tcl to be installed?


    Do you say about TixTree?
    If you want to use TixTree class, your Tcl/Tk must be able to use
    Tix extention.

    > 4. pack doesn't accept a block, even though Programming Ruby implies
    > that this is so. I've written the following code to allow pack to
    > accept a block. It's hackish, so maybe someone more familiar with the
    > Ruby/Tk internals can improve it:

    (snip)
    > Then you can do things like
    >
    > label.pack do
    > expand 1
    > fill "both"
    > end
    >
    > which is kind of useful to me.


    Hmmm... Do you want the feature strongly?
    Cannot a Hash parameter satisfy you?
    (e.g label.pack:)expand=>true, :fill=>'both') )
    --
    Hidetoshi NAGAI ()
    Hidetoshi NAGAI, Apr 8, 2004
    #2
    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. Replies:
    24
    Views:
    612
    jeffc
    Oct 24, 2003
  2. John Perks and Sarah Mount

    Assorted JNI questions

    John Perks and Sarah Mount, Oct 2, 2005, in forum: Java
    Replies:
    5
    Views:
    1,257
    Roedy Green
    Oct 6, 2005
  3. Replies:
    24
    Views:
    602
    jeffc
    Oct 24, 2003
  4. Replies:
    26
    Views:
    623
    jeffc
    Oct 24, 2003
  5. V.Ch.

    Assorted questions from a C++ programmer

    V.Ch., May 10, 2005, in forum: C Programming
    Replies:
    8
    Views:
    321
    Eric Sosman
    May 12, 2005
Loading...

Share This Page