CSC/ECE 517 Fall 2013/ch1 1w17 pk: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 131: Line 131:
==Disadvantages==
==Disadvantages==
*While a gem is available for the Windows installation, only source code is available for other platforms.
*While a gem is available for the Windows installation, only source code is available for other platforms.


=wxRuby=
=wxRuby=

Revision as of 21:50, 17 September 2013

GUI programming tools for Ruby are a set of widgets used for designing RUBY applications with graphical user interfaces (GUIs). Each widget facilitates a specific user-computer interaction, and appears as a visible part of the computer's GUI. Widget toolkits can be either native or cross platform. Ruby GUI toolkits are typically 3rd party GUI platforms that are wrapped by a Ruby driver. Ruby bindings are available for several widget toolkits. Commonly used tools are described below.


Shoes

Shoes is the best little DSL for cross-platform GUI programming in RUBY. This GUI toolkit feels like real Ruby, rather than just another C++ library wrapper. It was originally written by a guy named _why, and is now maintained by others. Currently, it is the most widely used GUI toolkit for RUBY.

Versions

Version Name Release
Version1 Curious _why release
Version2 Raisins _why release
Version3 Policeman Post_why release

Version 3 is the current stable release. It was released on August 19, 2013; 3 years ago.

Advantages

  • Simplicity- It is designed to make applications as easy as possible.
  • It has control at a lower level
  • Makes GUI development fun.
  • Simple Interface
  • Very good graphics

Cool Features

  • The unique thing about Shoes is that it gives very few controls, but one can build a wide range of different pages that are immediately accessible.
  • To save a bit of work, Shoes relies on a few libraries:
    • Cairo – for drawing
    • Pango – for text
    • Ruby – for programming

Disadvantages

  • It tries to support many platforms. Hence, it is a bit rough at the edges.
  • Current version is a place holder until Shoes is properly gemified.
  • Many common robust widgets are not available


Shoes 4

The upcoming version of shoes is Shoes 4. Due to various issues like compilation/release and stability with the current shoes implementation, development moved on to shoes4. Shoes4 is a complete all Ruby rewrite of shoes, using the Ruby bindings to the windowing libraries, rather than the C ones. It's goal is to be as close to 100% backwards compatible as it can get.


FxRuby

FxRuby is a toolkit for developing powerful and sophisticated cross-platform graphical user interfaces (GUIs) for RUBY applications. It is based on the FOX Toolkit, a popular open source C++ library developed by Jeroen van der Zijp. FXRuby has the advantages of both Ruby and C++. An application developer can write the code in ruby programming language which is dynamic, reflective and object-oriented while simultaneously take advantage of the performance and functionality of the highly optimized C++ toolkit.


Advantages

  • FXRuby supports everything of FOX, that is useful in Ruby:
  1. MDI/SDI application window layouts
  2. Floating toolbars
  3. Rich set of controls (tables, imagelists, menus, canvas, …)
  4. Flexible layout management
  5. Image read/write support in many formats
  6. Embedded OpenGL graphics
  • Relatively flat learning curve- very consistent naming, widget creation parameters, and so on.
  • It is not a wrapper around some other toolkit. Hence, one can actually override the way a widget works by sub classing and re-implementing behavior and how it is drawn.
  • Consistent vision- It is written with a consistent vision of how things should fit together.

Disadvantages

  • Missing support for some kind of RichText (which Qt and GTK+ today provide)
  • Internationalization and Localization are still being worked on.
  • Non-native look and feel. It looks like Windows XP even on a Mac or in Windows 7
  • Binary gems are available for Windows, OS X, and Ubuntu Linux but for other platforms, installing the gem requires you to compile native code.


ffi-tk

Of Ruby GUI bindings, the Tk binding is the oldest; it is widely available and still more or less the default toolkit for GUI programming with Ruby.Tk provides a number of (GUI) widgets commonly needed to develop desktop applications such as button, menu, canvas, text, frame, label, etc. Tk has been ported to run on most flavors of Linux, Mac OS, Unix, and Microsoft Windows. Tk was designed to be extended, and a wide range of extensions are available that offer new widgets or other capabilities. The "look and feel" of the Tk application depends on the version of the Tk library Ruby interpreter is linked against:

  • Tk 8.4 and below is notorious for its “ugly” look. The widgets have the outdated Motif look and feel, and, on Unix-based systems, bitmap fonts are used.
  • Tk 8.5 and above look more modern. It is shipped with the Tile theming engine, and widgets now look native to the hosting platform. On Unix-based systems outline fonts are now used.

Tk applications follow a widget hierarchy where any number of widgets may be placed within another widget, and those widgets within another widget, ad infinitum. The main widget in a Tk program is referred to as the root widget and can be created by making a new instance of the TkRoot class.

  • Most Tk-based applications follow the same cycle: create the widgets, place them in the interface, and finally, bind the events associated with each widget to a method.
  • There are three geometry managers place, grid and pack that are responsible for controlling the size and location of each of the widgets in the interface.


QtRuby

QtRuby is a binding of the application framework Qt for the programming language Ruby. Qt is a cross-platform application framework that is widely used for developing application software with a graphical user interface (GUI) and also used for developing non-GUI programs such as command-line tools and consoles for servers.

