Ruby has certainly won me over as far as command-line scripting is concerned, but I want to do more than that. Apart from wanting to write web apps with it (which I’ll probably discuss in a later post), I also want to use Ruby to write small, cross-platform GUI applications. So I spent a good deal of my free time last week doing just that, and found it to be at times rewarding and at times incredibly frustrating.

There’s a huge selection of GUI bindings for Ruby, allowing you to work with a wide variety of GUI toolkits. Unfortunately, most of these toolkits were intended to be used by C or C++ developers. As a result their APIs tend to be stodgy and, well, C-like, rather than Ruby-like, which is annoying since it can effectively suck the joy out of using Ruby.

That said, they’re not all bad; but none of them is all good either. Here’s a brief collection of thoughts on each of the toolkits I investigated.

Tk

The crotchety old man of cross-platform GUI toolkits. Took one look and ran away screaming. The API is a badly-documented mess, the widgets are non-native and ugly, and everyone who’s used it seems to hate it. Screw that.

FOX

I want to like FOX. Its Ruby API, provided by FXRuby, is good and well-documented, but FOX itself is a young project, and it shows. It seems to be developed primarily by one person, which is okay except that this person doesn’t have access to a Mac OS X system and thus can’t provide an OS X port. For me, this is a killer: Windows and OS X are my primary targets, followed by FreeBSD and Linux.

wxWidgets

A very stable, very mature toolkit with a good selection of widgets. Its most appealing feature is the fact that it uses native widgets whenever possible, thus ensuring a consistent look and feel with other applications on each platform. Furthermore, wxWidgets has excellent support for all the platforms I care about.

Unfortunately, the API is very C++-oriented, and the bindings provided by wxRuby do almost nothing to make it more Rubyish. What’s more, WxRuby has no documentation aside from a virtually useless auto-generated class and function list. They seem to expect developers to use the wxWidget API reference, which is, admittedly, well-written and very complete. However, WxRuby inexplicably leaves out a surprising number of API functions and, even more inexplicably, sometimes uses function signatures and constant names that differ from those of wxWidgets, occasionally even going so far as to change the actual purpose of a function. The result is a muddled mess, even though everything seems to work well if you actually take the time to cross-reference the wxWidgets API documentation with the WxRuby source code to figure out what you should be doing.

GTK+

By far the easiest to use of all the toolkits I looked at, which is due in no small part to Glade, a free UI designer that makes it a piece of pie to throw together a GTK+ GUI quickly with very little effort. The API bindings provided by Ruby-GNOME2 are excellent as well, and mostly do things in the Ruby Way™. The Ruby-GNOME2 project also provides excellent documentation and tutorials.

Unfortunately, GTK+ has its drawbacks. Windows support isn’t bad, and even uses native widgets in many places under Windows XP, but it requires a hefty set of runtime libraries. Unix support is excellent, of course, with the sad exception of—you guessed it —Mac OS X. It’s possible to run GTK+ apps in OS X using the X Windowing System, but this means your app looks inconsistent and ugly compared to the rest of the OS X interface.

To sum up, I’m frustrated. I want to like FOX, but it’s useless to me without OS X support. I think wxWidgets is superior to the others in almost every respect, except that it’s also useless to me because wxRuby is crap. And GTK+, while easy and painless and an absolute joy to use, has crappy OS X support and requires annoying runtimes on Windows.

Nevertheless, I think I’ve pretty much decided to use GTK+ for now. I’ve already developed one complete application with it (which I’ll release shortly), and I didn’t find it at all painful, especially compared to wxWidgets, which, thanks to WxRuby, makes me want to kill things.

Comments

but there exists a Cocoa framework for doing native osx development in ruby. Basically, it makes all of the regular Cocoa classes and utilties available to one's ruby application, and also lets one use the excellent Interface Builder to do the gui design. Tons of fun- all the joys of working with the Cocoa API without having to worry about Objective-C (a great language, as far as C-derivatives go, but not nearly as much fun to work in as Ruby).

Gravatar icon
bedrick
Sunday March 13, 2005 @ 01:27 PM (PST)

Sounds like I'd love it, except that it's not cross-platform. That's one more thing to add to my list of reasons why I need a Mac, though. :P

