Assorted Ruby/Tk Questions/Comments

B

Bill Atkins

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
 
H

Hidetoshi NAGAI

Hi,

From: (e-mail address removed) (Bill Atkins)
Subject: Assorted Ruby/Tk Questions/Comments
Date: Thu, 8 Apr 2004 05:24:18 +0900
Message-ID: said:
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') )
 

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 4
A "How to" about installing Ruby/TK for the Windows RubyInstaller 0
Ruby/tk Help Please 19
Ruby TK 2
A Tk window 20
More tk stuff 0
Bug with Ruby/Tk encoding (ruby-1.9.1-rc1) 6
Tk : non blocking Tk.mainloop 20

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top