Qt uses standard C++ but makes extensive use of a special code generator (called the Meta Object Compiler, or moc) together with several macros to enrich the language. Qt can also be used in several other programming languages via language bindings. It runs on the major desktop platforms and some of the mobile platforms. It has extensive internationalization support. Non-GUI features include SQL database access, XML parsing, thread management, network support, and a unified cross-platform application programming interface (API) for file handling.

Qt5 is the new version which marks a major change in the platform, with hardware-accelerated graphics, QML and JavaScript playing a major role. The traditional C++-only QWidgets continue to be supported, but do not benefit from the performance improvements available through the new architecture. Qt5 brings significant improvements to the speed and ease of developing user interfaces. Here is a code snippet to create a Hello world window.

require 'Qt4'
app = Qt::Application.new(ARGV)
hello = Qt::PushButton.new('Hello World!')
hello.resize(100, 30)
hello.show()
app.exec()
Line by Line Walkthrough
require 'Qt4'
This line loads the QtRuby extension.
app = Qt::Application.new(ARGV)
app is this program's Qt::Application instance. It is created here. We pass ARGV to the Qt::Application constructor so that it can process certain standard command-line arguments
hello = Qt::PushButton.new('Hello World!')
Here, after the Qt::Application, comes the first window-system code: A push button is created.
The button is set up to display the text "Hello world!". Because we don't specify a parent window (as second argument to :the Qt::PushButton constructor), the button will be a window of its own, with its own window frame and title bar.
hello.resize(100, 30)
The button is set up to be 100 pixels wide and 30 pixels high (excluding the window frame, which is provided by the :windowing system).
hello.show()
A widget is never visible when you create it. You must call Qt::Widget::show() to make it visible.
app.exec()

This is where our program passes control to Qt.

Advantages

  • It supports Linux and other flavors of Unix, as well as Mac OS X and Microsoft Windows.
  • The main advantage to Qt is that it has exactly the same look on Windows and OSX. This is not true for FXRuby nor Gtk2.

Disadvantages

  • While a gem is available for the Windows installation, only source code is available for other platforms.


wxRuby

wxRuby is a binding for the cross-platform wxWidgets C++ GUI toolkit, which lets you create native-looking desktop applications. It is available for installation as a gem.

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. applications can be ported to different operating systems with as little as a recompile.
  • WxWidgets is consistent and gives a native look and feel. WxWidgets uses the native toolkits on each OS (GTK on Linux, Win32 controls on Windows and Cocoa on OS X), so the application blends in everywhere.


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

 require 'rubygems'
 require 'wx'
 
 class MyApp < Wx::App
   def on_init
     @frame = Wx::Frame.new( nil, -1, "Application" )
     @frame.show
   end
 end
 
 app = MyApp.new
 app.main_loop
line by line walkthrough
require 'wx'
To load the WxRuby library, require the 'wx' module. From this point on, all the WxRuby classes will be available in the :Wx module.
class MyApp < Wx::App
Every WxRuby application is contained in a class inherited from the Wx::App class. this test class uses the name MyApp
   def on_init
     @frame = Wx::Frame.new( nil, -1, "Application" )
     @frame.show
   end
In this example, we're creating a single widget, a Wx::Frame. A Frame is a widget that holds other widgets. Though since :we're not putting any other widgets in it, we're simply using it to display an empty window.
the third parameter of the Wx::Frame constructor (not necessarily all constructors) is the text to display in the title :bar. Our rather non-descriptive string "Application" will be displayed in the title bar of our window, as well as in the :task bar.
 app = MyApp.new
 app.main_loop
Finally, after creating a widget, you must call show on it or it won't be shown. Though you may want to wait to do this :for some things (such as popup windows), since this is a simple single-widget application, doing this in the on_init :method is appropriate.

Advantages

  • Cross platform
  • Large support community
  • Excellent support for all major platforms

Disadvantages

  • The API is very C++-oriented
  • It has no documentation aside from auto-generated class and function list.

GTK+

The GTK is a library for creating graphical user interfaces in C programming language. The GTK library is also called the GIMP (GNU Image Manipulation Program) Toolkit. GIMP is an image retouching and editing tool. Originally, the library was created while developing the GIMP image manipulation program. Since then, the GTK became one of the most popular toolkits under Linux and BSD Unix. Today, most of the GUI software in the open source world is created in Qt or in GTK. Language bindings exist for Ruby, C++, Python, Perl, Java, and other programming languages. Ruby/GTK is an extension library to use GTK+ in Ruby. There are many applications using GTK+. Especially, Desktop Environment GNOME adopt GTK+ as interface.

Advantages

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.

Disadvantages

  • 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 with the sad exception of Mac OS X. It’s possible to run GTK+ apps in OS X using the X Windowing System, but this means the app looks inconsistent and ugly compared to the rest of the OS X interface.

References

  1. http://en.wikibooks.org/wiki/Ruby_Programming/GUI_Toolkit_Modules
  2. http://wonko.com/post/a_brief_comparison_of_cross-platform_gui_toolkits_from_rubys_per
  3. http://en.wikipedia.org/wiki/QtRuby
  4. http://en.wikipedia.org/wiki/Shoes_(GUI_toolkit)
  5. http://rubydoc.info/gems/shoes/frames
  6. http://www.fxruby.org/