CSC/ECE 517 Fall 2010/ch1 S10 GP

From Expertiza_Wiki
Jump to navigation Jump to search

GUI Toolkits for Ruby

Traditionally, Ruby is a command line tool. Most Ruby commands are entered as text in a terminal and provide output to the user in the text form. Actually, the Ruby interpretor is not bound to any program development environment. Ruby programs can be typed in any editor and there are a lot of libraries to provide Graphical User Interface (GUI). This article discusses various GUI toolkits for Ruby.

Ruby Toolkits

Standard Inbuilt Toolkit Library

The 'Tk' library is provided along with the standard Ruby distribution. Tk is an open source, platform independent toolkit. It is well-suited for cross-platform application development. Tk provides a number of widgets commonly needed to develop desktop applications such as button, menu, canvas, text, frame, label etc.

Tk is perfectly functional and easily available. Bindings are built-in to some ruby distros. Tk is easily customizable and configurable But Tk does not support native widgets and provides only a basic look and feel as compared to the other toolkits.

Thirdparty Toolkits

There are a number of toolkit libraries for Ruby provided by third-party vendors. Mostly these are wrappers around toolkits written in C and C++. Many of these toolkits may not support cross-platform application development. Some of the thirdparty toolkits are FxRuby, wxRuby, ruby-GNOME2, etc.

wxRuby is an open-source GUI toolkit for Ruby. WxRuby is a Ruby binding and wrapper for the WxWidgets C++ classes. It allows you to use all the features of WxWidgets from your Ruby programs without having to touch any native APIs or without having to use another language. You'll gain all of the benefits, including native look and feel and an easy installation. It provides a range of widgets and internationalisation support. It is a mature toolkit with a license compatible for open-source and commercial use.

Exclusive Ruby Toolkit

Shoes is a library implemented exclusively for Ruby. It is one of the most popular toolkits for Ruby. Shoes creates native applications with a look and feel similar to that of web applications. It is not built atop GTK, Qt, etc., but rather directly on the relevant native API (Win32 on Windows, for example). Shoes has a lot of potential and has a rich widget set. Not designed for serious, large-scale GUI applications, Shoes applications tend to be small, useful and clever programs, either for online or offline use. Things in Shoes are also drastically simplified and the learning curve is very shallow. However it lacks many of the more robust widgets common in other toolkits.

Environment Specific Libraries

Recent Ruby implementations have their own GUI facilities provided by toolkits associated with the environment. Some of them are Cocoa for MacRuby and Swing for JRuby.

Swing is the GUI library that is bundled with every installation of a Java runtime environment. If you run JRuby, then you can use Swing. JRuby is essentially the Ruby interpreter, except this version is written entirely in Java. JRuby features some of the same concepts, including object-oriented programming, and duck-typing as Ruby. The key difference is that JRuby is tightly integrated with Java, and can be called directly from Java programs.

Selecting the appropriate Toolkit

No single toolkit can be considered the best among available toolkits for Ruby. Users should select an appropriate toolkit based on their own requirements.

The following are some of the parameters that can be considered before choosing a toolkit.

  • Web-based documentation
  • Availability for relevant platforms
  • Appearance / aesthetics
  • Licence compatible with open source use
  • Range of features / widgets
  • Community support
  • Speed / performance
  • Internationalisation support
  • Licence compatible with commercial use
  • Accessibility features

Comparison of Toolkits

As mentioned earlier, choice of a toolkit depends solely on a developer's requirements. However, this section aims to compare some existing toolkits to better highlight their advantages and disadvantages. The toolkits discussed above all have cross-platform support and a free open-source license. All libraries, except the 'Tk' library, support a neat look and feel. Although all libraries support a wide range of widgets and features, Shoes offers a very simple interface providing ease of use which is useful for small scale projects. Additionally Shoes is extremely popular and has a very strong user community. Overall, if API style and simplicity is important, Shoes would be a good choice. For large applications, which require complex and rich features, wxRuby would be a good choice.

References