Gravatar icon
Sunday March 13, 2005 @ 02:34 PM (PST)

You WANT the Mac. So SHINY. *waves blue LED pendulum-style* You're feeling very hip...

Gravatar icon
Eilonwy
Sunday March 13, 2005 @ 03:24 PM (PST)

That's what the Mac mini was designed for. Just go pick one of them up. It'd work fine for developement of software while still not giving into their really expensive stuff.

Gravatar icon
electrofreak0110
Sunday March 13, 2005 @ 05:05 PM (PST)

Qt?

Did you look into Qt? I don't know what the Ruby bindings look like but it has good tools (Qt Designer is like Glade) and it's pretty nice to work with in its native C++. I've lost track of the licensing situation on the various platforms, but I think you should be able to hit your target platforms with one version or another.

And what's wrong with stodgy C[++]-like APIs? They're what make programming fun! Not to mention C toolkit APIs are a completely different beast than C++ (or other object-oriented) toolkits. I think an object-oriented toolkit would take it as a personal affront that you group it in the same judgment about stodginess as a procedural toolkit, and vice versa!
Gravatar icon
Zeus
Sunday March 13, 2005 @ 10:15 PM (PST)
I develop in Windows and Qt's development tools aren't currently available for Windows. They also have a really convoluted licensing scheme; any software I write using Qt must be released as open source under the GPL, unless I purchase a commercial license. Even though most of the software I write is GPLed, I don't want to tie myself to a restriction like that. What if I decide I want to switch to a BSD-style license? What if I decide I want to sell something I write? That said, I've used the Linux version of Qt Designer and I liked it a lot. I won't be using Qt unless they change their licensing scheme, though.

What's wrong with stodgy APIs? Gods! Use Ruby for a week and then ask me that with a straight face. There's nothing inherently wrong with them if you're using C, but when I'm using Ruby I want my APIs to be Ruby-like! I could have phrased that sentence better though; I didn't mean to imply that the C++ APIs had the same weaknesses as the C APIs, just that neither of them have the elegance of a purely Ruby API.

Gravatar icon
Sunday March 13, 2005 @ 10:49 PM (PST)
There's a thread going on on the ruby-talk mailing list (aka comp.lang.ruby) that might be of use to you: http://rubyurl.com/Ji5Od

Personally, my vote's always going to be for a Cocoa solution, but that's just because I'm a rabid mac fan anything but Cocoa just feels... wrong....
Gravatar icon
Careo
Wednesday March 16, 2005 @ 12:01 PM (PST)
Why don't u try Presenter from HCL Technologies
http://www.presenter5.com

It supports both C and C++
Gravatar icon
Presenter
Friday July 22, 2005 @ 12:03 PM (PDT)
Have you looked at Ultimate++?

Of course I have no idea if they even have Ruby bindings- I just discovered the thing linked from Wikipedia's Qt entry.
Gravatar icon
Rob
Saturday May 12, 2007 @ 08:47 PM (PDT)

Take a look at this article http://www.rubyinside.com/jruby-swt-future-cross-platform-ruby-desktop-app-development-298.html Of course,, it depends on jruby implementation :D

Gravatar icon
Humber
Thursday June 07, 2007 @ 01:53 PM (PDT)

Thanks for the review...I looked into this before, specifically wxRuby, PHP-GTK and Perl-GTK.

wxWidgets sounded the best -- but I have not used it. GTK sucks on OSX, try getting anyone who isn't a geek to use it.

Gravatar icon
Monday July 23, 2007 @ 02:12 AM (PDT)

I wonder how the writer feels two years later. I'm on Mac, but RubyCocoa look to complex for this non-programmer. I'm mainly interested in a personal solution so cross platform isn't important. I'm even considering Rails.

Gravatar icon
12 34
Saturday July 28, 2007 @ 10:02 AM (PDT)

Two years later, the author hasn't done much with Ruby GUI toolkits because, sadly, not much has changed. :/

Gravatar icon
Saturday July 28, 2007 @ 10:49 AM (PDT)

Just came across this useful page, and what you say about wxRuby was true two years ago. But I saw your recent comment that 'nothing's changed' and thought I'd let you know that's not the case about wxRuby.

