Looking for better Ruby/Tk references...

C

Chris Dagnon

... or better GUI APIs for Ruby.
(Primary questions at the bottom)


- Long Version/Background -
Hello all and sorry for the disruption, but I'm mid-stream of learning
Ruby and I have some GUIs I want to write. However Ruby/Tk... isn't as
easy as falling down a hill. The best part of it is that it comes in
the Ruby install for Windows XP which I downloaded. The second best
part is that the Pragmatic guide has a short chapter on it.

Using it is a different story. Yes, I have managed to make some GUIs -
my standard Tic-Tac-Toe GUI, a file explorer, and a basic text editor.
But I'm finding it very, very hard to get any more complex primarily
because I cannot find any definitive information on it. Certainly there
is the "Use Perl/Tk manuals by doing the following translations" key,
except that is incorrect for non-basic elements, if they even appear in
Ruby/Tk. TkOptionMenubutton isn't from Tk, and the 3 TkOption*'s don't
seem to fit the 2 Option*'s in Tk.

I've also gone through some other references like the MacDevCenter Tk
Primer - states that you need to start your option list with a '*' or it
doesn't work. However mine worked fine without it, which I hope means
that the API has matured since then and not what it could otherwise mean.

This page (email) gives a better overview of Ruby/Tk than most do, but
again lacks many of the specifics I need to get the API to work.
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138653?help-en

On a more philosophical note, I am still getting used to Ruby and having
to script things instead of write-and-compile things, and my question is:

Can Ruby be made explicit instead of implicit?

I can grant you that Java only seems explicit to me because:
a) I've spent enough time on the basics that I never have to think about
them anymore, and
b) that IDEs have had Ctrl+Space working for a long time for it, and
c) I can always fall back on the somewhat informative Javadoc at
java.sun.com.

So are there IDEs for Ruby which provide everything Eclipse provides
including the things which Ruby's scriptiveness requires, like
validating variable names are of the correct type and scope and defined
beforehand? Perhaps also including an IRB - minus the double
character-per-keypress like the SciTE(?).

I fought long enough with Swing and SWT to make my own basic enclosing
APIs so that if everything compiled, everything ran (usually even
correctly). With Ruby that isn't possible, but I'm curious if a better
paradigm could exist with Ruby and GUIs.




- Short Version -
My questions are:

0. Which version of Tcl/Tk does Ruby/Tk correspond to? Is there an
exact translation list showing which elements have Ruby/Tk counterparts,
or where to find implementations of them? (I haven't tried using
tkextlib yet)

1. Is there a definitive list of all valid key-value pairs for any or
all Tk elements? Explicitly listed with the method used to set them,
eg. .configure() or .command() etc. Hopefully also with one or more
examples of each and an explanation of what effects they are defined as
having (say, a Unit Text for each key-value pair?). If the only
resource are the Tcl/Tk man pages (where elements don't match 1-to-1 for
Ruby/Tk), have those been effective for others?

1b. A more definitive list of bind event name/combinations would be much
appreciated, as well as if .command() doesn't exist for an element
(having problems using it for TkOptionMenubutton), what can be used
instead on a change - or to bind to the associated TkVariable's change.

2. Has anyone compare/contrasted the existing GUI APIs for Ruby? Do any
of them have a Visual Studio? Or do any which can easily install on
Windows XP by a newbie have a Visual Design utility? I'm especially
interested in one which supports multiple monitors and a variety of
resolutions.

3. Is there an index page or GUI to definitively show what in the
ruby\tk subdirectories are runnable demos/samples and which are simply
included files?

4. Is there a Ruby/Tk homepage or Bugzilla? Several things have shown
incorrect behaviour, including TkOptionMenubutton where at times the
menu pops up completely separated from the menu or even the GUI itself.
I suppose that could be my settings' fault, however I'd still consider
that a bug if it was.


Thanks for any pointers,

-Chris
 
J

Justin Meyer

Hi Chris!

... or better GUI APIs for Ruby.
(Primary questions at the bottom)

... well, without stepping into that minefield...
again lacks many of the specifics I need to get the API to work.
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138653?help-en

... and without answering your other questions, is the following link of
any use to you?

http://www.jbrowse.com/text/rubytk_en.html

I'm no good for further details; I just happened to have that link
laying around :)

Cheers,
 
C

Chris Dagnon

... and without answering your other questions, is the following

That is a much better reference than what I've found so far - gives both
an overview and some details, drill-downs for the different levels of
info and even a few implementation examples. Still not every detail I
need (missing TkOptionMenubutton and it's relationship to the whole),
and it is a lot to digest at once. But at least it is a lot :)

