Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doing native GUI with Ruby

I'd like to develop a desktop app with Ruby. However, I'd like to have a native GUI on every platform (as opposed to a cross-platform GUI Toolkit that looks consistently awful across all platforms).

I expect to have to do different GUIs for each platform (as it's not just looks but also behaviors and idioms that are different), but I wonder what my options are? Especially wondering if there is a clean way to separate front and backend and bind the data properly?

Target Platforms are Windows (Vista & 7, XP is a Bonus), Mac OS X (Cocoa) and Linux (GTK? Qt? No idea).

like image 363
Michael Stum Avatar asked May 23 '11 00:05

Michael Stum


2 Answers

The Ruby language has excellent Qt library bindings and your scripts will be cross-platform.

like image 159
maerics Avatar answered Sep 29 '22 13:09

maerics


Two Kinds of Cross-Platform

It turns out there are two kinds of cross-platform UI toolkits.

One kind draws its own controls, and, like you said, looks equally bad on all platforms. Even worse: it looks out-of-place on all except one.

But there is another kind that just provides a harmonized interface to the native widgets. The best of example of this kind of toolkit is SWT1.. It looks, it is, approximately fully native on each platform, yet it has but a single API.

So you shouldn't simply rule-out all cross-platform toolkits, just rule out the ones that fake the native UI.

Develop the Wrapper Interface

There is a second way. If your program's interface with the user can be directed through a relatively narrow interface, you can simply develop to that interface and then implement the bottom part of it for each platform you want to support. Yes, you have to rewrite one module, but all the other modules stay exactly the same and you get native widgets. You also get the smallest possible executable without lots of bloat.

Perhaps most importantly, you don't have a complex and opaque software layer between your code and the native windowing system. You will probably save as much time debugging as you spend writing the extra module for your first port.


1. I know my Java examples won't help you much unless you are using jRuby, but SWT vs Swing is a really pure example of the right-vs-wrong (IMHO) UI toolkit divide.

like image 40
DigitalRoss Avatar answered Sep 29 '22 11:09

DigitalRoss