WxRuby now has a near-stable release with full method coverage within classes, full Ruby class reference documentation (based on the wxWidgets docs, but with the right method signatures and added Ruby examples). The core library remains a fairly straight port of the C++ lib, but there's an add-on package maintained by the same team called wxSugar, which makes the library much more Ruby-ish.

Gravatar icon
Tuesday July 31, 2007 @ 02:39 AM (PDT)

I didn't realize that. Thanks for the clarification, Alex. I'll definitely take another look at wxRuby.

Gravatar icon
Tuesday July 31, 2007 @ 10:02 AM (PDT)

Also have a look at the new Anvil framework built on top of Wx::Ruby. Check out my blog for examples: http://grasprubyonrails.com and the project at http://anvil.rubyforge.org. It's a very new framework, but holds a lot of promise. Also checkout the demo application being written on top of anvil: http://hamr.rubyforge.org.

Gravatar icon
Friday August 17, 2007 @ 09:06 AM (PDT)

Tk isn't ugly. It's very practical to use. It's *very* easy to build a GUI without a GUI builder with it. It's just under Ruby that it looks ugly. Try Tk with the right language ( Tcl ) and it's a lot more integrated and has native look 'n feel using the theming extension Tile.

Gravatar icon
anonymous
Wednesday August 22, 2007 @ 08:50 AM (PDT)

Wonko, Did you get a chance to look at wxRuby again? I'm interested in what it would take a write a cross platform Ruby app for Windows, Mac and maybe even Linux. Alan Sawyer

Gravatar icon
Alan Sawyer
Monday September 10, 2007 @ 06:32 PM (PDT)

I did play around with wxRuby and wxSugar after Alex's comment, and it's improved tremendously since I wrote this blog post. wxSugar is absolutely lovely. The biggest weak point is still the documentation, but in spite of that, wxRuby is now my primary choice for writing cross-platform GUI apps in Ruby.

Gravatar icon
Monday September 10, 2007 @ 08:07 PM (PDT)

Do you or anyone have an example of a GUI app running under Ruby via wxRuby, that I can play with to see how it functions under Windows and under Mac? I am pretty new to Ruby, so I'm trying to see if it makes sense for me to move from RealBasic to Ruby. Thanks for any help. Alan

Gravatar icon
Alan Sawyer
Tuesday September 11, 2007 @ 05:12 AM (PDT)

Alan Sawyer: Why would you want to move from REALbasic?

All: Is it possible to create stand-alone wxRuby applications for the three major platforms: Windows, Linux and Mac OS X? For Python there is py2exe and other tools. Is there anything as good for Ruby?

Gravatar icon
Wednesday September 12, 2007 @ 08:05 AM (PDT)

Not moving from it, but I want something that I can work on websites also with, and if I choose to go with RoR, why not learn and also use Ruby on Desktop. I like RealBasic at this point, but I really need something that I can do some website stuff in also. Alan

Gravatar icon
Alan Sawyer
Wednesday September 12, 2007 @ 05:18 PM (PDT)

OK, I see your point, Alan. I'm more into Python and wxPython but I'm also keeping an eye on wxRuby. wxRuby appears to be greatly inspired by wxPython.

Gravatar icon
Sunday September 16, 2007 @ 08:54 AM (PDT)

i think you need to reevaluate on the windows stuff

yes, you need ruby binary and ruby-gnome binaries, but other than that, once you HAVE this, it really works like a charm!

Gravatar icon
she
Wednesday January 02, 2008 @ 02:22 AM (PST)

thanks for the really helpful analysis. It saved me a ton of time.

Gravatar icon
j
Friday February 15, 2008 @ 11:51 PM (PST)

The poster of the comment that Tk is not ugly under Tcl is a fool. Tk is a piece of crap, just like this post says. There are plenty of better looking GUI toolkits around. Trash Tk, not worth the trouble.

Gravatar icon
anonymous
Sunday March 02, 2008 @ 05:09 AM (PST)
I agree with this guy, Tk sucks. It might be easy to code but from all the apps that I’ve seen written in it (aMSN, tkgate, couple others that I can’t remember off-hand).

