1. Technology
Send to a Friend via Email
You can opt-out at any time. Please refer to our privacy policy for contact information.

What is WxRuby? About WxWidgets and WxRuby

WxRuby and the WxWidgets GUI Toolkit

By

In order to know what WxRuby is, you first have to know about WxWidgets.

WxWidgets is a C++ GUI toolkit that can be used to write GUI (graphical user interface) applications. In this way, it's not unlike GTK, Qt or TK. However, it does differ from these toolkits in one major way: WxWidgets doesn't actually implement the toolkit at all, it uses another toolkit to do the actual drawing.

So what is the benefit of a GUI toolkit that needs yet another GUI toolkit to run? There are several.

Benefits of WxWidgets

  • WxWidgets is cross platform. Since it doesn't do much low-level interfacing with the OS, but rather with well established APIs that already exist on the OS, it's easy to port. (Not that you'd really ever have to worry about that, since the WxWidgets developers have taken care of that for you.) WxWidgets runs on the "big three" (that is, Windows, OS X and Linux ) and your applications can be ported to those operating systems with as little as a recompile.
  • WxWidgets is consistent and gives a native look and feel. When using some toolkits, such as Tk, your applications seem somewhat out of place. They don't look like the rest of the GUI applications running on the OS. Some widgets act differently, which may confuse users. Since WxWidgets uses the native toolkits on each OS (GTK on Linux, Win32 controls on Windows and Cocoa on OS X), your application blends in everywhere.
  • Your applications are portable. WxWidgets is written in C++. As long as your code uses only WxWidgets, the C++ standard library,and any other libraries you can bring with you, porting your application to a new OS is as simple as recompiling it. If using the native GUI APIs directly, porting non-trivial applications is a very complicated task, especially if the application code and API code are not decoupled well.

So WxWidgets is kind of a middleman or a translator. It will sit between your program and the native GUI toolkit and allow you to create widgets, as well as passing any messages received (mouse clicks, etc) up to your progam. It can also be thought of as a simplifier. Some GUI toolkits are very cumbersome and difficult to work with. Even if you don't need the cross-platform features, or care about the consistency, look and feel, writing your programs with WxWidgets can be easier than using the native GUI toolkit directly.

What's WxRuby?

So that's what WxWidgets is, but what is WxRuby? 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. You'll gain all of the benefits, including native look and feel, without having to touch any native APIs and without having to use another language at all.

Though WxRuby does have native C++ extensions, this shouldn't scare you off. Normally, gems that have native extensions are difficult to install. They require you to have a C++ compiler installed and configured, for you to have the Ruby development headers instaled where the C++ compiler can find them, and to have the libraries needed installed as well as their headers and link libraries. On some platforms (specifically Windows), this is not an easy task. However, the WxRuby people know this all too well, and have been thoughtful enough to provide pre-compiled WxRuby gems for all three major platforms. Though it is possible to install WxRuby from source and compile the native extensions yourself, you will probably find it isn't necessary.

  1. About.com
  2. Technology
  3. Ruby
  4. Graphical User Interfaces
  5. WxRuby
  6. What is WxRuby? About WxWidgets and WxRuby

©2014 About.com. All rights reserved.