Thanks!

-Chris
 
C

Chris Dagnon

Now that I think of it, a better question is:

Ruby allows defaults to be stated for all parameters to a method.

Has/Can someone implement Ruby/Tk with *all* parameters (configure,
commands, bind's...) specifically stated with their defaults?


I hope,

-Chris
 
G

gregarican

Chris said:
Has/Can someone implement Ruby/Tk with *all* parameters (configure,
commands, bind's...) specifically stated with their defaults?

I'm not sure if this type of writeup currently exists. If you look
through the http://www.jbrowse.com/text/rubytk_en.html document you
still don't get enough information to get your project going? I had a
couple of projects that I used with Ruby/Tk and found this document to
help fill in the blanks pretty well. That and perhaps translating a
Perl/Tk book to Ruby's terms. I know these aren't ideal solutions but
they should get you maybe 90% of the way there...
 
G

gregarican

Here is a good link that is a Tk reference -->
http://www.tcl.tk/man/tcl8.4/TkCmd/contents.htm. Then taking into
considering how Ruby/Tk prefixes the widget names with a Tk and how
Ruby treats the various parameters in hash-like fashion you should get
an idea on how to manipulate things. For example:

myLabel=TkLabel.new(myTkRoot) {text 'myText'
font 'myFontNameAndSize'
}.grid:)column=>1, :row=>0)
 
J

Joe Van Dyk

Here is a good link that is a Tk reference -->
http://www.tcl.tk/man/tcl8.4/TkCmd/contents.htm. Then taking into
considering how Ruby/Tk prefixes the widget names with a Tk and how
Ruby treats the various parameters in hash-like fashion you should get
an idea on how to manipulate things. For example:

myLabel=3DTkLabel.new(myTkRoot) {text 'myText'
font 'myFontNameAndSize'
}.grid:)column=3D>1, :row=3D>0)

I really prefer ruby-gnome2's API to tk's. It makes a whole lot more
sense to me (and the documentation is a lot better).

Gtk.init
window =3D Gtk::Window.new
label =3D Gtk::Label.new "my test"
window << label
window.show_all
Gtk.main_loop
 
G

gregarican

Joe said:
I really prefer ruby-gnome2's API to tk's. It makes a whole lot more
sense to me (and the documentation is a lot better).

Me too. The fact that Tk comes bundled with the vanilla Ruby
installation (esp. in terms of the Windows One Click deal) makes it a
toolkit that folks hit the ground running with. But for me I feel that
GTK and Qt are a little more object oriented and are a better fit in
terms of Ruby. Plus like you said, the documentation is a lot better.
It's just a shame that in terms of Windows implementations the Qt
library really only works for Cygwin installs. The only way I got it to
work on non-Cygwin installs was by using a Qt binary fileset published
for Ruby 1.6.8...
 
T

tony summerfelt

Joe Van Dyk wrote on 12/22/2005 11:00 PM:
I really prefer ruby-gnome2's API to tk's. It makes a whole lot more
sense to me (and the documentation is a lot better).

i've been playing around with gtk the last couple of days. your
example DOES look cleaner...until you start getting into non-trivial
gui's...ruby/tk's stays about the same, but gtk's ramps WAY up.

and gtk doesn't play well with ruby2script, i'd rather not have an
end-user install gtk themselves ('cause you just know they're going to
get all the environment variables wrong).

while the documentation for gtk seems a lot better, it lacks useful
examples. i wanted to create a simple text editor similar to the one
found here: http://tinyurl.com/cmbrl that example was too old for the
recent versions of ruby/gtk

i browsed the relevant documentation for hours (being new to gtk on
any platform) but coudln't find what i needed to change. granted i've
not done gui work in ruby before, but it shouldn't have been that hard
to crank out something as trivial as that.
 
J

Joe Van Dyk

Joe Van Dyk wrote on 12/22/2005 11:00 PM:


i've been playing around with gtk the last couple of days. your
example DOES look cleaner...until you start getting into non-trivial
gui's...ruby/tk's stays about the same, but gtk's ramps WAY up.

and gtk doesn't play well with ruby2script, i'd rather not have an
end-user install gtk themselves ('cause you just know they're going to
get all the environment variables wrong).

while the documentation for gtk seems a lot better, it lacks useful
examples. i wanted to create a simple text editor similar to the one
found here: http://tinyurl.com/cmbrl that example was too old for the
recent versions of ruby/gtk

i browsed the relevant documentation for hours (being new to gtk on
any platform) but coudln't find what i needed to change. granted i've
not done gui work in ruby before, but it shouldn't have been that hard
to crank out something as trivial as that.