GTK+ is alright, Glade makes it much better but I find that I’m limited by it when I want to do certain things. When I Google for how to do it, sometimes I found forums saying I can’t.

wxWidgets is quite nice to work with, especially with programs like DialogBlocks.

Alexei: Ruby2Script might be what you’re looking for.
Gravatar icon
Wednesday March 26, 2008 @ 12:34 PM (PDT)

Forgot to finish my first paragraph. I meant to say mos tof the apps I’ve seen written in Tk don’t look so great. aMSN has started to look better, but I still find it’s not as good as even GTK.

Gravatar icon
Wednesday March 26, 2008 @ 12:36 PM (PDT)

The GTK is not bad on Windows, they just need to download and install the GTK libs (easy as pie for a moderate user). But the lack of GTK on mac cancels that one out unless that status as changed, I’ve heard via the grapevine that there is a push to make GTK nice on OSX.

WxRuby seems like the likely candidate after reading the post above about it being more fully supported and stable now.

FXRuby just had a book come out by Pragmatic publishing—which I’ll peak at next time in Borders…I’m wanting to write a simple win/mac/nix app as well.

Packaging the app for various environments is a separate issue.

I asked in #rubinius about it, and Rubinius is still in early stages and not a viable solution.

It seems the solutions come down to: GTK, FXRuby, or WXRuby.

Gravatar icon
Monday July 07, 2008 @ 06:39 PM (PDT)

claims to work for windows, linux, and osx.

http://shoooes.net/

Gravatar icon
James Kyle
Monday August 25, 2008 @ 07:59 PM (PDT)

I have got to the stage where I can get ruby application that use wxRuby to run using the 1.8.6 ruby interpreter but I have not been able to get the same applications to run on the JRuby 1.1.4 engine. Just wondering if I have missed a simple trick.

Gravatar icon
Forest
Monday February 02, 2009 @ 02:52 PM (PST)

I’m also attempting to get wxRuby(2.0) to run in jruby(1.1.4). I’ve installed wxRuby via jgem and it shows up in my list of installed jruby gems, but when I execute a program (The PureMVC_Ruby example app, for instance) I get a require error: `require’: no such file to load — wxruby2 (LoadError)

Now if I run with my ruby install, it runs all fine and dandy… (ruby v1.8.6)

I’m running on a MacBook(Oct 2008) on OSX 10.5.6

Gravatar icon
Brady
Friday March 06, 2009 @ 11:45 AM (PST)

wxRuby – and any other compiled extension for “standard” Ruby – won’t work on JRuby. If you want a faster Ruby + wxRuby, use Ruby 1.9. If you want to do GUI development with JRuby, use SWING and possibly something like MonkeyBars.

Gravatar icon
Saturday March 21, 2009 @ 02:42 AM (PDT)

Hi I used to do Ruby too, but I have moved to Rebol, and used ruby only occasionally.

Rebol is more concise. e.g if you want a window with an empty text field, a “hello” label and a “click me” button, the code is:-
view layout [ field label “Hello” button “click me” ]

check their website www.rebol.com, if you want to know more.

compare that with what you have to write in Ruby, and you will understand why I moved to Rebol.

you can run the same code as a desktop program or in a web browser . that’s amazing !!!

good luck with your search for a Ruby gui library.

Gravatar icon
batman
Thursday December 03, 2009 @ 09:19 PM (PST)

Hm, I didn’t know that. Please look at: http://wiki.tcl.tk/13636. Those app screen shots look horid? Maybe you should spend some more time researching a product before writing it off. Tk has come a long way since the old Motif rules days.

Gravatar icon
jeremy
Sunday December 20, 2009 @ 06:57 AM (PST)

I would also take a look at Juce. Haven’t tried it thoroughly, though..

Gravatar icon
Thursday January 21, 2010 @ 06:41 AM (PST)
New comment

required, won't be displayed

optional

Don't type anything here unless you're an evil robot:


And especially don't type anything here:

Basic XHTML (including links) is allowed, just don't try anything fishy. Your comment will be auto-formatted unless you use your own <p> tags for formatting. You're also welcome to use Textile.

Copyright © 2002-2010 Ryan Grove. All rights reserved.
Powered by Thoth.