http://ruby-gnome2.sourceforge.jp/hiki.cgi?Simple+Text+Editor
 
R

ruby talk

------=_Part_15703_5231114.1137076275760
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I am working with tk to, and i find it hard to work with the examples i
find. I think the lack of good docs or examples holds me back from somethin=
g
i would like to do. For example I wish i knew about the TkOptionMenubutton.
I created this code
this snippet gets the list of files on the hard drive then displays them in
the menu. u can go back and forth between folders. When you click a file it
adds it to the text box

Code:
require "tk"
def MakeMenu (dir)
a=3DArray.new
dirarray=3DDir.entries(dir)
menu1 =3D TkMenu.new {
add 'command', {'label'=3D>"File", 'command'=3D>proc { }}
dirarray.each { |ax|
if File.file?(dir+"\\"+ax)
add 'command', {'label'=3D>ax, 'command'=3D>proc {
$Sendfile.value=3D$Sendfile.value+"  "+dir.gsub(' ','|')+"\\"+ax}}
end
if File.directory?(dir+"\\"+ax) and ax !=3D"." and
add 'command', {'label'=3D>ax, 'command'=3D>proc {MakeMenu(dir+"\\"+ax)=
}}
end
}

}
#pop up options
menu1.post TkWinfo.pointerx(root) ,TkWinfo.pointery(root)
end
root=3DTkRoot.new
usrname =3D TkVariable.new
v1 =3D TkVariable.new
$set_to_read =3DTkVariable.new
$email_array=3DArray.new
password =3D TkVariable.new
$Current_id=3DTkVariable.new
a=3DArray.new

radio_var =3D TkVariable.new('y')
$Voice_use=3D TkVariable.new(true)

TkFrame.new(root){
$Sendfile=3DTkText.new(self).pack "side"=3D>"top"
$Sendfile.width=3D50
$Sendfile.height=3D1
$options=3DTkButton.new(self) {text "files"
command {
MakeMenu("c:\\")
}
}.pack "side"=3D>"left"

pack}.grid "column"=3D>0,"row"=3D>3
TkFrame.new(root) {
}.grid "column"=3D>5, "row"=3D>5, "columnspan"=3D>5,"rowspan"=3D>5
Tk.mainloop

[code]

It is not as nice looking as a pull down menu, but its neat. I use it for
alot of my option menus.



[QUOTE]
That is a much better reference than what I've found so far - gives both
an overview and some details, drill-downs for the different levels of
info and even a few implementation examples.  Still not every detail I
need (missing TkOptionMenubutton and it's relationship to the whole),
and it is a lot to digest at once.  But at least it is a lot :)

Thanks!

-Chris



n
[/QUOTE]

------=_Part_15703_5231114.1137076275760--
 
H

Hidetoshi NAGAI

From: ruby talk <[email protected]>
Subject: Re: Looking for better Ruby/Tk references...
Date: Thu, 12 Jan 2006 23:31:29 +0900
Message-ID: said:
I am working with tk to, and i find it hard to work with the examples i
find. I think the lack of good docs or examples holds me back from something
i would like to do. For example I wish i knew about the TkOptionMenubutton.
I created this code
this snippet gets the list of files on the hard drive then displays them in
the menu. u can go back and forth between folders. When you click a file it
adds it to the text box

Did you see the sample "ext/tk/sample/tkcombobox.rb" on
the Ruby source tree?
It may be useful in such case.
 
R

ruby talk

------=_Part_21269_17011048.1137103715400
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

My example does not do anything so i probably skipped over it. Its like the
C:\ruby\samples\tk\tkextlib examples.

Becker

From: ruby talk <[email protected]>
Subject: Re: Looking for better Ruby/Tk references...
Date: Thu, 12 Jan 2006 23:31:29 +0900
m e

Did you see the sample "ext/tk/sample/tkcombobox.rb" on
the Ruby source tree?
It may be useful in such case.

------=_Part_21269_17011048.1137103715400--
 
C

Cam

Hi,

2. Has anyone compare/contrasted the existing GUI APIs for Ruby? Do any
of them have a Visual Studio? Or do any which can easily install on
Windows XP by a newbie have a Visual Design utility? I'm especially
interested in one which supports multiple monitors and a variety of
resolutions.

Gtk can be used w/ glade (it works wonderfully for me). I'm not sure
if glade is available for windows or not. I'm assuming that Qt
Designer also works w/ ruby-qt, although I have never tried it myself.

Cameron Matheson
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top