<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Daffodil</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Daffodil"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Daffodil"/>
	<updated>2026-05-11T12:43:56Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=43467</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6b SK</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=43467"/>
		<updated>2010-12-12T21:45:22Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''References''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Support for Assertions in Various O-O Programming Languages'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In computer language an [http://en.wikipedia.org/wiki/Assertion_(computing) assertion] is a construct that immediately terminates the execution of a program if a certain expression or a condition is evaluated to false (assertion failure). It is mainly used for code [http://en.wikipedia.org/wiki/Debugging debugging] . Programmers use assertions to check for potential errors or bugs in the application being developed. The main feature of assertions is to verify the validity of the assumptions made by chunk of code during execution. A good example to illustrate this is the use of [http://en.wikipedia.org/wiki/Dynamic_memory_allocation dynamic memory allocation] in C++, wherein we can use an assertion to check a [http://en.wikipedia.org/wiki/Pointer_(computing) pointer] and ensure that it is not null before using this pointer. If this check in not made, an error can be caused because of the occurance of a reference. Assertions play a vital role in developing reliable object-oriented software. An early advocate of using assertions in programming was Alan Turing [5]. Assertions are maily used to make the assumptions made by the programmers(that they believeto be correct) when they write a software explicit. Assertion-based Object-Oriented techniques produce reliable software and enable software components to be reused safely. In languages such as Eiffel, assertions form part of the design process. In other languages like Java, assertions are used only to check assumptions at runtime. Various object oriented programming languages support assertions. &lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Java''' =&lt;br /&gt;
&lt;br /&gt;
When implementing and debugging a class in java programming language, it is a good practice to specify conditions that should be true at a particular stage in a method. These conditions, called assertions, assure a software program’s validity by identifying bugs and related logical errors during the process of development. For example, if you write a module that calculates the temperature of an element, you might assert that the calculated temperature is not less than 0 degree Kelvin. The syntax for assert statements are as follows [1]:&lt;br /&gt;
&lt;br /&gt;
          assert Expression1;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a [http://en.wikipedia.org/wiki/Boolean_expression Boolean expression]. If Expression1 is evaluated to be false, then the system throws an AssertionError. This syntax for assert will not give a detail error message. Therefore second form of assert syntax can be used [1] as given below&lt;br /&gt;
         assert Expression1: Expression2;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a Boolean expression. Expression2 is an expression that has a value. This version of the assert statement provides detail message for the AssertionError. The system passes the value of Expression2 to the appropriate AssertionError constructor, which uses the string representation of the value as the error's detail message[1]. This form of the assertion statement should be used in preference to the first only when the program has some additional information that might help diagnose the failure.  Below is an example code that demonstrates the functionality of assert statement. This code checks with assert that the value entered is an even number only [2]. &lt;br /&gt;
&lt;br /&gt;
   import java.util.Scanner;&lt;br /&gt;
   &lt;br /&gt;
  	public class AssertTest&lt;br /&gt;
   {&lt;br /&gt;
       public static void main( String args[] )&lt;br /&gt;
      {&lt;br /&gt;
           Scanner input = new Scanner( System.in );&lt;br /&gt;
          &lt;br /&gt;
          System.out.print( &amp;quot;Enter an even number:  &amp;quot; );&lt;br /&gt;
         int number = input.nextInt();&lt;br /&gt;
          &lt;br /&gt;
        // assert that the number is even&lt;br /&gt;
         assert ((number % 2 == 0)) : &amp;quot;Not an even number: &amp;quot; + number;&lt;br /&gt;
 &lt;br /&gt;
       System.out.printf( &amp;quot;You entered an even number %d\n&amp;quot;, number );&lt;br /&gt;
      } &lt;br /&gt;
    } &lt;br /&gt;
OUTPUT:&lt;br /&gt;
&lt;br /&gt;
       Enter an even number:  20&lt;br /&gt;
       You entered an even number 20&lt;br /&gt;
       &lt;br /&gt;
       Enter an even number:  25&lt;br /&gt;
       Exception in thread &amp;quot;main&amp;quot; java.lang.AssertionError: Not an even number:  25&lt;br /&gt;
       at AssertTest.main(AssertTest.java:15)&lt;br /&gt;
&lt;br /&gt;
The above code prompts the user to enter an even number, then this number is read from command prompt.  The assert statement then determines whether the user entered an even or odd number. If the user entered an odd number (as in second case of output), then the program throws an error. Otherwise, the program proceeds normally. Lines that gets executed after the assert statement can assume that number is not odd&lt;br /&gt;
&lt;br /&gt;
One obvious question that may arise is when exceptions can do the [http://en.wikipedia.org/wiki/Exception_handling error handling] why we need another level of checking. Java exceptions are primarily used to handle unusual conditions arising during program execution.  Assertions are not to replace exceptions but to augment them. Assertions are used to specify conditions that a programmer assumes are true [11]. When programming, if a programmer can swear that the value being passed into a particular method is positive no matter what a calling client passes, it can be documented using an assertion to state it. Exceptions handle abnormal conditions arising in the course of the program; however they do not guarantee smooth or correct execution of the program. Assertions help state scenarios that ensure the program is running smoothly. Assertions can be efficient tools to ensure correct execution of a program [11]. They improve the confidence about the program.&lt;br /&gt;
&lt;br /&gt;
== '''Types of Assertions''' ==&lt;br /&gt;
* Preconditions - When a method is invoked, the state of the program at that time is indicated by precondition assertions. Precondition refers to the parameters passed to a method in a program. Precondition asserts validates the parameters passed to a method before they are used inside the method. &lt;br /&gt;
* Postconditions - The state of the program after a method completes its execution is indicated by postcondition assertions. Postcondition  should be evaluated before the exit point in a method. Postcondition asserts validates the return values in a method which has several return statements.&lt;br /&gt;
&lt;br /&gt;
One situation where use of assertions is helpful in Java programming language is : Internal Invariants. Assertions can be used within programs to make sure the program behaves in a predetermined manner and will throw an error when violated. For instance, an assertion can be placed in the code below to declare that age will never be negative [1].&lt;br /&gt;
&lt;br /&gt;
           if (age &amp;gt; 0)&lt;br /&gt;
           {&lt;br /&gt;
              age = age + 1;&lt;br /&gt;
           } &lt;br /&gt;
           else&lt;br /&gt;
           {&lt;br /&gt;
       		assert age &amp;gt;0:&amp;quot;Age cannot be negative&amp;quot;&lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
== '''Enabling and Disabling Assertions'''==&lt;br /&gt;
&lt;br /&gt;
Assertions are disabled at runtime by default as they reduce performance. To enable assertions at [http://en.wikipedia.org/wiki/Run_time_(computing) runtime], use the -ea command-line option. To disable assertions, use –da command line option. To execute a code with assertions enabled use&lt;br /&gt;
         java -ea AssertTest&lt;br /&gt;
&lt;br /&gt;
If you want to disable it again use&lt;br /&gt;
&lt;br /&gt;
         java -da AssertTest&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Java''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing Java code are JUnit , SpryTest , Jtest , TestNG and JExample. Other testing frameworks supported by Java can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Ruby''' =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Unit_testing Unit testing] is a process where individual parts of [http://en.wikipedia.org/wiki/Source_code source code] are isolated and tested separately to determine if they are bug free. The idea behind unit testing is that you write a test method that makes certain assertions about your code, working against a test fixture. [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby language] supports a module called Test::Unit::Assertions in test/unit/assertions.rb. Test::Unit::Assertions contains the standard Test::Unit assertions. Assertions is included in Test::Unit::TestCase. &lt;br /&gt;
&lt;br /&gt;
=='''Public class assert methods'''==&lt;br /&gt;
&lt;br /&gt;
*assert( boolean, [msg] )- This ensures that the object/expression is true&lt;br /&gt;
  assert [10, 20].include?(50)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_block(message=&amp;quot;assert_block failed.&amp;quot;) {|| ...} - If the block yields to true , then the assert passes&lt;br /&gt;
Example [3]:&lt;br /&gt;
       def assert_block(message=&amp;quot;assert_block failed.&amp;quot;) # :yields: &lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          if (! yield)&lt;br /&gt;
            raise AssertionFailedError.new(message.to_s)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* assert_match( regexp, string, [msg] )- Ensures that a string matches the regular expression&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_match(pattern, string, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          pattern = case(pattern)&lt;br /&gt;
            when String&lt;br /&gt;
              Regexp.new(Regexp.escape(pattern))&lt;br /&gt;
            else&lt;br /&gt;
              pattern&lt;br /&gt;
          end&lt;br /&gt;
          full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be =~\n&amp;lt;?&amp;gt;.&amp;quot;, string, pattern)&lt;br /&gt;
          assert_block(full_message) { string =~ pattern }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;) - If expected != actual, then the assert passes&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be != to\n&amp;lt;?&amp;gt;.&amp;quot;, expected, actual)&lt;br /&gt;
        assert_block(full_message) { expected != actual }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_nil(object, message=&amp;quot;&amp;quot;) - This assert passes if the object is nil.&lt;br /&gt;
&lt;br /&gt;
Example[3]:&lt;br /&gt;
&lt;br /&gt;
   # File test/unit/assertions.rb, line 173&lt;br /&gt;
      def assert_nil(object, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        assert_equal(nil, object, message)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are a bunch of other public class methods. This can be obtained from [4]&lt;br /&gt;
&lt;br /&gt;
=='''Test Method &amp;amp; Test Fixture'''==&lt;br /&gt;
&lt;br /&gt;
Assertions must be used inside test methods within test fixtures. Related tests are grouped inside a common test class using assert. The advantage of having a separate class for all related tests is that it keeps the actual developed code to be tested uncluttered from the test code, hence making maintainability easier. It also allows these test code to be deleted from the development code before the final delivery as these test codes are needed mainly for the developer/tester and need not be part of the final product. Major advantage is that it lets you write up a common test fixture for all tests to run against. Test fixtures are a way of organizing test data; they reside in the fixtures folder. The test_helper.rb file holds the default configuration for your tests.&lt;br /&gt;
&lt;br /&gt;
=='''Ruby on Rails'''==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] is an open source web framework for Ruby language. Rails adds some custom assertions of its own to the test/unit framework some of which are as stated below:&lt;br /&gt;
&lt;br /&gt;
*assert_difference(expressions, difference = 1, message = nil) {...} [4]&lt;br /&gt;
Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.&lt;br /&gt;
*assert_recognizes(expected_options, path, extras={}, message=nil) [4]&lt;br /&gt;
Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. &lt;br /&gt;
Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
*assert_template(expected = nil, message=nil)  [4]&lt;br /&gt;
Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Ruby''' ==&lt;br /&gt;
&lt;br /&gt;
The only xUnit framework that support testing Ruby code is Test::Unit. Other testing frameworks that support Ruby but that do not fall under the xUnit umbrella are RSpec , Shoulda , microtest and Bacon.&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in C++''' =&lt;br /&gt;
In [http://en.wikipedia.org/wiki/C%2B%2B C++] the support for assertions is pretty limited. Assertion is mainly used for error detection during debugging. If an assertion fails ,the program would stop at that point and indicate which assertion caused the failure. &lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
In C++ assertions are defined in the header file [http://en.wikipedia.org/wiki/Assert.h Assert.h].&lt;br /&gt;
&lt;br /&gt;
* assert (expression);&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       assert(isAdmin == true);&lt;br /&gt;
&lt;br /&gt;
Similar to other languages , assertions can be turned off in C++ if the NDEBUG macro is defined before the inclusion of the header Assert.h .&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in C++''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing C++ code are API Sanity Autotest, C++test, Cantata++, CppUnit and CppTest. To see the complete list of xUnit and other testing frameworks supported by C++ please refer to [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Python''' =&lt;br /&gt;
In [http://www.python.org/ Python] when the [http://docs.python.org/reference/simple_stmts.html#the-assert-statement assert] statement is encountered, the expression following the assert keyword is evaluated and the AssertionError exception is raised if the expression evaluates to false.&lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
The following code would raise the [http://docs.python.org/library/exceptions.html#exceptions.AssertionError AssertionError] exception.&lt;br /&gt;
&lt;br /&gt;
* assert condition&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       assert 1 == 2&lt;br /&gt;
&lt;br /&gt;
== Extended Assert ==&lt;br /&gt;
&lt;br /&gt;
In addition to evaluating an expression , arguments can be passed to the assertion so that for example, the right message can be displayed based on the outcome of the assertion.&lt;br /&gt;
&lt;br /&gt;
* assert Expression[, Arguments]&lt;br /&gt;
&lt;br /&gt;
Example [8];&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       def IsSenior(age):&lt;br /&gt;
          assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
          return (age &amp;gt;= 65)&lt;br /&gt;
       print IsSenior(15)&lt;br /&gt;
       print IsSenior(70)&lt;br /&gt;
       print IsSenior(-1)&lt;br /&gt;
&lt;br /&gt;
Example Output;&lt;br /&gt;
       false&lt;br /&gt;
       true&lt;br /&gt;
       Traceback (most recent call last):&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 9, in &amp;lt;module&amp;gt;&lt;br /&gt;
           print IsSenior(-5)&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 4, in IsSenior&lt;br /&gt;
           assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
       AssertionError: Age cannot be zero or less than zero !&lt;br /&gt;
&lt;br /&gt;
One of the key feature of assertions in Python is that if python is started with -O option, then the assertions would not be evaluated. The scenario where this feature would apply is developers can write a lot of assertions for debugging and when the code is to be executed in production , if it is started with -O option , then all the assertions written by the developers for debugging would not be evaluated.&lt;br /&gt;
&lt;br /&gt;
In general assertions are not the best means to test for failure cases. Instead of using an assertion exceptions would be the right way to handle scenarios like wrong user input or system/environment failures.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Python''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing python code are PyUnit, Nose, py.test and TwistedTrial. Other testing frameworks supported by python can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
One common used of assertions in python is for type checking. Please refer the article [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2007/wiki3_1_sa#Python Assertion in O-O languages] for more details.&lt;br /&gt;
&lt;br /&gt;
= '''Benefits of assertions''' =&lt;br /&gt;
*Use of assertions in the program help detect errors immediately and directly, rather than at a later stage. Assertion failure usually reports the location of failure in the code which helps in pin-pointing the error without further debugging.&lt;br /&gt;
*Assertions provide run time check for assumptions made by developers&lt;br /&gt;
*Assertions are also sometimes placed at points the execution is not supposed to reach. For example, assertions could be placed at the default clause of the switch statement in languages such as C++, and Java. Any case which the programmer does not handle intentionally will raise an error and the program will abort rather than silently continuing in an erroneous state.&lt;br /&gt;
*Assertions can be viewed as &amp;quot;dynamic documentation&amp;quot;, since they are checked at runtime, contrary to the traditional approach of documenting assumptions via plain /* comments */.&lt;br /&gt;
&lt;br /&gt;
*Assert statements are great for helping you to refactor and optimize your code with greater confidence that you have preserved correctness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Limitations of assertions''' =&lt;br /&gt;
&lt;br /&gt;
*Assertions rarely allow for graceful error recovery. They terminate the program abruptly and may not release some of the resources used by the program; hence it is considered bad practice to rely upon assertions for handling expected error conditions.&lt;br /&gt;
* Assertions sometime hinder execution time. For example, if the program has an assert that checks to see if the number to be returned is the smallest in the array, then the assertion will have to do the same amount of work that the method would have to do.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
When writing program, it is a good practice to check for violations of basic assumptions in the code. These checks help in debugging code. The assertion facility in J2SE 1.4 (and later versions) provides a unified support for assertions in Java technology as well as a convenient way for developers both to turn assertions on and off as needed. Assertions are used in Test Driven Development(TDD) in Ruby programing language. The Test::Unit library in Ruby has a variety of built in assertions that makes writing tests much easier. As seen above assertions are natively supported in some languages like Ruby, whereas in languages like C++ and python it is merely used as a mechanism to track errors when debugging.&lt;br /&gt;
&lt;br /&gt;
Although the use of assertions replaces the adhoc use of conditional tests with a uniform methodology, it does not allow for a repair strategy to continue program execution. This means that when an exception is detected, the program aborts with no recovery mechanism. Nevertheless, assertions play an important role in debugging and designing code with testability in mind. The assertion facility can be used to support an informal design-by-contract style of programming.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Kathy Sierra; Bert Bates [http://my.safaribooksonline.com/book/programming/java/0596009208 ''Head First Java''],O'Reilly Media, Inc., February 9, 2005&lt;br /&gt;
&lt;br /&gt;
* Rogers Cadenhead and Laura Lemay [http://workbench.cadenhead.org/book/java-21-days/chapter.php/7 ''Teach Yourself Java 2 in 21 Days''], MyWeblog an online resource&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://download.oracle.com/javase/1.4.2/docs/guide/lang/assert.html]  Programming with Assertions 	&lt;br /&gt;
&lt;br /&gt;
[http://www.deitel.com/articles/java_tutorials/20060106/Assertions.html]  Assertions in java&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/Assertions.html#M004514] Assertions in Ruby&lt;br /&gt;
&lt;br /&gt;
[http://guides.rubyonrails.org/testing.html#assertions-available] Ruby assertions&lt;br /&gt;
&lt;br /&gt;
[http://topfunky.com/clients/rails/ruby_and_rails_assertions.pdf] Ruby on Rails assertion cheat sheet&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.clemson.edu/~malloy/papers/prospectus/prospectus.pdf] More about assertions&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/reference/simple_stmts.html] Python simple statements documentation&lt;br /&gt;
&lt;br /&gt;
[http://www.tutorialspoint.com/python/assertions_in_python.htm] Assertions in Python&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks] Testing frameworks for programming languages&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/XUnit] xUnit&lt;br /&gt;
&lt;br /&gt;
[http://javaboutique.internet.com/tutorials/assertions/] More on assertions&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=43466</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6b SK</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=43466"/>
		<updated>2010-12-12T21:44:53Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''References''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Support for Assertions in Various O-O Programming Languages'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In computer language an [http://en.wikipedia.org/wiki/Assertion_(computing) assertion] is a construct that immediately terminates the execution of a program if a certain expression or a condition is evaluated to false (assertion failure). It is mainly used for code [http://en.wikipedia.org/wiki/Debugging debugging] . Programmers use assertions to check for potential errors or bugs in the application being developed. The main feature of assertions is to verify the validity of the assumptions made by chunk of code during execution. A good example to illustrate this is the use of [http://en.wikipedia.org/wiki/Dynamic_memory_allocation dynamic memory allocation] in C++, wherein we can use an assertion to check a [http://en.wikipedia.org/wiki/Pointer_(computing) pointer] and ensure that it is not null before using this pointer. If this check in not made, an error can be caused because of the occurance of a reference. Assertions play a vital role in developing reliable object-oriented software. An early advocate of using assertions in programming was Alan Turing [5]. Assertions are maily used to make the assumptions made by the programmers(that they believeto be correct) when they write a software explicit. Assertion-based Object-Oriented techniques produce reliable software and enable software components to be reused safely. In languages such as Eiffel, assertions form part of the design process. In other languages like Java, assertions are used only to check assumptions at runtime. Various object oriented programming languages support assertions. &lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Java''' =&lt;br /&gt;
&lt;br /&gt;
When implementing and debugging a class in java programming language, it is a good practice to specify conditions that should be true at a particular stage in a method. These conditions, called assertions, assure a software program’s validity by identifying bugs and related logical errors during the process of development. For example, if you write a module that calculates the temperature of an element, you might assert that the calculated temperature is not less than 0 degree Kelvin. The syntax for assert statements are as follows [1]:&lt;br /&gt;
&lt;br /&gt;
          assert Expression1;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a [http://en.wikipedia.org/wiki/Boolean_expression Boolean expression]. If Expression1 is evaluated to be false, then the system throws an AssertionError. This syntax for assert will not give a detail error message. Therefore second form of assert syntax can be used [1] as given below&lt;br /&gt;
         assert Expression1: Expression2;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a Boolean expression. Expression2 is an expression that has a value. This version of the assert statement provides detail message for the AssertionError. The system passes the value of Expression2 to the appropriate AssertionError constructor, which uses the string representation of the value as the error's detail message[1]. This form of the assertion statement should be used in preference to the first only when the program has some additional information that might help diagnose the failure.  Below is an example code that demonstrates the functionality of assert statement. This code checks with assert that the value entered is an even number only [2]. &lt;br /&gt;
&lt;br /&gt;
   import java.util.Scanner;&lt;br /&gt;
   &lt;br /&gt;
  	public class AssertTest&lt;br /&gt;
   {&lt;br /&gt;
       public static void main( String args[] )&lt;br /&gt;
      {&lt;br /&gt;
           Scanner input = new Scanner( System.in );&lt;br /&gt;
          &lt;br /&gt;
          System.out.print( &amp;quot;Enter an even number:  &amp;quot; );&lt;br /&gt;
         int number = input.nextInt();&lt;br /&gt;
          &lt;br /&gt;
        // assert that the number is even&lt;br /&gt;
         assert ((number % 2 == 0)) : &amp;quot;Not an even number: &amp;quot; + number;&lt;br /&gt;
 &lt;br /&gt;
       System.out.printf( &amp;quot;You entered an even number %d\n&amp;quot;, number );&lt;br /&gt;
      } &lt;br /&gt;
    } &lt;br /&gt;
OUTPUT:&lt;br /&gt;
&lt;br /&gt;
       Enter an even number:  20&lt;br /&gt;
       You entered an even number 20&lt;br /&gt;
       &lt;br /&gt;
       Enter an even number:  25&lt;br /&gt;
       Exception in thread &amp;quot;main&amp;quot; java.lang.AssertionError: Not an even number:  25&lt;br /&gt;
       at AssertTest.main(AssertTest.java:15)&lt;br /&gt;
&lt;br /&gt;
The above code prompts the user to enter an even number, then this number is read from command prompt.  The assert statement then determines whether the user entered an even or odd number. If the user entered an odd number (as in second case of output), then the program throws an error. Otherwise, the program proceeds normally. Lines that gets executed after the assert statement can assume that number is not odd&lt;br /&gt;
&lt;br /&gt;
One obvious question that may arise is when exceptions can do the [http://en.wikipedia.org/wiki/Exception_handling error handling] why we need another level of checking. Java exceptions are primarily used to handle unusual conditions arising during program execution.  Assertions are not to replace exceptions but to augment them. Assertions are used to specify conditions that a programmer assumes are true [11]. When programming, if a programmer can swear that the value being passed into a particular method is positive no matter what a calling client passes, it can be documented using an assertion to state it. Exceptions handle abnormal conditions arising in the course of the program; however they do not guarantee smooth or correct execution of the program. Assertions help state scenarios that ensure the program is running smoothly. Assertions can be efficient tools to ensure correct execution of a program [11]. They improve the confidence about the program.&lt;br /&gt;
&lt;br /&gt;
== '''Types of Assertions''' ==&lt;br /&gt;
* Preconditions - When a method is invoked, the state of the program at that time is indicated by precondition assertions. Precondition refers to the parameters passed to a method in a program. Precondition asserts validates the parameters passed to a method before they are used inside the method. &lt;br /&gt;
* Postconditions - The state of the program after a method completes its execution is indicated by postcondition assertions. Postcondition  should be evaluated before the exit point in a method. Postcondition asserts validates the return values in a method which has several return statements.&lt;br /&gt;
&lt;br /&gt;
One situation where use of assertions is helpful in Java programming language is : Internal Invariants. Assertions can be used within programs to make sure the program behaves in a predetermined manner and will throw an error when violated. For instance, an assertion can be placed in the code below to declare that age will never be negative [1].&lt;br /&gt;
&lt;br /&gt;
           if (age &amp;gt; 0)&lt;br /&gt;
           {&lt;br /&gt;
              age = age + 1;&lt;br /&gt;
           } &lt;br /&gt;
           else&lt;br /&gt;
           {&lt;br /&gt;
       		assert age &amp;gt;0:&amp;quot;Age cannot be negative&amp;quot;&lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
== '''Enabling and Disabling Assertions'''==&lt;br /&gt;
&lt;br /&gt;
Assertions are disabled at runtime by default as they reduce performance. To enable assertions at [http://en.wikipedia.org/wiki/Run_time_(computing) runtime], use the -ea command-line option. To disable assertions, use –da command line option. To execute a code with assertions enabled use&lt;br /&gt;
         java -ea AssertTest&lt;br /&gt;
&lt;br /&gt;
If you want to disable it again use&lt;br /&gt;
&lt;br /&gt;
         java -da AssertTest&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Java''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing Java code are JUnit , SpryTest , Jtest , TestNG and JExample. Other testing frameworks supported by Java can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Ruby''' =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Unit_testing Unit testing] is a process where individual parts of [http://en.wikipedia.org/wiki/Source_code source code] are isolated and tested separately to determine if they are bug free. The idea behind unit testing is that you write a test method that makes certain assertions about your code, working against a test fixture. [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby language] supports a module called Test::Unit::Assertions in test/unit/assertions.rb. Test::Unit::Assertions contains the standard Test::Unit assertions. Assertions is included in Test::Unit::TestCase. &lt;br /&gt;
&lt;br /&gt;
=='''Public class assert methods'''==&lt;br /&gt;
&lt;br /&gt;
*assert( boolean, [msg] )- This ensures that the object/expression is true&lt;br /&gt;
  assert [10, 20].include?(50)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_block(message=&amp;quot;assert_block failed.&amp;quot;) {|| ...} - If the block yields to true , then the assert passes&lt;br /&gt;
Example [3]:&lt;br /&gt;
       def assert_block(message=&amp;quot;assert_block failed.&amp;quot;) # :yields: &lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          if (! yield)&lt;br /&gt;
            raise AssertionFailedError.new(message.to_s)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* assert_match( regexp, string, [msg] )- Ensures that a string matches the regular expression&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_match(pattern, string, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          pattern = case(pattern)&lt;br /&gt;
            when String&lt;br /&gt;
              Regexp.new(Regexp.escape(pattern))&lt;br /&gt;
            else&lt;br /&gt;
              pattern&lt;br /&gt;
          end&lt;br /&gt;
          full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be =~\n&amp;lt;?&amp;gt;.&amp;quot;, string, pattern)&lt;br /&gt;
          assert_block(full_message) { string =~ pattern }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;) - If expected != actual, then the assert passes&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be != to\n&amp;lt;?&amp;gt;.&amp;quot;, expected, actual)&lt;br /&gt;
        assert_block(full_message) { expected != actual }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_nil(object, message=&amp;quot;&amp;quot;) - This assert passes if the object is nil.&lt;br /&gt;
&lt;br /&gt;
Example[3]:&lt;br /&gt;
&lt;br /&gt;
   # File test/unit/assertions.rb, line 173&lt;br /&gt;
      def assert_nil(object, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        assert_equal(nil, object, message)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are a bunch of other public class methods. This can be obtained from [4]&lt;br /&gt;
&lt;br /&gt;
=='''Test Method &amp;amp; Test Fixture'''==&lt;br /&gt;
&lt;br /&gt;
Assertions must be used inside test methods within test fixtures. Related tests are grouped inside a common test class using assert. The advantage of having a separate class for all related tests is that it keeps the actual developed code to be tested uncluttered from the test code, hence making maintainability easier. It also allows these test code to be deleted from the development code before the final delivery as these test codes are needed mainly for the developer/tester and need not be part of the final product. Major advantage is that it lets you write up a common test fixture for all tests to run against. Test fixtures are a way of organizing test data; they reside in the fixtures folder. The test_helper.rb file holds the default configuration for your tests.&lt;br /&gt;
&lt;br /&gt;
=='''Ruby on Rails'''==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] is an open source web framework for Ruby language. Rails adds some custom assertions of its own to the test/unit framework some of which are as stated below:&lt;br /&gt;
&lt;br /&gt;
*assert_difference(expressions, difference = 1, message = nil) {...} [4]&lt;br /&gt;
Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.&lt;br /&gt;
*assert_recognizes(expected_options, path, extras={}, message=nil) [4]&lt;br /&gt;
Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. &lt;br /&gt;
Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
*assert_template(expected = nil, message=nil)  [4]&lt;br /&gt;
Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Ruby''' ==&lt;br /&gt;
&lt;br /&gt;
The only xUnit framework that support testing Ruby code is Test::Unit. Other testing frameworks that support Ruby but that do not fall under the xUnit umbrella are RSpec , Shoulda , microtest and Bacon.&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in C++''' =&lt;br /&gt;
In [http://en.wikipedia.org/wiki/C%2B%2B C++] the support for assertions is pretty limited. Assertion is mainly used for error detection during debugging. If an assertion fails ,the program would stop at that point and indicate which assertion caused the failure. &lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
In C++ assertions are defined in the header file [http://en.wikipedia.org/wiki/Assert.h Assert.h].&lt;br /&gt;
&lt;br /&gt;
* assert (expression);&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       assert(isAdmin == true);&lt;br /&gt;
&lt;br /&gt;
Similar to other languages , assertions can be turned off in C++ if the NDEBUG macro is defined before the inclusion of the header Assert.h .&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in C++''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing C++ code are API Sanity Autotest, C++test, Cantata++, CppUnit and CppTest. To see the complete list of xUnit and other testing frameworks supported by C++ please refer to [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Python''' =&lt;br /&gt;
In [http://www.python.org/ Python] when the [http://docs.python.org/reference/simple_stmts.html#the-assert-statement assert] statement is encountered, the expression following the assert keyword is evaluated and the AssertionError exception is raised if the expression evaluates to false.&lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
The following code would raise the [http://docs.python.org/library/exceptions.html#exceptions.AssertionError AssertionError] exception.&lt;br /&gt;
&lt;br /&gt;
* assert condition&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       assert 1 == 2&lt;br /&gt;
&lt;br /&gt;
== Extended Assert ==&lt;br /&gt;
&lt;br /&gt;
In addition to evaluating an expression , arguments can be passed to the assertion so that for example, the right message can be displayed based on the outcome of the assertion.&lt;br /&gt;
&lt;br /&gt;
* assert Expression[, Arguments]&lt;br /&gt;
&lt;br /&gt;
Example [8];&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       def IsSenior(age):&lt;br /&gt;
          assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
          return (age &amp;gt;= 65)&lt;br /&gt;
       print IsSenior(15)&lt;br /&gt;
       print IsSenior(70)&lt;br /&gt;
       print IsSenior(-1)&lt;br /&gt;
&lt;br /&gt;
Example Output;&lt;br /&gt;
       false&lt;br /&gt;
       true&lt;br /&gt;
       Traceback (most recent call last):&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 9, in &amp;lt;module&amp;gt;&lt;br /&gt;
           print IsSenior(-5)&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 4, in IsSenior&lt;br /&gt;
           assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
       AssertionError: Age cannot be zero or less than zero !&lt;br /&gt;
&lt;br /&gt;
One of the key feature of assertions in Python is that if python is started with -O option, then the assertions would not be evaluated. The scenario where this feature would apply is developers can write a lot of assertions for debugging and when the code is to be executed in production , if it is started with -O option , then all the assertions written by the developers for debugging would not be evaluated.&lt;br /&gt;
&lt;br /&gt;
In general assertions are not the best means to test for failure cases. Instead of using an assertion exceptions would be the right way to handle scenarios like wrong user input or system/environment failures.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Python''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing python code are PyUnit, Nose, py.test and TwistedTrial. Other testing frameworks supported by python can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
One common used of assertions in python is for type checking. Please refer the article [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2007/wiki3_1_sa#Python Assertion in O-O languages] for more details.&lt;br /&gt;
&lt;br /&gt;
= '''Benefits of assertions''' =&lt;br /&gt;
*Use of assertions in the program help detect errors immediately and directly, rather than at a later stage. Assertion failure usually reports the location of failure in the code which helps in pin-pointing the error without further debugging.&lt;br /&gt;
*Assertions provide run time check for assumptions made by developers&lt;br /&gt;
*Assertions are also sometimes placed at points the execution is not supposed to reach. For example, assertions could be placed at the default clause of the switch statement in languages such as C++, and Java. Any case which the programmer does not handle intentionally will raise an error and the program will abort rather than silently continuing in an erroneous state.&lt;br /&gt;
*Assertions can be viewed as &amp;quot;dynamic documentation&amp;quot;, since they are checked at runtime, contrary to the traditional approach of documenting assumptions via plain /* comments */.&lt;br /&gt;
&lt;br /&gt;
*Assert statements are great for helping you to refactor and optimize your code with greater confidence that you have preserved correctness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Limitations of assertions''' =&lt;br /&gt;
&lt;br /&gt;
*Assertions rarely allow for graceful error recovery. They terminate the program abruptly and may not release some of the resources used by the program; hence it is considered bad practice to rely upon assertions for handling expected error conditions.&lt;br /&gt;
* Assertions sometime hinder execution time. For example, if the program has an assert that checks to see if the number to be returned is the smallest in the array, then the assertion will have to do the same amount of work that the method would have to do.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
When writing program, it is a good practice to check for violations of basic assumptions in the code. These checks help in debugging code. The assertion facility in J2SE 1.4 (and later versions) provides a unified support for assertions in Java technology as well as a convenient way for developers both to turn assertions on and off as needed. Assertions are used in Test Driven Development(TDD) in Ruby programing language. The Test::Unit library in Ruby has a variety of built in assertions that makes writing tests much easier. As seen above assertions are natively supported in some languages like Ruby, whereas in languages like C++ and python it is merely used as a mechanism to track errors when debugging.&lt;br /&gt;
&lt;br /&gt;
Although the use of assertions replaces the adhoc use of conditional tests with a uniform methodology, it does not allow for a repair strategy to continue program execution. This means that when an exception is detected, the program aborts with no recovery mechanism. Nevertheless, assertions play an important role in debugging and designing code with testability in mind. The assertion facility can be used to support an informal design-by-contract style of programming.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Kathy Sierra; Bert Bates [http://my.safaribooksonline.com/book/programming/java/0596009208 ''Head First Java''],O'Reilly Media, Inc., February 9, 2005&lt;br /&gt;
&lt;br /&gt;
* Rogers Cadenhead and Laura Lemay [http://workbench.cadenhead.org/book/java-21-days/chapter.php/7 ''Teach Yourself Java 2 in 21 Days''], MyWeblog&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://download.oracle.com/javase/1.4.2/docs/guide/lang/assert.html]  Programming with Assertions 	&lt;br /&gt;
&lt;br /&gt;
[http://www.deitel.com/articles/java_tutorials/20060106/Assertions.html]  Assertions in java&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/Assertions.html#M004514] Assertions in Ruby&lt;br /&gt;
&lt;br /&gt;
[http://guides.rubyonrails.org/testing.html#assertions-available] Ruby assertions&lt;br /&gt;
&lt;br /&gt;
[http://topfunky.com/clients/rails/ruby_and_rails_assertions.pdf] Ruby on Rails assertion cheat sheet&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.clemson.edu/~malloy/papers/prospectus/prospectus.pdf] More about assertions&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/reference/simple_stmts.html] Python simple statements documentation&lt;br /&gt;
&lt;br /&gt;
[http://www.tutorialspoint.com/python/assertions_in_python.htm] Assertions in Python&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks] Testing frameworks for programming languages&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/XUnit] xUnit&lt;br /&gt;
&lt;br /&gt;
[http://javaboutique.internet.com/tutorials/assertions/] More on assertions&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=43465</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6b SK</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=43465"/>
		<updated>2010-12-12T21:44:41Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Support for Assertions in Various O-O Programming Languages'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In computer language an [http://en.wikipedia.org/wiki/Assertion_(computing) assertion] is a construct that immediately terminates the execution of a program if a certain expression or a condition is evaluated to false (assertion failure). It is mainly used for code [http://en.wikipedia.org/wiki/Debugging debugging] . Programmers use assertions to check for potential errors or bugs in the application being developed. The main feature of assertions is to verify the validity of the assumptions made by chunk of code during execution. A good example to illustrate this is the use of [http://en.wikipedia.org/wiki/Dynamic_memory_allocation dynamic memory allocation] in C++, wherein we can use an assertion to check a [http://en.wikipedia.org/wiki/Pointer_(computing) pointer] and ensure that it is not null before using this pointer. If this check in not made, an error can be caused because of the occurance of a reference. Assertions play a vital role in developing reliable object-oriented software. An early advocate of using assertions in programming was Alan Turing [5]. Assertions are maily used to make the assumptions made by the programmers(that they believeto be correct) when they write a software explicit. Assertion-based Object-Oriented techniques produce reliable software and enable software components to be reused safely. In languages such as Eiffel, assertions form part of the design process. In other languages like Java, assertions are used only to check assumptions at runtime. Various object oriented programming languages support assertions. &lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Java''' =&lt;br /&gt;
&lt;br /&gt;
When implementing and debugging a class in java programming language, it is a good practice to specify conditions that should be true at a particular stage in a method. These conditions, called assertions, assure a software program’s validity by identifying bugs and related logical errors during the process of development. For example, if you write a module that calculates the temperature of an element, you might assert that the calculated temperature is not less than 0 degree Kelvin. The syntax for assert statements are as follows [1]:&lt;br /&gt;
&lt;br /&gt;
          assert Expression1;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a [http://en.wikipedia.org/wiki/Boolean_expression Boolean expression]. If Expression1 is evaluated to be false, then the system throws an AssertionError. This syntax for assert will not give a detail error message. Therefore second form of assert syntax can be used [1] as given below&lt;br /&gt;
         assert Expression1: Expression2;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a Boolean expression. Expression2 is an expression that has a value. This version of the assert statement provides detail message for the AssertionError. The system passes the value of Expression2 to the appropriate AssertionError constructor, which uses the string representation of the value as the error's detail message[1]. This form of the assertion statement should be used in preference to the first only when the program has some additional information that might help diagnose the failure.  Below is an example code that demonstrates the functionality of assert statement. This code checks with assert that the value entered is an even number only [2]. &lt;br /&gt;
&lt;br /&gt;
   import java.util.Scanner;&lt;br /&gt;
   &lt;br /&gt;
  	public class AssertTest&lt;br /&gt;
   {&lt;br /&gt;
       public static void main( String args[] )&lt;br /&gt;
      {&lt;br /&gt;
           Scanner input = new Scanner( System.in );&lt;br /&gt;
          &lt;br /&gt;
          System.out.print( &amp;quot;Enter an even number:  &amp;quot; );&lt;br /&gt;
         int number = input.nextInt();&lt;br /&gt;
          &lt;br /&gt;
        // assert that the number is even&lt;br /&gt;
         assert ((number % 2 == 0)) : &amp;quot;Not an even number: &amp;quot; + number;&lt;br /&gt;
 &lt;br /&gt;
       System.out.printf( &amp;quot;You entered an even number %d\n&amp;quot;, number );&lt;br /&gt;
      } &lt;br /&gt;
    } &lt;br /&gt;
OUTPUT:&lt;br /&gt;
&lt;br /&gt;
       Enter an even number:  20&lt;br /&gt;
       You entered an even number 20&lt;br /&gt;
       &lt;br /&gt;
       Enter an even number:  25&lt;br /&gt;
       Exception in thread &amp;quot;main&amp;quot; java.lang.AssertionError: Not an even number:  25&lt;br /&gt;
       at AssertTest.main(AssertTest.java:15)&lt;br /&gt;
&lt;br /&gt;
The above code prompts the user to enter an even number, then this number is read from command prompt.  The assert statement then determines whether the user entered an even or odd number. If the user entered an odd number (as in second case of output), then the program throws an error. Otherwise, the program proceeds normally. Lines that gets executed after the assert statement can assume that number is not odd&lt;br /&gt;
&lt;br /&gt;
One obvious question that may arise is when exceptions can do the [http://en.wikipedia.org/wiki/Exception_handling error handling] why we need another level of checking. Java exceptions are primarily used to handle unusual conditions arising during program execution.  Assertions are not to replace exceptions but to augment them. Assertions are used to specify conditions that a programmer assumes are true [11]. When programming, if a programmer can swear that the value being passed into a particular method is positive no matter what a calling client passes, it can be documented using an assertion to state it. Exceptions handle abnormal conditions arising in the course of the program; however they do not guarantee smooth or correct execution of the program. Assertions help state scenarios that ensure the program is running smoothly. Assertions can be efficient tools to ensure correct execution of a program [11]. They improve the confidence about the program.&lt;br /&gt;
&lt;br /&gt;
== '''Types of Assertions''' ==&lt;br /&gt;
* Preconditions - When a method is invoked, the state of the program at that time is indicated by precondition assertions. Precondition refers to the parameters passed to a method in a program. Precondition asserts validates the parameters passed to a method before they are used inside the method. &lt;br /&gt;
* Postconditions - The state of the program after a method completes its execution is indicated by postcondition assertions. Postcondition  should be evaluated before the exit point in a method. Postcondition asserts validates the return values in a method which has several return statements.&lt;br /&gt;
&lt;br /&gt;
One situation where use of assertions is helpful in Java programming language is : Internal Invariants. Assertions can be used within programs to make sure the program behaves in a predetermined manner and will throw an error when violated. For instance, an assertion can be placed in the code below to declare that age will never be negative [1].&lt;br /&gt;
&lt;br /&gt;
           if (age &amp;gt; 0)&lt;br /&gt;
           {&lt;br /&gt;
              age = age + 1;&lt;br /&gt;
           } &lt;br /&gt;
           else&lt;br /&gt;
           {&lt;br /&gt;
       		assert age &amp;gt;0:&amp;quot;Age cannot be negative&amp;quot;&lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
== '''Enabling and Disabling Assertions'''==&lt;br /&gt;
&lt;br /&gt;
Assertions are disabled at runtime by default as they reduce performance. To enable assertions at [http://en.wikipedia.org/wiki/Run_time_(computing) runtime], use the -ea command-line option. To disable assertions, use –da command line option. To execute a code with assertions enabled use&lt;br /&gt;
         java -ea AssertTest&lt;br /&gt;
&lt;br /&gt;
If you want to disable it again use&lt;br /&gt;
&lt;br /&gt;
         java -da AssertTest&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Java''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing Java code are JUnit , SpryTest , Jtest , TestNG and JExample. Other testing frameworks supported by Java can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Ruby''' =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Unit_testing Unit testing] is a process where individual parts of [http://en.wikipedia.org/wiki/Source_code source code] are isolated and tested separately to determine if they are bug free. The idea behind unit testing is that you write a test method that makes certain assertions about your code, working against a test fixture. [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby language] supports a module called Test::Unit::Assertions in test/unit/assertions.rb. Test::Unit::Assertions contains the standard Test::Unit assertions. Assertions is included in Test::Unit::TestCase. &lt;br /&gt;
&lt;br /&gt;
=='''Public class assert methods'''==&lt;br /&gt;
&lt;br /&gt;
*assert( boolean, [msg] )- This ensures that the object/expression is true&lt;br /&gt;
  assert [10, 20].include?(50)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_block(message=&amp;quot;assert_block failed.&amp;quot;) {|| ...} - If the block yields to true , then the assert passes&lt;br /&gt;
Example [3]:&lt;br /&gt;
       def assert_block(message=&amp;quot;assert_block failed.&amp;quot;) # :yields: &lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          if (! yield)&lt;br /&gt;
            raise AssertionFailedError.new(message.to_s)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* assert_match( regexp, string, [msg] )- Ensures that a string matches the regular expression&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_match(pattern, string, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          pattern = case(pattern)&lt;br /&gt;
            when String&lt;br /&gt;
              Regexp.new(Regexp.escape(pattern))&lt;br /&gt;
            else&lt;br /&gt;
              pattern&lt;br /&gt;
          end&lt;br /&gt;
          full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be =~\n&amp;lt;?&amp;gt;.&amp;quot;, string, pattern)&lt;br /&gt;
          assert_block(full_message) { string =~ pattern }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;) - If expected != actual, then the assert passes&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be != to\n&amp;lt;?&amp;gt;.&amp;quot;, expected, actual)&lt;br /&gt;
        assert_block(full_message) { expected != actual }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_nil(object, message=&amp;quot;&amp;quot;) - This assert passes if the object is nil.&lt;br /&gt;
&lt;br /&gt;
Example[3]:&lt;br /&gt;
&lt;br /&gt;
   # File test/unit/assertions.rb, line 173&lt;br /&gt;
      def assert_nil(object, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        assert_equal(nil, object, message)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are a bunch of other public class methods. This can be obtained from [4]&lt;br /&gt;
&lt;br /&gt;
=='''Test Method &amp;amp; Test Fixture'''==&lt;br /&gt;
&lt;br /&gt;
Assertions must be used inside test methods within test fixtures. Related tests are grouped inside a common test class using assert. The advantage of having a separate class for all related tests is that it keeps the actual developed code to be tested uncluttered from the test code, hence making maintainability easier. It also allows these test code to be deleted from the development code before the final delivery as these test codes are needed mainly for the developer/tester and need not be part of the final product. Major advantage is that it lets you write up a common test fixture for all tests to run against. Test fixtures are a way of organizing test data; they reside in the fixtures folder. The test_helper.rb file holds the default configuration for your tests.&lt;br /&gt;
&lt;br /&gt;
=='''Ruby on Rails'''==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] is an open source web framework for Ruby language. Rails adds some custom assertions of its own to the test/unit framework some of which are as stated below:&lt;br /&gt;
&lt;br /&gt;
*assert_difference(expressions, difference = 1, message = nil) {...} [4]&lt;br /&gt;
Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.&lt;br /&gt;
*assert_recognizes(expected_options, path, extras={}, message=nil) [4]&lt;br /&gt;
Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. &lt;br /&gt;
Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
*assert_template(expected = nil, message=nil)  [4]&lt;br /&gt;
Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Ruby''' ==&lt;br /&gt;
&lt;br /&gt;
The only xUnit framework that support testing Ruby code is Test::Unit. Other testing frameworks that support Ruby but that do not fall under the xUnit umbrella are RSpec , Shoulda , microtest and Bacon.&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in C++''' =&lt;br /&gt;
In [http://en.wikipedia.org/wiki/C%2B%2B C++] the support for assertions is pretty limited. Assertion is mainly used for error detection during debugging. If an assertion fails ,the program would stop at that point and indicate which assertion caused the failure. &lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
In C++ assertions are defined in the header file [http://en.wikipedia.org/wiki/Assert.h Assert.h].&lt;br /&gt;
&lt;br /&gt;
* assert (expression);&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       assert(isAdmin == true);&lt;br /&gt;
&lt;br /&gt;
Similar to other languages , assertions can be turned off in C++ if the NDEBUG macro is defined before the inclusion of the header Assert.h .&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in C++''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing C++ code are API Sanity Autotest, C++test, Cantata++, CppUnit and CppTest. To see the complete list of xUnit and other testing frameworks supported by C++ please refer to [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Python''' =&lt;br /&gt;
In [http://www.python.org/ Python] when the [http://docs.python.org/reference/simple_stmts.html#the-assert-statement assert] statement is encountered, the expression following the assert keyword is evaluated and the AssertionError exception is raised if the expression evaluates to false.&lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
The following code would raise the [http://docs.python.org/library/exceptions.html#exceptions.AssertionError AssertionError] exception.&lt;br /&gt;
&lt;br /&gt;
* assert condition&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       assert 1 == 2&lt;br /&gt;
&lt;br /&gt;
== Extended Assert ==&lt;br /&gt;
&lt;br /&gt;
In addition to evaluating an expression , arguments can be passed to the assertion so that for example, the right message can be displayed based on the outcome of the assertion.&lt;br /&gt;
&lt;br /&gt;
* assert Expression[, Arguments]&lt;br /&gt;
&lt;br /&gt;
Example [8];&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       def IsSenior(age):&lt;br /&gt;
          assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
          return (age &amp;gt;= 65)&lt;br /&gt;
       print IsSenior(15)&lt;br /&gt;
       print IsSenior(70)&lt;br /&gt;
       print IsSenior(-1)&lt;br /&gt;
&lt;br /&gt;
Example Output;&lt;br /&gt;
       false&lt;br /&gt;
       true&lt;br /&gt;
       Traceback (most recent call last):&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 9, in &amp;lt;module&amp;gt;&lt;br /&gt;
           print IsSenior(-5)&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 4, in IsSenior&lt;br /&gt;
           assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
       AssertionError: Age cannot be zero or less than zero !&lt;br /&gt;
&lt;br /&gt;
One of the key feature of assertions in Python is that if python is started with -O option, then the assertions would not be evaluated. The scenario where this feature would apply is developers can write a lot of assertions for debugging and when the code is to be executed in production , if it is started with -O option , then all the assertions written by the developers for debugging would not be evaluated.&lt;br /&gt;
&lt;br /&gt;
In general assertions are not the best means to test for failure cases. Instead of using an assertion exceptions would be the right way to handle scenarios like wrong user input or system/environment failures.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Python''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing python code are PyUnit, Nose, py.test and TwistedTrial. Other testing frameworks supported by python can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
One common used of assertions in python is for type checking. Please refer the article [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2007/wiki3_1_sa#Python Assertion in O-O languages] for more details.&lt;br /&gt;
&lt;br /&gt;
= '''Benefits of assertions''' =&lt;br /&gt;
*Use of assertions in the program help detect errors immediately and directly, rather than at a later stage. Assertion failure usually reports the location of failure in the code which helps in pin-pointing the error without further debugging.&lt;br /&gt;
*Assertions provide run time check for assumptions made by developers&lt;br /&gt;
*Assertions are also sometimes placed at points the execution is not supposed to reach. For example, assertions could be placed at the default clause of the switch statement in languages such as C++, and Java. Any case which the programmer does not handle intentionally will raise an error and the program will abort rather than silently continuing in an erroneous state.&lt;br /&gt;
*Assertions can be viewed as &amp;quot;dynamic documentation&amp;quot;, since they are checked at runtime, contrary to the traditional approach of documenting assumptions via plain /* comments */.&lt;br /&gt;
&lt;br /&gt;
*Assert statements are great for helping you to refactor and optimize your code with greater confidence that you have preserved correctness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Limitations of assertions''' =&lt;br /&gt;
&lt;br /&gt;
*Assertions rarely allow for graceful error recovery. They terminate the program abruptly and may not release some of the resources used by the program; hence it is considered bad practice to rely upon assertions for handling expected error conditions.&lt;br /&gt;
* Assertions sometime hinder execution time. For example, if the program has an assert that checks to see if the number to be returned is the smallest in the array, then the assertion will have to do the same amount of work that the method would have to do.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
When writing program, it is a good practice to check for violations of basic assumptions in the code. These checks help in debugging code. The assertion facility in J2SE 1.4 (and later versions) provides a unified support for assertions in Java technology as well as a convenient way for developers both to turn assertions on and off as needed. Assertions are used in Test Driven Development(TDD) in Ruby programing language. The Test::Unit library in Ruby has a variety of built in assertions that makes writing tests much easier. As seen above assertions are natively supported in some languages like Ruby, whereas in languages like C++ and python it is merely used as a mechanism to track errors when debugging.&lt;br /&gt;
&lt;br /&gt;
Although the use of assertions replaces the adhoc use of conditional tests with a uniform methodology, it does not allow for a repair strategy to continue program execution. This means that when an exception is detected, the program aborts with no recovery mechanism. Nevertheless, assertions play an important role in debugging and designing code with testability in mind. The assertion facility can be used to support an informal design-by-contract style of programming.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Kathy Sierra; Bert Bates [http://my.safaribooksonline.com/book/programming/java/0596009208 ''Head First Java''],O'Reilly Media, Inc., February 9, 2005&lt;br /&gt;
&lt;br /&gt;
* Rogers Cadenhead and Laura Lemay [http://workbench.cadenhead.org/book/java-21-days/chapter.php/7 ''Teach Yourself Java 2 in 21 Days''], MyWeblog&lt;br /&gt;
&lt;br /&gt;
** Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://download.oracle.com/javase/1.4.2/docs/guide/lang/assert.html]  Programming with Assertions 	&lt;br /&gt;
&lt;br /&gt;
[http://www.deitel.com/articles/java_tutorials/20060106/Assertions.html]  Assertions in java&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/Assertions.html#M004514] Assertions in Ruby&lt;br /&gt;
&lt;br /&gt;
[http://guides.rubyonrails.org/testing.html#assertions-available] Ruby assertions&lt;br /&gt;
&lt;br /&gt;
[http://topfunky.com/clients/rails/ruby_and_rails_assertions.pdf] Ruby on Rails assertion cheat sheet&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.clemson.edu/~malloy/papers/prospectus/prospectus.pdf] More about assertions&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/reference/simple_stmts.html] Python simple statements documentation&lt;br /&gt;
&lt;br /&gt;
[http://www.tutorialspoint.com/python/assertions_in_python.htm] Assertions in Python&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks] Testing frameworks for programming languages&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/XUnit] xUnit&lt;br /&gt;
&lt;br /&gt;
[http://javaboutique.internet.com/tutorials/assertions/] More on assertions&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=43373</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6b SK</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=43373"/>
		<updated>2010-12-07T05:43:30Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Support for Assertions in Various O-O Programming Languages'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In computer language an [http://en.wikipedia.org/wiki/Assertion_(computing) assertion] is a construct that immediately terminates the execution of a program if a certain expression or a condition is evaluated to false (assertion failure). It is mainly used for code [http://en.wikipedia.org/wiki/Debugging debugging] . Programmers use assertions to check for potential errors or bugs in the application being developed. The main feature of assertions is to verify the validity of the assumptions made by chunk of code during execution. A good example to illustrate this is the use of [http://en.wikipedia.org/wiki/Dynamic_memory_allocation dynamic memory allocation] in C++, wherein we can use an assertion to check a [http://en.wikipedia.org/wiki/Pointer_(computing) pointer] and ensure that it is not null before using this pointer. If this check in not made, an error can be caused because of the occurance of a reference. Assertions play a vital role in developing reliable object-oriented software. An early advocate of using assertions in programming was Alan Turing [5]. Assertions are maily used to make the assumptions made by the programmers(that they believeto be correct) when they write a software explicit. Assertion-based Object-Oriented techniques produce reliable software and enable software components to be reused safely. In languages such as Eiffel, assertions form part of the design process. In other languages like Java, assertions are used only to check assumptions at runtime. Various object oriented programming languages support assertions. &lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Java''' =&lt;br /&gt;
&lt;br /&gt;
When implementing and debugging a class in java programming language, it is a good practice to specify conditions that should be true at a particular stage in a method. These conditions, called assertions, assure a software program’s validity by identifying bugs and related logical errors during the process of development. For example, if you write a module that calculates the temperature of an element, you might assert that the calculated temperature is not less than 0 degree Kelvin. The syntax for assert statements are as follows [1]:&lt;br /&gt;
&lt;br /&gt;
          assert Expression1;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a [http://en.wikipedia.org/wiki/Boolean_expression Boolean expression]. If Expression1 is evaluated to be false, then the system throws an AssertionError. This syntax for assert will not give a detail error message. Therefore second form of assert syntax can be used [1] as given below&lt;br /&gt;
         assert Expression1: Expression2;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a Boolean expression. Expression2 is an expression that has a value. This version of the assert statement provides detail message for the AssertionError. The system passes the value of Expression2 to the appropriate AssertionError constructor, which uses the string representation of the value as the error's detail message[1]. This form of the assertion statement should be used in preference to the first only when the program has some additional information that might help diagnose the failure.  Below is an example code that demonstrates the functionality of assert statement. This code checks with assert that the value entered is an even number only [2]. &lt;br /&gt;
&lt;br /&gt;
   import java.util.Scanner;&lt;br /&gt;
   &lt;br /&gt;
  	public class AssertTest&lt;br /&gt;
   {&lt;br /&gt;
       public static void main( String args[] )&lt;br /&gt;
      {&lt;br /&gt;
           Scanner input = new Scanner( System.in );&lt;br /&gt;
          &lt;br /&gt;
          System.out.print( &amp;quot;Enter an even number:  &amp;quot; );&lt;br /&gt;
         int number = input.nextInt();&lt;br /&gt;
          &lt;br /&gt;
        // assert that the number is even&lt;br /&gt;
         assert ((number % 2 == 0)) : &amp;quot;Not an even number: &amp;quot; + number;&lt;br /&gt;
 &lt;br /&gt;
       System.out.printf( &amp;quot;You entered an even number %d\n&amp;quot;, number );&lt;br /&gt;
      } &lt;br /&gt;
    } &lt;br /&gt;
OUTPUT:&lt;br /&gt;
&lt;br /&gt;
       Enter an even number:  20&lt;br /&gt;
       You entered an even number 20&lt;br /&gt;
       &lt;br /&gt;
       Enter an even number:  25&lt;br /&gt;
       Exception in thread &amp;quot;main&amp;quot; java.lang.AssertionError: Not an even number:  25&lt;br /&gt;
       at AssertTest.main(AssertTest.java:15)&lt;br /&gt;
&lt;br /&gt;
The above code prompts the user to enter an even number, then this number is read from command prompt.  The assert statement then determines whether the user entered an even or odd number. If the user entered an odd number (as in second case of output), then the program throws an error. Otherwise, the program proceeds normally. Lines that gets executed after the assert statement can assume that number is not odd&lt;br /&gt;
&lt;br /&gt;
One obvious question that may arise is when exceptions can do the [http://en.wikipedia.org/wiki/Exception_handling error handling] why we need another level of checking. Java exceptions are primarily used to handle unusual conditions arising during program execution.  Assertions are not to replace exceptions but to augment them. Assertions are used to specify conditions that a programmer assumes are true [11]. When programming, if a programmer can swear that the value being passed into a particular method is positive no matter what a calling client passes, it can be documented using an assertion to state it. Exceptions handle abnormal conditions arising in the course of the program; however they do not guarantee smooth or correct execution of the program. Assertions help state scenarios that ensure the program is running smoothly. Assertions can be efficient tools to ensure correct execution of a program [11]. They improve the confidence about the program.&lt;br /&gt;
&lt;br /&gt;
== '''Types of Assertions''' ==&lt;br /&gt;
* Preconditions - When a method is invoked, the state of the program at that time is indicated by precondition assertions. Precondition refers to the parameters passed to a method in a program. Precondition asserts validates the parameters passed to a method before they are used inside the method. &lt;br /&gt;
* Postconditions - The state of the program after a method completes its execution is indicated by postcondition assertions. Postcondition  should be evaluated before the exit point in a method. Postcondition asserts validates the return values in a method which has several return statements.&lt;br /&gt;
&lt;br /&gt;
One situation where use of assertions is helpful in Java programming language is : Internal Invariants. Assertions can be used within programs to make sure the program behaves in a predetermined manner and will throw an error when violated. For instance, an assertion can be placed in the code below to declare that age will never be negative [1].&lt;br /&gt;
&lt;br /&gt;
           if (age &amp;gt; 0)&lt;br /&gt;
           {&lt;br /&gt;
              age = age + 1;&lt;br /&gt;
           } &lt;br /&gt;
           else&lt;br /&gt;
           {&lt;br /&gt;
       		assert age &amp;gt;0:&amp;quot;Age cannot be negative&amp;quot;&lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
== '''Enabling and Disabling Assertions'''==&lt;br /&gt;
&lt;br /&gt;
Assertions are disabled at runtime by default as they reduce performance. To enable assertions at [http://en.wikipedia.org/wiki/Run_time_(computing) runtime], use the -ea command-line option. To disable assertions, use –da command line option. To execute a code with assertions enabled use&lt;br /&gt;
         java -ea AssertTest&lt;br /&gt;
&lt;br /&gt;
If you want to disable it again use&lt;br /&gt;
&lt;br /&gt;
         java -da AssertTest&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Java''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing Java code are JUnit , SpryTest , Jtest , TestNG and JExample. Other testing frameworks supported by Java can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Ruby''' =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Unit_testing Unit testing] is a process where individual parts of [http://en.wikipedia.org/wiki/Source_code source code] are isolated and tested separately to determine if they are bug free. The idea behind unit testing is that you write a test method that makes certain assertions about your code, working against a test fixture. [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby language] supports a module called Test::Unit::Assertions in test/unit/assertions.rb. Test::Unit::Assertions contains the standard Test::Unit assertions. Assertions is included in Test::Unit::TestCase. &lt;br /&gt;
&lt;br /&gt;
=='''Public class assert methods'''==&lt;br /&gt;
&lt;br /&gt;
*assert( boolean, [msg] )- This ensures that the object/expression is true&lt;br /&gt;
  assert [10, 20].include?(50)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_block(message=&amp;quot;assert_block failed.&amp;quot;) {|| ...} - If the block yields to true , then the assert passes&lt;br /&gt;
Example [3]:&lt;br /&gt;
       def assert_block(message=&amp;quot;assert_block failed.&amp;quot;) # :yields: &lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          if (! yield)&lt;br /&gt;
            raise AssertionFailedError.new(message.to_s)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* assert_match( regexp, string, [msg] )- Ensures that a string matches the regular expression&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_match(pattern, string, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          pattern = case(pattern)&lt;br /&gt;
            when String&lt;br /&gt;
              Regexp.new(Regexp.escape(pattern))&lt;br /&gt;
            else&lt;br /&gt;
              pattern&lt;br /&gt;
          end&lt;br /&gt;
          full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be =~\n&amp;lt;?&amp;gt;.&amp;quot;, string, pattern)&lt;br /&gt;
          assert_block(full_message) { string =~ pattern }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;) - If expected != actual, then the assert passes&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be != to\n&amp;lt;?&amp;gt;.&amp;quot;, expected, actual)&lt;br /&gt;
        assert_block(full_message) { expected != actual }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_nil(object, message=&amp;quot;&amp;quot;) - This assert passes if the object is nil.&lt;br /&gt;
&lt;br /&gt;
Example[3]:&lt;br /&gt;
&lt;br /&gt;
   # File test/unit/assertions.rb, line 173&lt;br /&gt;
      def assert_nil(object, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        assert_equal(nil, object, message)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are a bunch of other public class methods. This can be obtained from [4]&lt;br /&gt;
&lt;br /&gt;
=='''Test Method &amp;amp; Test Fixture'''==&lt;br /&gt;
&lt;br /&gt;
Assertions must be used inside test methods within test fixtures. Related tests are grouped inside a common test class using assert. The advantage of having a separate class for all related tests is that it keeps the actual developed code to be tested uncluttered from the test code, hence making maintainability easier. It also allows these test code to be deleted from the development code before the final delivery as these test codes are needed mainly for the developer/tester and need not be part of the final product. Major advantage is that it lets you write up a common test fixture for all tests to run against. Test fixtures are a way of organizing test data; they reside in the fixtures folder. The test_helper.rb file holds the default configuration for your tests.&lt;br /&gt;
&lt;br /&gt;
=='''Ruby on Rails'''==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] is an open source web framework for Ruby language. Rails adds some custom assertions of its own to the test/unit framework some of which are as stated below:&lt;br /&gt;
&lt;br /&gt;
*assert_difference(expressions, difference = 1, message = nil) {...} [4]&lt;br /&gt;
Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.&lt;br /&gt;
*assert_recognizes(expected_options, path, extras={}, message=nil) [4]&lt;br /&gt;
Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. &lt;br /&gt;
Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
*assert_template(expected = nil, message=nil)  [4]&lt;br /&gt;
Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Ruby''' ==&lt;br /&gt;
&lt;br /&gt;
The only xUnit framework that support testing Ruby code is Test::Unit. Other testing frameworks that support Ruby but that do not fall under the xUnit umbrella are RSpec , Shoulda , microtest and Bacon.&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in C++''' =&lt;br /&gt;
In [http://en.wikipedia.org/wiki/C%2B%2B C++] the support for assertions is pretty limited. Assertion is mainly used for error detection during debugging. If an assertion fails ,the program would stop at that point and indicate which assertion caused the failure. &lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
In C++ assertions are defined in the header file [http://en.wikipedia.org/wiki/Assert.h Assert.h].&lt;br /&gt;
&lt;br /&gt;
* assert (expression);&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       assert(isAdmin == true);&lt;br /&gt;
&lt;br /&gt;
Similar to other languages , assertions can be turned off in C++ if the NDEBUG macro is defined before the inclusion of the header Assert.h .&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in C++''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing C++ code are API Sanity Autotest, C++test, Cantata++, CppUnit and CppTest. To see the complete list of xUnit and other testing frameworks supported by C++ please refer to [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Python''' =&lt;br /&gt;
In [http://www.python.org/ Python] when the [http://docs.python.org/reference/simple_stmts.html#the-assert-statement assert] statement is encountered, the expression following the assert keyword is evaluated and the AssertionError exception is raised if the expression evaluates to false.&lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
The following code would raise the [http://docs.python.org/library/exceptions.html#exceptions.AssertionError AssertionError] exception.&lt;br /&gt;
&lt;br /&gt;
* assert condition&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       assert 1 == 2&lt;br /&gt;
&lt;br /&gt;
== Extended Assert ==&lt;br /&gt;
&lt;br /&gt;
In addition to evaluating an expression , arguments can be passed to the assertion so that for example, the right message can be displayed based on the outcome of the assertion.&lt;br /&gt;
&lt;br /&gt;
* assert Expression[, Arguments]&lt;br /&gt;
&lt;br /&gt;
Example [8];&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       def IsSenior(age):&lt;br /&gt;
          assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
          return (age &amp;gt;= 65)&lt;br /&gt;
       print IsSenior(15)&lt;br /&gt;
       print IsSenior(70)&lt;br /&gt;
       print IsSenior(-1)&lt;br /&gt;
&lt;br /&gt;
Example Output;&lt;br /&gt;
       false&lt;br /&gt;
       true&lt;br /&gt;
       Traceback (most recent call last):&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 9, in &amp;lt;module&amp;gt;&lt;br /&gt;
           print IsSenior(-5)&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 4, in IsSenior&lt;br /&gt;
           assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
       AssertionError: Age cannot be zero or less than zero !&lt;br /&gt;
&lt;br /&gt;
One of the key feature of assertions in Python is that if python is started with -O option, then the assertions would not be evaluated. The scenario where this feature would apply is developers can write a lot of assertions for debugging and when the code is to be executed in production , if it is started with -O option , then all the assertions written by the developers for debugging would not be evaluated.&lt;br /&gt;
&lt;br /&gt;
In general assertions are not the best means to test for failure cases. Instead of using an assertion exceptions would be the right way to handle scenarios like wrong user input or system/environment failures.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Python''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing python code are PyUnit, Nose, py.test and TwistedTrial. Other testing frameworks supported by python can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
One common used of assertions in python is for type checking. Please refer the article [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2007/wiki3_1_sa#Python Assertion in O-O languages] for more details.&lt;br /&gt;
&lt;br /&gt;
= '''Benefits of assertions''' =&lt;br /&gt;
*Use of assertions in the program help detect errors immediately and directly, rather than at a later stage. Assertion failure usually reports the location of failure in the code which helps in pin-pointing the error without further debugging.&lt;br /&gt;
*Assertions provide run time check for assumptions made by developers&lt;br /&gt;
*Assertions are also sometimes placed at points the execution is not supposed to reach. For example, assertions could be placed at the default clause of the switch statement in languages such as C++, and Java. Any case which the programmer does not handle intentionally will raise an error and the program will abort rather than silently continuing in an erroneous state.&lt;br /&gt;
*Assertions can be viewed as &amp;quot;dynamic documentation&amp;quot;, since they are checked at runtime, contrary to the traditional approach of documenting assumptions via plain /* comments */.&lt;br /&gt;
&lt;br /&gt;
*Assert statements are great for helping you to refactor and optimize your code with greater confidence that you have preserved correctness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Limitations of assertions''' =&lt;br /&gt;
&lt;br /&gt;
*Assertions rarely allow for graceful error recovery. They terminate the program abruptly and may not release some of the resources used by the program; hence it is considered bad practice to rely upon assertions for handling expected error conditions.&lt;br /&gt;
* Assertions sometime hinder execution time. For example, if the program has an assert that checks to see if the number to be returned is the smallest in the array, then the assertion will have to do the same amount of work that the method would have to do.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
When writing program, it is a good practice to check for violations of basic assumptions in the code. These checks help in debugging code. The assertion facility in J2SE 1.4 (and later versions) provides a unified support for assertions in Java technology as well as a convenient way for developers both to turn assertions on and off as needed. Assertions are used in Test Driven Development(TDD) in Ruby programing language. The Test::Unit library in Ruby has a variety of built in assertions that makes writing tests much easier. As seen above assertions are natively supported in some languages like Ruby, whereas in languages like C++ and python it is merely used as a mechanism to track errors when debugging.&lt;br /&gt;
&lt;br /&gt;
Although the use of assertions replaces the adhoc use of conditional tests with a uniform methodology, it does not allow for a repair strategy to continue program execution. This means that when an exception is detected, the program aborts with no recovery mechanism. Nevertheless, assertions play an important role in debugging and designing code with testability in mind. The assertion facility can be used to support an informal design-by-contract style of programming.&lt;br /&gt;
&lt;br /&gt;
= '''Reference''' =&lt;br /&gt;
&lt;br /&gt;
[http://download.oracle.com/javase/1.4.2/docs/guide/lang/assert.html]  Programming with Assertions 	&lt;br /&gt;
&lt;br /&gt;
[http://www.deitel.com/articles/java_tutorials/20060106/Assertions.html]  Assertions in java&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/Assertions.html#M004514] Assertions in Ruby&lt;br /&gt;
&lt;br /&gt;
[http://guides.rubyonrails.org/testing.html#assertions-available] Ruby assertions&lt;br /&gt;
&lt;br /&gt;
[http://topfunky.com/clients/rails/ruby_and_rails_assertions.pdf] Ruby on Rails assertion cheat sheet&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.clemson.edu/~malloy/papers/prospectus/prospectus.pdf] More about assertions&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/reference/simple_stmts.html] Python simple statements documentation&lt;br /&gt;
&lt;br /&gt;
[http://www.tutorialspoint.com/python/assertions_in_python.htm] Assertions in Python&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks] Testing frameworks for programming languages&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/XUnit] xUnit&lt;br /&gt;
&lt;br /&gt;
[http://javaboutique.internet.com/tutorials/assertions/] More on assertions&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=41841</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6b SK</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=41841"/>
		<updated>2010-11-18T03:01:09Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Support for Assertions in Various O-O Programming Languages'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In computer language an [http://en.wikipedia.org/wiki/Assertion_(computing) assertion] is a construct that immediately terminates the execution of a program if a certain expression or a condition is evaluated to false (assertion failure). It is mainly used for code [http://en.wikipedia.org/wiki/Debugging debugging] . Programmers use assertions to check for potential errors or bugs in the application being developed. The main feature of assertions is to verify the validity of the assumptions made by chunk of code during execution. A good example to illustrate this is the use of [http://en.wikipedia.org/wiki/Dynamic_memory_allocation dynamic memory allocation] in C++, wherein we can use an assertion to check a [http://en.wikipedia.org/wiki/Pointer_(computing) pointer] and ensure that it is not null before using this pointer. If this check in not made, an error can be caused because of the occurance of a reference. Assertions play a vital role in developing reliable object-oriented software. An early advocate of using assertions in programming was Alan Turing [5]. Assertions are maily used to make the assumptions made by the programmers(that they believeto be correct) when they write a software explicit. Assertion-based Object-Oriented techniques produce reliable software and enable software components to be reused safely. In languages such as Eiffel, assertions form part of the design process. In other languages like Java, assertions are used only to check assumptions at runtime. Various object oriented programming languages support assertions. &lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Java''' =&lt;br /&gt;
&lt;br /&gt;
When implementing and debugging a class in java programming language, it is a good practice to specify conditions that should be true at a particular stage in a method. These conditions, called assertions, assure a software program’s validity by identifying bugs and related logical errors during the process of development. For example, if you write a module that calculates the temperature of an element, you might assert that the calculated temperature is not less than 0 degree Kelvin. The syntax for assert statements are as follows [1]:&lt;br /&gt;
&lt;br /&gt;
          assert Expression1;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a [http://en.wikipedia.org/wiki/Boolean_expression Boolean expression]. If Expression1 is evaluated to be false, then the system throws an AssertionError. This syntax for assert will not give a detail error message. Therefore second form of assert syntax can be used [1] as given below&lt;br /&gt;
         assert Expression1: Expression2;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a Boolean expression. Expression2 is an expression that has a value. This version of the assert statement provides detail message for the AssertionError. The system passes the value of Expression2 to the appropriate AssertionError constructor, which uses the string representation of the value as the error's detail message[1]. This form of the assertion statement should be used in preference to the first only when the program has some additional information that might help diagnose the failure.  Below is an example code that demonstrates the functionality of assert statement. This code checks with assert that the value entered is an even number only [2]. &lt;br /&gt;
&lt;br /&gt;
   import java.util.Scanner;&lt;br /&gt;
   &lt;br /&gt;
  	public class AssertTest&lt;br /&gt;
   {&lt;br /&gt;
       public static void main( String args[] )&lt;br /&gt;
      {&lt;br /&gt;
           Scanner input = new Scanner( System.in );&lt;br /&gt;
          &lt;br /&gt;
          System.out.print( &amp;quot;Enter an even number:  &amp;quot; );&lt;br /&gt;
         int number = input.nextInt();&lt;br /&gt;
          &lt;br /&gt;
        // assert that the number is even&lt;br /&gt;
         assert ((number % 2 == 0)) : &amp;quot;Not an even number: &amp;quot; + number;&lt;br /&gt;
 &lt;br /&gt;
       System.out.printf( &amp;quot;You entered an even number %d\n&amp;quot;, number );&lt;br /&gt;
      } &lt;br /&gt;
    } &lt;br /&gt;
OUTPUT:&lt;br /&gt;
&lt;br /&gt;
       Enter an even number:  10&lt;br /&gt;
       You entered an even number 10&lt;br /&gt;
       &lt;br /&gt;
       Enter an even number:  25&lt;br /&gt;
       Exception in thread &amp;quot;main&amp;quot; java.lang.AssertionError: Not an even number:  25&lt;br /&gt;
       at AssertTest.main(AssertTest.java:15)&lt;br /&gt;
&lt;br /&gt;
The above code prompts the user to enter an even number, then this number is read from command prompt.  The assert statement then determines whether the user entered an even or odd number. If the user entered an odd number (as in second case of output), then the program throws an error. Otherwise, the program proceeds normally. Lines that gets executed after the assert statement can assume that number is not odd&lt;br /&gt;
&lt;br /&gt;
One obvious question that may arise is when exceptions can do the [http://en.wikipedia.org/wiki/Exception_handling error handling] why we need another level of checking. Java exceptions are primarily used to handle unusual conditions arising during program execution.  Assertions are not to replace exceptions but to augment them. Assertions are used to specify conditions that a programmer assumes are true [11]. When programming, if a programmer can swear that the value being passed into a particular method is positive no matter what a calling client passes, it can be documented using an assertion to state it. Exceptions handle abnormal conditions arising in the course of the program; however they do not guarantee smooth or correct execution of the program. Assertions help state scenarios that ensure the program is running smoothly. Assertions can be efficient tools to ensure correct execution of a program [11]. They improve the confidence about the program.&lt;br /&gt;
&lt;br /&gt;
== '''Types of Assertions''' ==&lt;br /&gt;
* Preconditions - When a method is invoked, the state of the program at that time is indicated by precondition assertions. Precondition refers to the parameters passed to a method in a program. Precondition asserts validates the parameters passed to a method before they are used inside the method. &lt;br /&gt;
* Postconditions - The state of the program after a method completes its execution is indicated by postcondition assertions. Postcondition  should be evaluated before the exit point in a method. Postcondition asserts validates the return values in a method which has several return statements.&lt;br /&gt;
&lt;br /&gt;
One situation where use of assertions is helpful in Java programming language is : Internal Invariants. Assertions can be used within programs to make sure the program behaves in a predetermined manner and will throw an error when violated. For instance, an assertion can be placed in the code below to declare that age will never be negative [1].&lt;br /&gt;
&lt;br /&gt;
           if (age &amp;gt; 0)&lt;br /&gt;
           {&lt;br /&gt;
              age = age + 1;&lt;br /&gt;
           } &lt;br /&gt;
           else&lt;br /&gt;
           {&lt;br /&gt;
       		assert age &amp;gt;0:&amp;quot;Age cannot be negative&amp;quot;&lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
== '''Enabling and Disabling Assertions'''==&lt;br /&gt;
&lt;br /&gt;
Assertions are disabled at runtime by default as they reduce performance. To enable assertions at [http://en.wikipedia.org/wiki/Run_time_(computing) runtime], use the -ea command-line option. To disable assertions, use –da command line option. To execute a code with assertions enabled use&lt;br /&gt;
         java -ea AssertTest&lt;br /&gt;
&lt;br /&gt;
If you want to disable it again use&lt;br /&gt;
&lt;br /&gt;
         java -da AssertTest&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Java''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing Java code are JUnit , SpryTest , Jtest , TestNG and JExample. Other testing frameworks supported by Java can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Ruby''' =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Unit_testing Unit testing] is a process where individual parts of [http://en.wikipedia.org/wiki/Source_code source code] are isolated and tested separately to determine if they are bug free. The idea behind unit testing is that you write a test method that makes certain assertions about your code, working against a test fixture. [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby language] supports a module called Test::Unit::Assertions in test/unit/assertions.rb. Test::Unit::Assertions contains the standard Test::Unit assertions. Assertions is included in Test::Unit::TestCase. &lt;br /&gt;
&lt;br /&gt;
=='''Public class assert methods'''==&lt;br /&gt;
&lt;br /&gt;
*assert( boolean, [msg] )- This ensures that the object/expression is true&lt;br /&gt;
  assert [10, 20].include?(50)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_block(message=&amp;quot;assert_block failed.&amp;quot;) {|| ...} - If the block yields to true , then the assert passes&lt;br /&gt;
Example [3]:&lt;br /&gt;
       def assert_block(message=&amp;quot;assert_block failed.&amp;quot;) # :yields: &lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          if (! yield)&lt;br /&gt;
            raise AssertionFailedError.new(message.to_s)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* assert_match( regexp, string, [msg] )- Ensures that a string matches the regular expression&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_match(pattern, string, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          pattern = case(pattern)&lt;br /&gt;
            when String&lt;br /&gt;
              Regexp.new(Regexp.escape(pattern))&lt;br /&gt;
            else&lt;br /&gt;
              pattern&lt;br /&gt;
          end&lt;br /&gt;
          full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be =~\n&amp;lt;?&amp;gt;.&amp;quot;, string, pattern)&lt;br /&gt;
          assert_block(full_message) { string =~ pattern }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;) - If expected != actual, then the assert passes&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be != to\n&amp;lt;?&amp;gt;.&amp;quot;, expected, actual)&lt;br /&gt;
        assert_block(full_message) { expected != actual }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_nil(object, message=&amp;quot;&amp;quot;) - This assert passes if the object is nil.&lt;br /&gt;
&lt;br /&gt;
Example[3]:&lt;br /&gt;
&lt;br /&gt;
   # File test/unit/assertions.rb, line 173&lt;br /&gt;
      def assert_nil(object, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        assert_equal(nil, object, message)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are a bunch of other public class methods. This can be obtained from [4]&lt;br /&gt;
&lt;br /&gt;
=='''Test Method &amp;amp; Test Fixture'''==&lt;br /&gt;
&lt;br /&gt;
Assertions must be used inside test methods within test fixtures. Related tests are grouped inside a common test class using assert. The advantage of having a separate class for all related tests is that it keeps the actual developed code to be tested uncluttered from the test code, hence making maintainability easier. It also allows these test code to be deleted from the development code before the final delivery as these test codes are needed mainly for the developer/tester and need not be part of the final product. Major advantage is that it lets you write up a common test fixture for all tests to run against. Test fixtures are a way of organizing test data; they reside in the fixtures folder. The test_helper.rb file holds the default configuration for your tests.&lt;br /&gt;
&lt;br /&gt;
=='''Ruby on Rails'''==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] is an open source web framework for Ruby language. Rails adds some custom assertions of its own to the test/unit framework some of which are as stated below:&lt;br /&gt;
&lt;br /&gt;
*assert_difference(expressions, difference = 1, message = nil) {...} [4]&lt;br /&gt;
Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.&lt;br /&gt;
*assert_recognizes(expected_options, path, extras={}, message=nil) [4]&lt;br /&gt;
Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. &lt;br /&gt;
Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
*assert_template(expected = nil, message=nil)  [4]&lt;br /&gt;
Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Ruby''' ==&lt;br /&gt;
&lt;br /&gt;
The only xUnit framework that support testing Ruby code is Test::Unit. Other testing frameworks that support Ruby but that do not fall under the xUnit umbrella are RSpec , Shoulda , microtest and Bacon.&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in C++''' =&lt;br /&gt;
In [http://en.wikipedia.org/wiki/C%2B%2B C++] the support for assertions is pretty limited. Assertion is mainly used for error detection during debugging. If an assertion fails ,the program would stop at that point and indicate which assertion caused the failure. &lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
In C++ assertions are defined in the header file [http://en.wikipedia.org/wiki/Assert.h Assert.h].&lt;br /&gt;
&lt;br /&gt;
* assert (expression);&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       assert(isAdmin == true);&lt;br /&gt;
&lt;br /&gt;
Similar to other languages , assertions can be turned off in C++ if the NDEBUG macro is defined before the inclusion of the header Assert.h .&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in C++''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing C++ code are API Sanity Autotest, C++test, Cantata++, CppUnit and CppTest. To see the complete list of xUnit and other testing frameworks supported by C++ please refer to [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Python''' =&lt;br /&gt;
In [http://www.python.org/ Python] when the [http://docs.python.org/reference/simple_stmts.html#the-assert-statement assert] statement is encountered, the expression following the assert keyword is evaluated and the AssertionError exception is raised if the expression evaluates to false.&lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
The following code would raise the [http://docs.python.org/library/exceptions.html#exceptions.AssertionError AssertionError] exception.&lt;br /&gt;
&lt;br /&gt;
* assert condition&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       assert 1 == 2&lt;br /&gt;
&lt;br /&gt;
== Extended Assert ==&lt;br /&gt;
&lt;br /&gt;
In addition to evaluating an expression , arguments can be passed to the assertion so that for example, the right message can be displayed based on the outcome of the assertion.&lt;br /&gt;
&lt;br /&gt;
* assert Expression[, Arguments]&lt;br /&gt;
&lt;br /&gt;
Example [8];&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       def IsSenior(age):&lt;br /&gt;
          assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
          return (age &amp;gt;= 65)&lt;br /&gt;
       print IsSenior(15)&lt;br /&gt;
       print IsSenior(70)&lt;br /&gt;
       print IsSenior(-1)&lt;br /&gt;
&lt;br /&gt;
Example Output;&lt;br /&gt;
       false&lt;br /&gt;
       true&lt;br /&gt;
       Traceback (most recent call last):&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 9, in &amp;lt;module&amp;gt;&lt;br /&gt;
           print IsSenior(-5)&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 4, in IsSenior&lt;br /&gt;
           assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
       AssertionError: Age cannot be zero or less than zero !&lt;br /&gt;
&lt;br /&gt;
One of the key feature of assertions in Python is that if python is started with -O option, then the assertions would not be evaluated. The scenario where this feature would apply is developers can write a lot of assertions for debugging and when the code is to be executed in production , if it is started with -O option , then all the assertions written by the developers for debugging would not be evaluated.&lt;br /&gt;
&lt;br /&gt;
In general assertions are not the best means to test for failure cases. Instead of using an assertion exceptions would be the right way to handle scenarios like wrong user input or system/environment failures.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Python''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing python code are PyUnit, Nose, py.test and TwistedTrial. Other testing frameworks supported by python can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
One common used of assertions in python is for type checking. Please refer the article [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2007/wiki3_1_sa#Python Assertion in O-O languages] for more details.&lt;br /&gt;
&lt;br /&gt;
= '''Benefits of assertions''' =&lt;br /&gt;
*Use of assertions in the program help detect errors immediately and directly, rather than at a later stage. Assertion failure usually reports the location of failure in the code which helps in pin-pointing the error without further debugging.&lt;br /&gt;
*Assertions provide run time check for assumptions made by developers&lt;br /&gt;
*Assertions are also sometimes placed at points the execution is not supposed to reach. For example, assertions could be placed at the default clause of the switch statement in languages such as C++, and Java. Any case which the programmer does not handle intentionally will raise an error and the program will abort rather than silently continuing in an erroneous state.&lt;br /&gt;
*Assertions can be viewed as &amp;quot;dynamic documentation&amp;quot;, since they are checked at runtime, contrary to the traditional approach of documenting assumptions via plain /* comments */.&lt;br /&gt;
&lt;br /&gt;
*Assert statements are great for helping you to refactor and optimize your code with greater confidence that you have preserved correctness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Limitations of assertions''' =&lt;br /&gt;
&lt;br /&gt;
*Assertions rarely allow for graceful error recovery. They terminate the program abruptly and may not release some of the resources used by the program; hence it is considered bad practice to rely upon assertions for handling expected error conditions.&lt;br /&gt;
* Assertions sometime hinder execution time. For example, if the program has an assert that checks to see if the number to be returned is the smallest in the array, then the assertion will have to do the same amount of work that the method would have to do.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
When writing program, it is a good practice to check for violations of basic assumptions in the code. These checks help in debugging code. The assertion facility in J2SE 1.4 (and later versions) provides a unified support for assertions in Java technology as well as a convenient way for developers both to turn assertions on and off as needed. Assertions are used in Test Driven Development(TDD) in Ruby programing language. The Test::Unit library in Ruby has a variety of built in assertions that makes writing tests much easier. As seen above assertions are natively supported in some languages like Ruby, whereas in languages like C++ and python it is merely used as a mechanism to track errors when debugging.&lt;br /&gt;
&lt;br /&gt;
Although the use of assertions replaces the adhoc use of conditional tests with a uniform methodology, it does not allow for a repair strategy to continue program execution. This means that when an exception is detected, the program aborts with no recovery mechanism. Nevertheless, assertions play an important role in debugging and designing code with testability in mind. The assertion facility can be used to support an informal design-by-contract style of programming.&lt;br /&gt;
&lt;br /&gt;
= '''Reference''' =&lt;br /&gt;
&lt;br /&gt;
[http://download.oracle.com/javase/1.4.2/docs/guide/lang/assert.html]  Programming with Assertions 	&lt;br /&gt;
&lt;br /&gt;
[http://www.deitel.com/articles/java_tutorials/20060106/Assertions.html]  Assertions in java&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/Assertions.html#M004514] Assertions in Ruby&lt;br /&gt;
&lt;br /&gt;
[http://guides.rubyonrails.org/testing.html#assertions-available] Ruby assertions&lt;br /&gt;
&lt;br /&gt;
[http://topfunky.com/clients/rails/ruby_and_rails_assertions.pdf] Ruby on Rails assertion cheat sheet&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.clemson.edu/~malloy/papers/prospectus/prospectus.pdf] More about assertions&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/reference/simple_stmts.html] Python simple statements documentation&lt;br /&gt;
&lt;br /&gt;
[http://www.tutorialspoint.com/python/assertions_in_python.htm] Assertions in Python&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks] Testing frameworks for programming languages&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/XUnit] xUnit&lt;br /&gt;
&lt;br /&gt;
[http://javaboutique.internet.com/tutorials/assertions/] More on assertions&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=41135</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6b SK</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=41135"/>
		<updated>2010-11-17T17:06:25Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Support for Assertions in Various O-O Programming Languages'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In computer language an [http://en.wikipedia.org/wiki/Assertion_(computing) assertion] is a construct that immediately terminates the execution of a program if a certain expression or a condition is evaluated to false (assertion failure). It is mainly used for code [http://en.wikipedia.org/wiki/Debugging debugging] . Programmers use assertions to check for potential errors or bugs in the application being developed. The main feature of assertions is to verify the validity of the assumptions made by chunk of code during execution. A good example to illustrate this is the use of [http://en.wikipedia.org/wiki/Dynamic_memory_allocation dynamic memory allocation] in C++, wherein we can use an assertion to check a [http://en.wikipedia.org/wiki/Pointer_(computing) pointer] and ensure that it is not null before using this pointer. If this check in not made, an error can be caused because of the occurance of a reference. Assertions play a vital role in developing reliable object-oriented software. An early advocate of using assertions in programming was Alan Turing [5]. Assertions are maily used to make the assumptions made by the programmers(that they believeto be correct) when they write a software explicit. Assertion-based Object-Oriented techniques produce reliable software and enable software components to be reused safely. In languages such as Eiffel, assertions form part of the design process. In other languages like Java, assertions are used only to check assumptions at runtime. Various object oriented programming languages support assertions. &lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Java''' =&lt;br /&gt;
&lt;br /&gt;
When implementing and debugging a class in java programming language, it is a good practice to specify conditions that should be true at a particular stage in a method. These conditions, called assertions, assure a software program’s validity by identifying bugs and related logical errors during the process of development. For example, if you write a module that calculates the temperature of an element, you might assert that the calculated temperature is not less than 0 degree Kelvin. The syntax for assert statements are as follows [1]:&lt;br /&gt;
&lt;br /&gt;
          assert Expression1;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a [http://en.wikipedia.org/wiki/Boolean_expression Boolean expression]. If Expression1 is evaluated to be false, then the system throws an AssertionError. This syntax for assert will not give a detail error message. Therefore second form of assert syntax can be used [1] as given below&lt;br /&gt;
         assert Expression1: Expression2;&lt;br /&gt;
&lt;br /&gt;
Expression1 is a Boolean expression. Expression2 is an expression that has a value. This version of the assert statement provides detail message for the AssertionError. The system passes the value of Expression2 to the appropriate AssertionError constructor, which uses the string representation of the value as the error's detail message[1]. This form of the assertion statement should be used in preference to the first only when the program has some additional information that might help diagnose the failure.  Below is an example code that demonstrates the functionality of assert statement. This code checks with assert that the value entered is an even number only [2]. &lt;br /&gt;
&lt;br /&gt;
   import java.util.Scanner;&lt;br /&gt;
   &lt;br /&gt;
  	public class AssertTest&lt;br /&gt;
   {&lt;br /&gt;
       public static void main( String args[] )&lt;br /&gt;
      {&lt;br /&gt;
           Scanner input = new Scanner( System.in );&lt;br /&gt;
          &lt;br /&gt;
          System.out.print( &amp;quot;Enter an even number:  &amp;quot; );&lt;br /&gt;
         int number = input.nextInt();&lt;br /&gt;
          &lt;br /&gt;
        // assert that the number is even&lt;br /&gt;
         assert ((number % 2 == 0)) : &amp;quot;Not an even number: &amp;quot; + number;&lt;br /&gt;
 &lt;br /&gt;
       System.out.printf( &amp;quot;You entered an even number %d\n&amp;quot;, number );&lt;br /&gt;
      } &lt;br /&gt;
    } &lt;br /&gt;
OUTPUT:&lt;br /&gt;
&lt;br /&gt;
       Enter an even number:  10&lt;br /&gt;
       You entered an even number 10&lt;br /&gt;
       &lt;br /&gt;
       Enter an even number:  25&lt;br /&gt;
       Exception in thread &amp;quot;main&amp;quot; java.lang.AssertionError: Not an even number:  25&lt;br /&gt;
       at AssertTest.main(AssertTest.java:15)&lt;br /&gt;
&lt;br /&gt;
The above code prompts the user to enter an even number, then this number is read from command prompt.  The assert statement then determines whether the user entered an even or odd number. If the user entered an odd number (as in second case of output), then the program throws an error. Otherwise, the program proceeds normally. Lines that gets executed after the assert statement can assume that number is not odd&lt;br /&gt;
&lt;br /&gt;
One obvious question that may arise is when exceptions can do the [http://en.wikipedia.org/wiki/Exception_handling error handling] why we need another level of checking. Java exceptions are primarily used to handle unusual conditions arising during program execution.  Assertions are not to replace exceptions but to augment them. Assertions are used to specify conditions that a programmer assumes are true [11]. When programming, if a programmer can swear that the value being passed into a particular method is positive no matter what a calling client passes, it can be documented using an assertion to state it. Exceptions handle abnormal conditions arising in the course of the program; however they do not guarantee smooth or correct execution of the program. Assertions help state scenarios that ensure the program is running smoothly. Assertions can be efficient tools to ensure correct execution of a program [11]. They improve the confidence about the program.&lt;br /&gt;
&lt;br /&gt;
== '''Types of Assertions''' ==&lt;br /&gt;
* Preconditions - When a method is invoked, the state of the program at that time is indicated by precondition assertions. Precondition refers to the parameters passed to a method in a program. Precondition asserts validates the parameters passed to a method before they are used inside the method. &lt;br /&gt;
* Postconditions - The state of the program after a method completes its execution is indicated by postcondition assertions. Postcondition  should be evaluated before the exit point in a method. Postcondition asserts validates the return values in a method which has several return statements.&lt;br /&gt;
&lt;br /&gt;
One situation where use of assertions is helpful in Java programming language is : Internal Invariants. Assertions can be used within programs to make sure the program behaves in a predetermined manner and will throw an error when violated. For instance, an assertion can be placed in the code below to declare that age will never be negative [1].&lt;br /&gt;
&lt;br /&gt;
           if (age &amp;gt; 0)&lt;br /&gt;
           {&lt;br /&gt;
              age = age + 1;&lt;br /&gt;
           } &lt;br /&gt;
           else&lt;br /&gt;
           {&lt;br /&gt;
       		assert age &amp;gt;0:&amp;quot;Age cannot be negative&amp;quot;&lt;br /&gt;
           }&lt;br /&gt;
&lt;br /&gt;
== '''Enabling and Disabling Assertions'''==&lt;br /&gt;
&lt;br /&gt;
Assertions are disabled at runtime by default as they reduce performance. To enable assertions at [http://en.wikipedia.org/wiki/Run_time_(computing) runtime], use the -ea command-line option. To disable assertions, use –da command line option. To execute a code with assertions enabled use&lt;br /&gt;
         java -ea AssertTest&lt;br /&gt;
&lt;br /&gt;
The assertion status of a class (enabled or disabled) is set at the time it is initialized, and does not change. There is, however, one corner case that demands special treatment. It is possible, though generally not desirable, to execute methods or constructors prior to initialization. This can happen when a class hierarchy contains circularity in its static initialization. If an assert statement executes before its class is initialized, the execution must behave as if assertions were enabled in the class.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Java''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing Java code are JUnit , SpryTest , Jtest , TestNG and JExample. Other testing frameworks supported by Java can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Ruby''' =&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Unit_testing Unit testing] is a process where individual parts of [http://en.wikipedia.org/wiki/Source_code source code] are isolated and tested separately to determine if they are bug free. The idea behind unit testing is that you write a test method that makes certain assertions about your code, working against a test fixture. [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby language] supports a module called Test::Unit::Assertions in test/unit/assertions.rb. Test::Unit::Assertions contains the standard Test::Unit assertions. Assertions is included in Test::Unit::TestCase. &lt;br /&gt;
&lt;br /&gt;
=='''Public class assert methods'''==&lt;br /&gt;
&lt;br /&gt;
*assert( boolean, [msg] )- This ensures that the object/expression is true&lt;br /&gt;
  assert [10, 20].include?(50)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_block(message=&amp;quot;assert_block failed.&amp;quot;) {|| ...} - If the block yields to true , then the assert passes&lt;br /&gt;
Example [3]:&lt;br /&gt;
       def assert_block(message=&amp;quot;assert_block failed.&amp;quot;) # :yields: &lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          if (! yield)&lt;br /&gt;
            raise AssertionFailedError.new(message.to_s)&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* assert_match( regexp, string, [msg] )- Ensures that a string matches the regular expression&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_match(pattern, string, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        _wrap_assertion do&lt;br /&gt;
          pattern = case(pattern)&lt;br /&gt;
            when String&lt;br /&gt;
              Regexp.new(Regexp.escape(pattern))&lt;br /&gt;
            else&lt;br /&gt;
              pattern&lt;br /&gt;
          end&lt;br /&gt;
          full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be =~\n&amp;lt;?&amp;gt;.&amp;quot;, string, pattern)&lt;br /&gt;
          assert_block(full_message) { string =~ pattern }&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;) - If expected != actual, then the assert passes&lt;br /&gt;
&lt;br /&gt;
Example [3]:&lt;br /&gt;
      def assert_not_equal(expected, actual, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        full_message = build_message(message, &amp;quot;&amp;lt;?&amp;gt; expected to be != to\n&amp;lt;?&amp;gt;.&amp;quot;, expected, actual)&lt;br /&gt;
        assert_block(full_message) { expected != actual }&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*assert_nil(object, message=&amp;quot;&amp;quot;) - This assert passes if the object is nil.&lt;br /&gt;
&lt;br /&gt;
Example[3]:&lt;br /&gt;
&lt;br /&gt;
   # File test/unit/assertions.rb, line 173&lt;br /&gt;
      def assert_nil(object, message=&amp;quot;&amp;quot;)&lt;br /&gt;
        assert_equal(nil, object, message)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are a bunch of other public class methods. This can be obtained from [4]&lt;br /&gt;
&lt;br /&gt;
=='''Test Method &amp;amp; Test Fixture'''==&lt;br /&gt;
&lt;br /&gt;
Assertions must be used inside test methods within test fixtures. Related tests are grouped inside a common test class using assert. The advantage of having a separate class for all related tests is that it keeps the actual developed code to be tested uncluttered from the test code, hence making maintainability easier. It also allows these test code to be deleted from the development code before the final delivery as these test codes are needed mainly for the developer/tester and need not be part of the final product. Main advantage is it allows you to set up a common test fixture for your tests to run against. Test fixtures are a way of organizing test data; they reside in the fixtures folder. The test_helper.rb file holds the default configuration for your tests.&lt;br /&gt;
&lt;br /&gt;
=='''Ruby on Rails'''==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Ruby_on_Rails Rails] is an open source web framework for Ruby language. Rails adds some custom assertions of its own to the test/unit framework some of which are as stated below:&lt;br /&gt;
&lt;br /&gt;
*assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.&lt;br /&gt;
*assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. &lt;br /&gt;
Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
*assert_template(expected = nil, message=nil)&lt;br /&gt;
Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Ruby''' ==&lt;br /&gt;
&lt;br /&gt;
The only xUnit framework that support testing Ruby code is Test::Unit. Other testing frameworks that support Ruby but that do not fall under the xUnit umbrella are RSpec , Shoulda , microtest and Bacon.&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in C++''' =&lt;br /&gt;
In [http://en.wikipedia.org/wiki/C%2B%2B C++] the support for assertions is pretty limited. Assertion is mainly used for error detection during debugging. If an assertion fails ,the program would stop at that point and indicate which assertion caused the failure. &lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
In C++ assertions are defined in the header file [http://en.wikipedia.org/wiki/Assert.h Assert.h].&lt;br /&gt;
&lt;br /&gt;
* assert (expression);&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       assert(isAdmin == true);&lt;br /&gt;
&lt;br /&gt;
Similar to other languages , assertions can be turned off in C++ if the NDEBUG macro is defined before the inclusion of the header Assert.h .&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in C++''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing C++ code are API Sanity Autotest, C++test, Cantata++, CppUnit and CppTest. To see the complete list of xUnit and other testing frameworks supported by C++ please refer to [9]&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Python''' =&lt;br /&gt;
In [http://www.python.org/ Python] when the [http://docs.python.org/reference/simple_stmts.html#the-assert-statement assert] statement is encountered, the expression following the assert keyword is evaluated and the AssertionError exception is raised if the expression evaluates to false.&lt;br /&gt;
&lt;br /&gt;
== Simple Assert ==&lt;br /&gt;
&lt;br /&gt;
The following code would raise the [http://docs.python.org/library/exceptions.html#exceptions.AssertionError AssertionError] exception.&lt;br /&gt;
&lt;br /&gt;
* assert condition&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       assert 1 == 2&lt;br /&gt;
&lt;br /&gt;
== Extended Assert ==&lt;br /&gt;
&lt;br /&gt;
In addition to evaluating an expression , arguments can be passed to the assertion so that for example, the right message can be displayed based on the outcome of the assertion.&lt;br /&gt;
&lt;br /&gt;
* assert Expression[, Arguments]&lt;br /&gt;
&lt;br /&gt;
Example [8];&lt;br /&gt;
       #!/usr/bin/python&lt;br /&gt;
       def IsSenior(age):&lt;br /&gt;
          assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
          return (age &amp;gt;= 65)&lt;br /&gt;
       print IsSenior(15)&lt;br /&gt;
       print IsSenior(70)&lt;br /&gt;
       print IsSenior(-1)&lt;br /&gt;
&lt;br /&gt;
Example Output;&lt;br /&gt;
       false&lt;br /&gt;
       true&lt;br /&gt;
       Traceback (most recent call last):&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 9, in &amp;lt;module&amp;gt;&lt;br /&gt;
           print IsSenior(-5)&lt;br /&gt;
         File &amp;quot;test.py&amp;quot;, line 4, in IsSenior&lt;br /&gt;
           assert (age &amp;gt;= 1),&amp;quot;Age cannot be zero or less than zero !&amp;quot;&lt;br /&gt;
       AssertionError: Age cannot be zero or less than zero !&lt;br /&gt;
&lt;br /&gt;
One of the key feature of assertions in Python is that if python is started with -O option, then the assertions would not be evaluated. The scenario where this feature would apply is developers can write a lot of assertions for debugging and when the code is to be executed in production , if it is started with -O option , then all the assertions written by the developers for debugging would not be evaluated.&lt;br /&gt;
&lt;br /&gt;
In general assertions are not the best means to test for failure cases. Instead of using an assertion exceptions would be the right way to handle scenarios like wrong user input or system/environment failures.&lt;br /&gt;
&lt;br /&gt;
== '''xUnit Frameworks that support testing in Python''' ==&lt;br /&gt;
&lt;br /&gt;
Some of the xUnit frameworks that support testing python code are PyUnit, Nose, py.test and TwistedTrial. Other testing frameworks supported by python can be looked up at [9]&lt;br /&gt;
&lt;br /&gt;
One common used of assertions in python is for type checking. Please refer the article [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2007/wiki3_1_sa#Python Assertion in O-O languages] for more details.&lt;br /&gt;
&lt;br /&gt;
= '''Benefits of assertions''' =&lt;br /&gt;
*Use of assertions in the program help detect errors immediately and directly, rather than at a later stage. Assertion failure usually reports the location of failure in the code which helps in pin-pointing the error without further debugging.&lt;br /&gt;
*Assertions provide run time check for assumptions made by developers&lt;br /&gt;
*Assertions are also sometimes placed at points the execution is not supposed to reach. For example, assertions could be placed at the default clause of the switch statement in languages such as C++, and Java. Any case which the programmer does not handle intentionally will raise an error and the program will abort rather than silently continuing in an erroneous state.&lt;br /&gt;
*Assertions can be viewed as &amp;quot;dynamic documentation&amp;quot;, since they are checked at runtime, contrary to the traditional approach of documenting assumptions via plain /* comments */.&lt;br /&gt;
&lt;br /&gt;
*Assert statements are great for helping you to refactor and optimize your code with greater confidence that you have preserved correctness&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Limitations of assertions''' =&lt;br /&gt;
&lt;br /&gt;
*Assertions rarely allow for graceful error recovery. They terminate the program abruptly and may not release some of the resources used by the program; hence it is considered bad practice to rely upon assertions for handling expected error conditions.&lt;br /&gt;
* Assertions sometime hinder execution time. For example, if the program has an assert that checks to see if the number to be returned is the smallest in the array, then the assertion will have to do the same amount of work that the method would have to do.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
When writing program, it is a good practice to check for violations of basic assumptions in the code. These checks help in debugging code. The assertion facility in J2SE 1.4 (and later versions) provides a unified support for assertions in Java technology as well as a convenient way for developers both to turn assertions on and off as needed. Assertions are used in Test Driven Development(TDD) in Ruby programing language. The Test::Unit library in Ruby has a variety of built in assertions that makes writing tests much easier. As seen above assertions are natively supported in some languages like Ruby, whereas in languages like C++ and python it is merely used as a mechanism to track errors when debugging.&lt;br /&gt;
&lt;br /&gt;
Although the use of assertions replaces the adhoc use of conditional tests with a uniform methodology, it does not allow for a repair strategy to continue program execution. This means that when an exception is detected, the program aborts with no recovery mechanism. Nevertheless, assertions play an important role in debugging and designing code with testability in mind. The assertion facility can be used to support an informal design-by-contract style of programming.&lt;br /&gt;
&lt;br /&gt;
= '''Reference''' =&lt;br /&gt;
&lt;br /&gt;
[http://download.oracle.com/javase/1.4.2/docs/guide/lang/assert.html]  Programming with Assertions 	&lt;br /&gt;
&lt;br /&gt;
[http://www.deitel.com/articles/java_tutorials/20060106/Assertions.html]  Assertions in java&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit/Assertions.html#M004514] Assertions in Ruby&lt;br /&gt;
&lt;br /&gt;
[http://guides.rubyonrails.org/testing.html#assertions-available] Ruby assertions&lt;br /&gt;
&lt;br /&gt;
[http://topfunky.com/clients/rails/ruby_and_rails_assertions.pdf] Ruby on Rails assertion cheat sheet&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.clemson.edu/~malloy/papers/prospectus/prospectus.pdf] More about assertions&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/reference/simple_stmts.html] Python simple statements documentation&lt;br /&gt;
&lt;br /&gt;
[http://www.tutorialspoint.com/python/assertions_in_python.htm] Assertions in Python&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks] Testing frameworks for programming languages&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/XUnit] xUnit&lt;br /&gt;
&lt;br /&gt;
[http://javaboutique.internet.com/tutorials/assertions/] More on assertions&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=40338</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6b SK</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=40338"/>
		<updated>2010-11-13T22:58:51Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Support for Assertions in Various O-O Programming Languages'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Java''' =&lt;br /&gt;
&lt;br /&gt;
== '''Types of Assertions''' ==&lt;br /&gt;
&lt;br /&gt;
== '''Enabling and Disabling Assertions'''==&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Ruby''' =&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in C++''' =&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Python''' =&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Perl''' =&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in    ''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=40283</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6b SK</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6b_SK&amp;diff=40283"/>
		<updated>2010-11-12T00:02:53Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Support for Assertions in Various O-O Programming Languages'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Java''' =&lt;br /&gt;
&lt;br /&gt;
== '''Types of Assertions''' ==&lt;br /&gt;
&lt;br /&gt;
== '''Enabling and Disabling Assertions'''==&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Ruby''' =&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in C++''' =&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Python''' =&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in Perl''' =&lt;br /&gt;
&lt;br /&gt;
= '''Support for Assertions in    ''' =&lt;br /&gt;
&lt;br /&gt;
= '''Benefits and Drawbacks of using Assertions''' =&lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_ms&amp;diff=40282</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 ms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_ms&amp;diff=40282"/>
		<updated>2010-11-11T23:59:41Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE 517 Fall 2010/ch1 1a vc]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1a br]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1b mg]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1c JF]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1e az]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1e bb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1f vn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 25 ag]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 2b dg]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 2e RI]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S6 aa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S6 km]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 GP]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 MS]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 MM]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 PH]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 2a CB]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 2a mw]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 2c ck]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S23 GP]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S24 NS]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S23 SS]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S23 NR]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S20 TT]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 2d AS]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S24 rm]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch3 3a SN]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch3 3b ka]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch3 3e br]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch3 3f lj]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch3 3h az]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch3 3h PW]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch3 3i IC]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch3 3i MM]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch3 3j KS]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch3 S30 SK]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch3 4b mt]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch4 4e ms]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch4 4f sv]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch4 4g HW]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch4 4g km]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch4 4h am]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch5 5b mt]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch5 5b jz]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch5 5c ck]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch5 5c IC]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch5 5f SN]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch5 5a KR]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch5 5b RR]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch5 5e ms]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/chd 6d isb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch6 6b SK]]&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_ms&amp;diff=36263</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 ms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_ms&amp;diff=36263"/>
		<updated>2010-09-23T01:33:22Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[CSC/ECE 517 Fall 2010/ch1 1a vc]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1a br]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1b mg]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1c JF]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1e az]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1e bb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1f vn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 2b dg]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 2e RI]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S6 aa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S6 km]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 GP]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 MS]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 MM]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 PH]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 2b AT]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 2c ck]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S23 GP]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S24 NS]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S23 SS]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S23 NR]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S20 TT]]&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_ms&amp;diff=36262</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 ms</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_ms&amp;diff=36262"/>
		<updated>2010-09-23T01:32:09Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[CSC/ECE 517 Fall 2010/ch1 1a vc]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1a br]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1b mg]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1c JF]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1e az]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1e bb]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 1f vn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 2b dg]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 2e RI]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S6 aa]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S6 km]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 GP]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 MS]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 MM]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch1 S10 PH]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 2b AT]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 2c ck]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S23 GP]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S24 NS]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S23 SS]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S23 NR]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2010/ch2 S20 AA]]&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=MainPage&amp;diff=36255</id>
		<title>MainPage</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=MainPage&amp;diff=36255"/>
		<updated>2010-09-23T01:06:36Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: Main Page moved to Http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE 517 Fall 2010/ch1 S10 MS&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE 517 Fall 2010/ch1 S10 MS]]&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=36254</id>
		<title>Http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=36254"/>
		<updated>2010-09-23T01:06:36Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: Main Page moved to Http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE 517 Fall 2010/ch1 S10 MS&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;'''Wiki Text book !'''&amp;lt;/big&amp;gt;&lt;br /&gt;
* [[CSC 216]] learning exercise&lt;br /&gt;
* [[Expertiza documentation]]&lt;br /&gt;
* [[CSC 379]]&lt;br /&gt;
* [[CSC/ECE 506 Fall 2007]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2007]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34791</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34791"/>
		<updated>2010-09-16T21:27:19Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Different Ruby GUI toolkits''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of [http://en.wikipedia.org/wiki/Application_programming_interface API's] that helps in developing Graphical User Interface[http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for web based or desktop applications. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are plenty of Ruby GUI toolkits to choose from depending on applications being developed. Each has its own advantages and disadvantages. Tk is the oldest GUI toolkit among others. Shoes is the most recent one developed. WxRuby is the widely used toolkit. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
require loads the Tk ruby extension. TkRoot is similar to Object class. Every toolkit is extended from the root. Its a starter for the GUI&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
require loads the foxruby application. Fxapp is the programs instance created after which a new button with &amp;quot; Hello World&amp;quot; is created. Then the application is run and the message is displayed.&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This code initially loads the QtRuby extension.The app is the programs instance that is created here. A push button for &amp;quot;Hello World is created&amp;quot;. The button is set up to be 100 pixels wide and 30 pixels high. the show() is called to make the widget visible as it is always invisible when created. Finally Qt receives and processes user and system events and passes these on to the appropriate widgets. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Hello World&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
The class inherits from the app class of WXruby. The on_init method of a Wx::App class is run before the main loop of that application is entered. parent widget is the first parameter of the constructor. The second parameter of widget constructors is an id field. The third parameter of the Wx::Frame constructor is the text to display in the title .&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
  widget.get_size&lt;br /&gt;
  widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above: [19]&lt;br /&gt;
&lt;br /&gt;
  widget.size&lt;br /&gt;
  widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion.&lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/doc/wxruby_intro.html] Wxruby Overview&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34790</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34790"/>
		<updated>2010-09-16T20:55:51Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of [http://en.wikipedia.org/wiki/Application_programming_interface API's] that helps in developing Graphical User Interface[http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for web based or desktop applications. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
require loads the Tk ruby extension. TkRoot is similar to Object class. Every toolkit is extended from the root. Its a starter for the GUI&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
require loads the foxruby application. Fxapp is the programs instance created after which a new button with &amp;quot; Hello World&amp;quot; is created. Then the application is run and the message is displayed.&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This code initially loads the QtRuby extension.The app is the programs instance that is created here. A push button for &amp;quot;Hello World is created&amp;quot;. The button is set up to be 100 pixels wide and 30 pixels high. the show() is called to make the widget visible as it is always invisible when created. Finally Qt receives and processes user and system events and passes these on to the appropriate widgets. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Hello World&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
The class inherits from the app class of WXruby. The on_init method of a Wx::App class is run before the main loop of that application is entered. parent widget is the first parameter of the constructor. The second parameter of widget constructors is an id field. The third parameter of the Wx::Frame constructor is the text to display in the title .&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
  widget.get_size&lt;br /&gt;
  widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above: [19]&lt;br /&gt;
&lt;br /&gt;
  widget.size&lt;br /&gt;
  widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/doc/wxruby_intro.html] Wxruby Overview&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34789</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34789"/>
		<updated>2010-09-16T20:43:01Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Sample Hello World Program using Qt''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of [http://en.wikipedia.org/wiki/Application_programming_interface API's] that helps in developing Graphical User Interface[http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for web based or desktop applications. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
Line 1: Loads the Tk ruby extension&lt;br /&gt;
Line 2: TkRoot is similar to Object class. Every toolkit is extended from the root. &lt;br /&gt;
Line 3: Its a starter for the GUI&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Line 1 -loads the QtRuby extension.&lt;br /&gt;
*Line 2: app is the programs instance that is created here&lt;br /&gt;
*Line 3: A push button for &amp;quot;Hello World is created&amp;quot;&lt;br /&gt;
*Line 4: The button is set up to be 100 pixels wide and 30 pixels high&lt;br /&gt;
*Line 5 : show() is called to make the widget visible as it is always invisible when created.&lt;br /&gt;
*Line 6: Qt receives and processes user and system events and passes these on to the appropriate widgets. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
  widget.get_size&lt;br /&gt;
  widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above: [19]&lt;br /&gt;
&lt;br /&gt;
  widget.size&lt;br /&gt;
  widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/doc/wxruby_intro.html] Wxruby Overview&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34788</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34788"/>
		<updated>2010-09-16T20:42:27Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Sample Hello World Program using Qt''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of [http://en.wikipedia.org/wiki/Application_programming_interface API's] that helps in developing Graphical User Interface[http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for web based or desktop applications. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
Line 1: Loads the Tk ruby extension&lt;br /&gt;
Line 2: TkRoot is similar to Object class. Every toolkit is extended from the root. &lt;br /&gt;
Line 3: Its a starter for the GUI&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Line 1 -loads the QtRuby extension.&lt;br /&gt;
Line 2: app is the programs instance that is created here&lt;br /&gt;
Line 3: A push button for &amp;quot;Hello World is created&amp;quot;&lt;br /&gt;
Line 4: The button is set up to be 100 pixels wide and 30 pixels high&lt;br /&gt;
Line 5 : show() is called to make the widget visible as it is always invisible when created.&lt;br /&gt;
Line 6: Qt receives and processes user and system events and passes these on to the appropriate widgets. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
  widget.get_size&lt;br /&gt;
  widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above: [19]&lt;br /&gt;
&lt;br /&gt;
  widget.size&lt;br /&gt;
  widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/doc/wxruby_intro.html] Wxruby Overview&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34787</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34787"/>
		<updated>2010-09-16T20:41:46Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Sample Hello World Program using Tk''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of [http://en.wikipedia.org/wiki/Application_programming_interface API's] that helps in developing Graphical User Interface[http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for web based or desktop applications. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
Line 1: Loads the Tk ruby extension&lt;br /&gt;
Line 2: TkRoot is similar to Object class. Every toolkit is extended from the root. &lt;br /&gt;
Line 3: Its a starter for the GUI&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
  widget.get_size&lt;br /&gt;
  widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above: [19]&lt;br /&gt;
&lt;br /&gt;
  widget.size&lt;br /&gt;
  widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/doc/wxruby_intro.html] Wxruby Overview&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34785</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34785"/>
		<updated>2010-09-16T20:05:04Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Introduction''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of [http://en.wikipedia.org/wiki/Application_programming_interface API's] that helps in developing Graphical User Interface[http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for web based or desktop applications. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
  widget.get_size&lt;br /&gt;
  widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above: [19]&lt;br /&gt;
&lt;br /&gt;
  widget.size&lt;br /&gt;
  widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/doc/wxruby_intro.html] Wxruby Overview&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34784</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=34784"/>
		<updated>2010-09-16T20:03:04Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] that help in developing GUI for web based or desktop applications. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
  widget.get_size&lt;br /&gt;
  widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above: [19]&lt;br /&gt;
&lt;br /&gt;
  widget.size&lt;br /&gt;
  widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/doc/wxruby_intro.html] Wxruby Overview&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33980</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33980"/>
		<updated>2010-09-08T20:54:54Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Getting and Setting Options''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
  widget.get_size&lt;br /&gt;
  widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above: [19]&lt;br /&gt;
&lt;br /&gt;
  widget.size&lt;br /&gt;
  widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/doc/wxruby_intro.html] Wxruby Overview&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33979</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33979"/>
		<updated>2010-09-08T20:54:00Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''External Links''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
widget.get_size&lt;br /&gt;
widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above: &lt;br /&gt;
&lt;br /&gt;
# Ruby style&lt;br /&gt;
widget.size&lt;br /&gt;
widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/doc/wxruby_intro.html] Wxruby Overview&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33978</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33978"/>
		<updated>2010-09-08T20:53:05Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''WxRuby2''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
widget.get_size&lt;br /&gt;
widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above: &lt;br /&gt;
&lt;br /&gt;
# Ruby style&lt;br /&gt;
widget.size&lt;br /&gt;
widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33975</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33975"/>
		<updated>2010-09-08T20:52:26Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Creating Menu''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
widget.get_size&lt;br /&gt;
widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above:&lt;br /&gt;
&lt;br /&gt;
# Ruby style&lt;br /&gt;
widget.size&lt;br /&gt;
widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33973</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33973"/>
		<updated>2010-09-08T20:51:55Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''WxRuby2''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting options'''===&lt;br /&gt;
&lt;br /&gt;
C++ and Java conventions are used for naming the methods for getting and setting properties using wxWidgets API. For example, In C++ style,to get and set the size of a widget, the methods are named :&lt;br /&gt;
&lt;br /&gt;
widget.get_size&lt;br /&gt;
widget.set_size(new_size)&lt;br /&gt;
&lt;br /&gt;
In Ruby, methods are named simply after the property. Therefore, in wxRuby, the following are valid alternatives to the above:&lt;br /&gt;
&lt;br /&gt;
# Ruby style&lt;br /&gt;
widget.size&lt;br /&gt;
widget.size = new_size&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33960</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33960"/>
		<updated>2010-09-08T20:43:45Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''References''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -  [2]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After we create a widget AND SET ITS OPTIONS, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Cross Platform GUI&lt;br /&gt;
* Easy application development &lt;br /&gt;
* Available easily. &lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Documentation is not good&lt;br /&gt;
* Do not have good appearance&lt;br /&gt;
* Can be used only for simple application&lt;br /&gt;
* No support for native widgets&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
The options can be passed into the class's new method when the object is first instantiated. They can usually also be changed after the object exists through some object-specific accessor method. For example, the options for an FXButton can be get or set via the FXButton#buttonStyle accessor methods. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Easy to install and use&lt;br /&gt;
* Well documented&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Light weight when compared to WxRuby which is more fully featured&lt;br /&gt;
* Instead of using native widgets, it draws its own widgets on every platform &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information on FoxRuby can be obtained from [18].&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
All Qt setters begin with the word set, such as Qt::Widget::setMinimumSize and all getters begin with get. This can be overridden in Ruby by dropping the set and using assignment. This means the following three statements are equivalent:&lt;br /&gt;
&lt;br /&gt;
widget.setMinimumSize(50)&lt;br /&gt;
widget.minimumSize = 50     # same&lt;br /&gt;
widget.minimum_size = 50    # same&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Available on MS Windows, Mac, and GNU/Linux (under commercial license)&lt;br /&gt;
* Has a full-featured embeddable GUI&lt;br /&gt;
* Offers reliable commercial support&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though a gem is available for the Windows installation. only source code is available for other platforms.&lt;br /&gt;
* Costly preventing large scale adoption.&lt;br /&gt;
* Because Qt is a C++ toolkit, some idioms are used in the toolkit that are necessary due to constraints in the language.&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
More information about QtRuby and its usage can be obtained from [17].&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[8]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
* Stable and complete GUI toolkit&lt;br /&gt;
* Consistent look and feel because of the usage of native widgets&lt;br /&gt;
* Good support for all platforms&lt;br /&gt;
* WxWidgets has bindings for python, perl, java, lua, eiffel, C# (.NET), basic and ruby&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
&lt;br /&gt;
* Even though it has bindings for other languages, the API is mostly C++ oriented&lt;br /&gt;
* WxWidgets tries to support a very expansive feature set, and as a result, some lesser-used components of the toolkit are not as stable/reliable as commonly used components are&lt;br /&gt;
* It does not provide binaries for any system. &lt;br /&gt;
* It has to be compiled manually&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Benefits'''===&lt;br /&gt;
&lt;br /&gt;
* Good graphics&lt;br /&gt;
* Simple interface &lt;br /&gt;
* Control at a lower level&lt;br /&gt;
&lt;br /&gt;
==='''Drawbacks'''===&lt;br /&gt;
* Rough around the edges since it attempts to support so many platforms. &lt;br /&gt;
* Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* Dave Thomas, with Chad Fowler and Andy Hunt [http://pragprog.com/titles/ruby/programming-ruby ''Programing Ruby''], the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Julian Smart, Kevin Hock, Stefan Csomor [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false ''Cross-Platform GUI Programming with wxWidgets''] Prentice Hall PTR, 2006&lt;br /&gt;
&lt;br /&gt;
* Caleb Tennis [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby ''Rapid GUI Development with QtRuby''] the Pragmatic Programmers, LLC, 2005&lt;br /&gt;
&lt;br /&gt;
* Lyle Johnson [http://www.pragprog.com/titles/fxruby/fxruby ''Create Lean and Mean FxRuby GUIs''], the Pragmatic Programmers, LLC, 2008&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;br /&gt;
&lt;br /&gt;
[http://book.opensourceproject.org.cn/lamp/ruby/rubyway2nd/opensource/0768667208/ch12lev1sec4.html] QtRuby Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/api/] FoxRuby Documentation Tutorial&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33805</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33805"/>
		<updated>2010-09-08T16:40:59Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [1].&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code - [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [2]]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [3].&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [4].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [5].&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [15].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program [16].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [6].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example -  [7]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[8]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [9]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [10].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'[11]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [12]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. Disadvantages are-  It is still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [13]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33802</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33802"/>
		<updated>2010-09-08T16:31:51Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''CallBack ''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [1]].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code - [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [2]]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/ [3]].&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { &lt;br /&gt;
     text &amp;quot;Hi&amp;quot;&lt;br /&gt;
     command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/ [4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() &lt;br /&gt;
  {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new &lt;br /&gt;
  {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text')  » 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/ [5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [http://www.fxruby.org/doc/examples.html [15]].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [16]].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. Disadvantages are-  It is still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33800</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33800"/>
		<updated>2010-09-08T16:30:33Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Getting and Setting Options''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [1]].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code - [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [2]]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
     root = TkRoot.new do&lt;br /&gt;
       title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
       minsize(250,250)&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
     l1 = TkLabel.new(root) do&lt;br /&gt;
       text 'Hello world!'&lt;br /&gt;
       background 'blue'&lt;br /&gt;
       pack { padx 15; pady 15; }&lt;br /&gt;
     end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/ [3]].&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/ [4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/ [5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [http://www.fxruby.org/doc/examples.html [15]].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [16]].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. Disadvantages are-  It is still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33796</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33796"/>
		<updated>2010-09-08T16:29:27Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Sample Hello World Program using Tk''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
      msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [1]].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code - [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [2]]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/ [3]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/ [4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/ [5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [http://www.fxruby.org/doc/examples.html [15]].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [16]].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. Disadvantages are-  It is still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33398</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33398"/>
		<updated>2010-09-08T01:09:21Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Tk''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop applications. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [1]].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code - [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [2]]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/ [3]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/ [4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/ [5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [http://www.fxruby.org/doc/examples.html [15]].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [16]].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. Disadvantages are-  It is still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33299</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33299"/>
		<updated>2010-09-07T22:22:57Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Adding Status Bar''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [1]].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code - [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [2]]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/ [3]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/ [4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/ [5]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [http://www.fxruby.org/doc/examples.html [15]].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [16]].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. Disadvantages are-  It is still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33297</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33297"/>
		<updated>2010-09-07T22:22:28Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [1]].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code - [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI [2]]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/ [3]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/ [4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/ [5]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [http://www.fxruby.org/doc/examples.html [15]].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [16]].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9] ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. Disadvantages are-  It is still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33291</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33291"/>
		<updated>2010-09-07T22:17:58Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code - [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/[3]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/[4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [http://www.fxruby.org/doc/examples.html [15]].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [16]].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. Disadvantages are-  It is still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33276</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33276"/>
		<updated>2010-09-07T22:07:39Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code - [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/[3]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/[4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [http://www.fxruby.org/doc/examples.html [15]].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [16]].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33271</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33271"/>
		<updated>2010-09-07T22:02:20Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''=== &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]].&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== &lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code - [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/[3]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/[4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program  [http://www.fxruby.org/doc/examples.html [15]].&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== &lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of QtRuby program[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [16]].&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33268</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33268"/>
		<updated>2010-09-07T21:59:35Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''===  [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/[3]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/[4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''=== [http://www.fxruby.org/doc/examples.html [15]]&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== [http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [16]]&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
[http://www.fxruby.org/doc/examples.html] Hello World program using FxRuby&lt;br /&gt;
&lt;br /&gt;
[http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01] Hello World program using QtRuby&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33266</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33266"/>
		<updated>2010-09-07T21:55:09Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby libraries for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoes is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk which is an old toolkit. Shoes is the most recent toolkit developed for Ruby. But the most advantageous among all is agreed to be wxRuby2 as it is one of the most complete GUI toolkit with many utility classes. It also comes with a lot of documentation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''===  [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/[3]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/[4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== [http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [15]]&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33261</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33261"/>
		<updated>2010-09-07T21:49:01Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''===  [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''=== [http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot; [http://ruby-doc.org/docs/ProgrammingRuby/[3]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check [http://ruby-doc.org/docs/ProgrammingRuby/[4]].&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''=== [http://www.darshancomputing.com/qt4-qtruby-tutorial/chapter_01 [15]]&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed [http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]].&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc [http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow' [http://ruby.about.com/od/shoes/ss/shoes2.htm [11]].&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example - [http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33254</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33254"/>
		<updated>2010-09-07T21:38:02Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Conclusion''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit for Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRuby etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Tk'''===&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new {title “Hello World!”}&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;, which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
[[Image:first.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:sample label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[3]]&lt;br /&gt;
&lt;br /&gt;
==='''CallBack '''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check.&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be achieved dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[4]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:foxapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Qt'''===&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:qthellofirst.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]]&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' - It adds a menu item to the menu bar. Usually takes three arguments - ID, text to be displayed, keyboard shortcut.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu. append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]]&lt;br /&gt;
&lt;br /&gt;
[[Image:shoeapp.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm [11]]&lt;br /&gt;
&lt;br /&gt;
[[Image:flow app.jpg]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
Ruby is a [http://en.wikipedia.org/wiki/Multi-paradigm_programming_language#Multi-paradigm_programming_language multi-paradigm programming language].  It not only supports web application programming, but  is a good programming language to write cross platform GUI applications. There are lot of GUI toolkit  supported by Ruby from which one can choose to develop their web/desktop application.  TkRuby is one of the old cross platform GUI toolkit.  WxRuby is a very  stable toolkit with a good selection of widgets. QtRuby being a multiplatform toolkit provides interface for Mac, Windows and Unix Operating systems.  Fxruby incorporates the functionality of a featureful, highly optimized C++ toolkit. Shoes is a simplified GUI toolkit that creates native applications with a Web feel. These toolkits have their own advantages and disadvantages. It is good to experiment with several GUI toolkits and then choose the one that looks like the best fit for what is trying to be accomplished.&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33114</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33114"/>
		<updated>2010-09-07T06:10:58Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Sample HelloWorld Program using Qt''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit For Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRub etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and  easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for  ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances  and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Tk'''===&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new { title “Hello World!” }&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;,which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:Label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[3]]&lt;br /&gt;
&lt;br /&gt;
==='''CallBack and Binding Variables'''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check.&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be acheived dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[4]]&lt;br /&gt;
&lt;br /&gt;
==='''Canvas'''===&lt;br /&gt;
&lt;br /&gt;
The Canvas widget is used to draw any picture you want by mere pressing of a button and the movement of the mouse in which ever direction you want to. Once the button is released, a Post Script, which is nothing but the image drawn, is displayed. It is generally used if you want to draw large size pictures like outline of a house, single line diagram of any instrument or just a random drawing.&lt;br /&gt;
&lt;br /&gt;
==='''Scrolling'''===&lt;br /&gt;
&lt;br /&gt;
This is generally used when a subset or a smaller portion of an image is needed to work with. In that case, we set up scrollbars for the required class. The movement of the scroll bar changes the widget view and vice versa. Hence, they are inter-dependent or bidirectional.&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Qt'''===&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
     app = Qt::Application.new(ARGV)&lt;br /&gt;
     hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
     hello.resize(100, 30)&lt;br /&gt;
     hello.show()&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World(1).jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]]&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' -&amp;gt; It adds a menu item to the menu bar. Usually takes three arguments (ID, text to be displayed, keyboard shortcut, short  &lt;br /&gt;
            description (optional)) . The menu is appended by using two arguments (menu object, name of object)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu.append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Shoes.Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
[[Image:123.jpg]]&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm [11]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33113</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33113"/>
		<updated>2010-09-07T06:10:27Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Sample Hello World Program using Shoes''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit For Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRub etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and  easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for  ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances  and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Tk'''===&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new { title “Hello World!” }&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;,which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:Label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[3]]&lt;br /&gt;
&lt;br /&gt;
==='''CallBack and Binding Variables'''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check.&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be acheived dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[4]]&lt;br /&gt;
&lt;br /&gt;
==='''Canvas'''===&lt;br /&gt;
&lt;br /&gt;
The Canvas widget is used to draw any picture you want by mere pressing of a button and the movement of the mouse in which ever direction you want to. Once the button is released, a Post Script, which is nothing but the image drawn, is displayed. It is generally used if you want to draw large size pictures like outline of a house, single line diagram of any instrument or just a random drawing.&lt;br /&gt;
&lt;br /&gt;
==='''Scrolling'''===&lt;br /&gt;
&lt;br /&gt;
This is generally used when a subset or a smaller portion of an image is needed to work with. In that case, we set up scrollbars for the required class. The movement of the scroll bar changes the widget view and vice versa. Hence, they are inter-dependent or bidirectional.&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Qt'''===&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
&lt;br /&gt;
  app = Qt::Application.new(ARGV)&lt;br /&gt;
&lt;br /&gt;
  hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
  hello.resize(100, 30)&lt;br /&gt;
  hello.show()&lt;br /&gt;
&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World(1).jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]]&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' -&amp;gt; It adds a menu item to the menu bar. Usually takes three arguments (ID, text to be displayed, keyboard shortcut, short  &lt;br /&gt;
            description (optional)) . The menu is appended by using two arguments (menu object, name of object)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu.append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Shoes.Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
[[Image:123.jpg]]&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm [11]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
    image 'lilies.jpg'&lt;br /&gt;
    image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
    'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33111</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33111"/>
		<updated>2010-09-07T06:08:32Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit For Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRub etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and  easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for  ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances  and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Tk'''===&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new { title “Hello World!” }&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;,which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    root = TkRoot.new do&lt;br /&gt;
     title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
     minsize(250,250)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    l1 = TkLabel.new(root) do&lt;br /&gt;
      text 'Hello world!'&lt;br /&gt;
      background 'blue'&lt;br /&gt;
      pack { padx 15; pady 15; }&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:Label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[3]]&lt;br /&gt;
&lt;br /&gt;
==='''CallBack and Binding Variables'''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check.&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be acheived dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[4]]&lt;br /&gt;
&lt;br /&gt;
==='''Canvas'''===&lt;br /&gt;
&lt;br /&gt;
The Canvas widget is used to draw any picture you want by mere pressing of a button and the movement of the mouse in which ever direction you want to. Once the button is released, a Post Script, which is nothing but the image drawn, is displayed. It is generally used if you want to draw large size pictures like outline of a house, single line diagram of any instrument or just a random drawing.&lt;br /&gt;
&lt;br /&gt;
==='''Scrolling'''===&lt;br /&gt;
&lt;br /&gt;
This is generally used when a subset or a smaller portion of an image is needed to work with. In that case, we set up scrollbars for the required class. The movement of the scroll bar changes the widget view and vice versa. Hence, they are inter-dependent or bidirectional.&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Qt'''===&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
&lt;br /&gt;
  app = Qt::Application.new(ARGV)&lt;br /&gt;
&lt;br /&gt;
  hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
  hello.resize(100, 30)&lt;br /&gt;
  hello.show()&lt;br /&gt;
&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World(1).jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]]&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' -&amp;gt; It adds a menu item to the menu bar. Usually takes three arguments (ID, text to be displayed, keyboard shortcut, short  &lt;br /&gt;
            description (optional)) . The menu is appended by using two arguments (menu object, name of object)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu.append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Shoes.Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
[[Image:123.jpg]]&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm [11]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
&lt;br /&gt;
  image 'lilies.jpg'&lt;br /&gt;
  image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
  'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33109</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33109"/>
		<updated>2010-09-07T06:07:27Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''Sample HelloWorld Program using FxRuby''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit For Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRub etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and  easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for  ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances  and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Tk'''===&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new { title “Hello World!” }&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;,which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  root = TkRoot.new do&lt;br /&gt;
   title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
   minsize(250,250)&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  l1 = TkLabel.new(root) do&lt;br /&gt;
    text 'Hello world!'&lt;br /&gt;
    background 'blue'&lt;br /&gt;
    pack { padx 15; pady 15; }&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:Label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[3]]&lt;br /&gt;
&lt;br /&gt;
==='''CallBack and Binding Variables'''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check.&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be acheived dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[4]]&lt;br /&gt;
&lt;br /&gt;
==='''Canvas'''===&lt;br /&gt;
&lt;br /&gt;
The Canvas widget is used to draw any picture you want by mere pressing of a button and the movement of the mouse in which ever direction you want to. Once the button is released, a Post Script, which is nothing but the image drawn, is displayed. It is generally used if you want to draw large size pictures like outline of a house, single line diagram of any instrument or just a random drawing.&lt;br /&gt;
&lt;br /&gt;
==='''Scrolling'''===&lt;br /&gt;
&lt;br /&gt;
This is generally used when a subset or a smaller portion of an image is needed to work with. In that case, we set up scrollbars for the required class. The movement of the scroll bar changes the widget view and vice versa. Hence, they are inter-dependent or bidirectional.&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
  include Fox&lt;br /&gt;
    application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
    main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
    FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
    application.create()&lt;br /&gt;
    main.show(PLACEMENT_SCREEN)&lt;br /&gt;
    application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello.jpg]]&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Qt'''===&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
&lt;br /&gt;
  app = Qt::Application.new(ARGV)&lt;br /&gt;
&lt;br /&gt;
  hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
  hello.resize(100, 30)&lt;br /&gt;
  hello.show()&lt;br /&gt;
&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World(1).jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]]&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' -&amp;gt; It adds a menu item to the menu bar. Usually takes three arguments (ID, text to be displayed, keyboard shortcut, short  &lt;br /&gt;
            description (optional)) . The menu is appended by using two arguments (menu object, name of object)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu.append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Shoes.Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
[[Image:123.jpg]]&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm [11]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
&lt;br /&gt;
  image 'lilies.jpg'&lt;br /&gt;
  image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
  'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33107</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33107"/>
		<updated>2010-09-07T06:05:38Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''CallBack and Binding Variables''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit For Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRub etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and  easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for  ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances  and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Tk'''===&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new { title “Hello World!” }&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;,which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  root = TkRoot.new do&lt;br /&gt;
   title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
   minsize(250,250)&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  l1 = TkLabel.new(root) do&lt;br /&gt;
    text 'Hello world!'&lt;br /&gt;
    background 'blue'&lt;br /&gt;
    pack { padx 15; pady 15; }&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:Label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[3]]&lt;br /&gt;
&lt;br /&gt;
==='''CallBack and Binding Variables'''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check.&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be acheived dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[4]]&lt;br /&gt;
&lt;br /&gt;
==='''Canvas'''===&lt;br /&gt;
&lt;br /&gt;
The Canvas widget is used to draw any picture you want by mere pressing of a button and the movement of the mouse in which ever direction you want to. Once the button is released, a Post Script, which is nothing but the image drawn, is displayed. It is generally used if you want to draw large size pictures like outline of a house, single line diagram of any instrument or just a random drawing.&lt;br /&gt;
&lt;br /&gt;
==='''Scrolling'''===&lt;br /&gt;
&lt;br /&gt;
This is generally used when a subset or a smaller portion of an image is needed to work with. In that case, we set up scrollbars for the required class. The movement of the scroll bar changes the widget view and vice versa. Hence, they are inter-dependent or bidirectional.&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
&lt;br /&gt;
  include Fox&lt;br /&gt;
&lt;br /&gt;
  application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
  main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
  FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
  application.create()&lt;br /&gt;
  main.show(PLACEMENT_SCREEN)&lt;br /&gt;
  application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Qt'''===&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
&lt;br /&gt;
  app = Qt::Application.new(ARGV)&lt;br /&gt;
&lt;br /&gt;
  hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
  hello.resize(100, 30)&lt;br /&gt;
  hello.show()&lt;br /&gt;
&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World(1).jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]]&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' -&amp;gt; It adds a menu item to the menu bar. Usually takes three arguments (ID, text to be displayed, keyboard shortcut, short  &lt;br /&gt;
            description (optional)) . The menu is appended by using two arguments (menu object, name of object)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu.append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Shoes.Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
[[Image:123.jpg]]&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm [11]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
&lt;br /&gt;
  image 'lilies.jpg'&lt;br /&gt;
  image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
  'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33106</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33106"/>
		<updated>2010-09-07T06:04:59Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit For Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRub etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and  easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for  ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances  and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Tk'''===&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new { title “Hello World!” }&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;,which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  root = TkRoot.new do&lt;br /&gt;
   title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
   minsize(250,250)&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  l1 = TkLabel.new(root) do&lt;br /&gt;
    text 'Hello world!'&lt;br /&gt;
    background 'blue'&lt;br /&gt;
    pack { padx 15; pady 15; }&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:Label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[3]]&lt;br /&gt;
&lt;br /&gt;
==='''CallBack and Binding Variables'''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check.&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be acheived dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[4]] &lt;br /&gt;
&lt;br /&gt;
==='''Canvas'''===&lt;br /&gt;
&lt;br /&gt;
The Canvas widget is used to draw any picture you want by mere pressing of a button and the movement of the mouse in which ever direction you want to. Once the button is released, a Post Script, which is nothing but the image drawn, is displayed. It is generally used if you want to draw large size pictures like outline of a house, single line diagram of any instrument or just a random drawing.&lt;br /&gt;
&lt;br /&gt;
==='''Scrolling'''===&lt;br /&gt;
&lt;br /&gt;
This is generally used when a subset or a smaller portion of an image is needed to work with. In that case, we set up scrollbars for the required class. The movement of the scroll bar changes the widget view and vice versa. Hence, they are inter-dependent or bidirectional.&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==  &lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
  #!/usr/bin/env ruby&lt;br /&gt;
&lt;br /&gt;
  require 'fox16'&lt;br /&gt;
&lt;br /&gt;
  include Fox&lt;br /&gt;
&lt;br /&gt;
  application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
  main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
  FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
  application.create()&lt;br /&gt;
  main.show(PLACEMENT_SCREEN)&lt;br /&gt;
  application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Qt'''===&lt;br /&gt;
&lt;br /&gt;
  require 'Qt4'&lt;br /&gt;
&lt;br /&gt;
  app = Qt::Application.new(ARGV)&lt;br /&gt;
&lt;br /&gt;
  hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
  hello.resize(100, 30)&lt;br /&gt;
  hello.show()&lt;br /&gt;
&lt;br /&gt;
  app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World(1).jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
  require 'wx'&lt;br /&gt;
 &lt;br /&gt;
   class MyApp &amp;lt; Wx::App&lt;br /&gt;
     def on_init&lt;br /&gt;
       @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
       @frame.show&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 &lt;br /&gt;
   app = MyApp.new&lt;br /&gt;
   app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]]&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' -&amp;gt; It adds a menu item to the menu bar. Usually takes three arguments (ID, text to be displayed, keyboard shortcut, short  &lt;br /&gt;
            description (optional)) . The menu is appended by using two arguments (menu object, name of object)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
  help = Wx::Menu.new&lt;br /&gt;
  help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
  menu.append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  status = Wx::StatusBar.new(self)&lt;br /&gt;
  status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
     para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Shoes.Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
    flow :width =&amp;gt; 250 do&lt;br /&gt;
    button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
    button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
[[Image:123.jpg]]&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm [11]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  stack do&lt;br /&gt;
&lt;br /&gt;
  image 'lilies.jpg'&lt;br /&gt;
  image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
  'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33104</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33104"/>
		<updated>2010-09-07T05:56:06Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit For Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRub etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and  easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for  ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances  and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Tk'''===&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
    msg = TkRoot.new { title “Hello World!” }&lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;,which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  root = TkRoot.new do&lt;br /&gt;
   title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
   minsize(250,250)&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  l1 = TkLabel.new(root) do&lt;br /&gt;
    text 'Hello world!'&lt;br /&gt;
    background 'blue'&lt;br /&gt;
    pack { padx 15; pady 15; }&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:Label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[3]]&lt;br /&gt;
&lt;br /&gt;
==='''CallBack and Binding Variables'''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
  TkLabel.new()&lt;br /&gt;
  { text &amp;quot;Hi&amp;quot;&lt;br /&gt;
    command proc {l appcheck.value; exit }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check.&lt;br /&gt;
&lt;br /&gt;
  appcheck = TkVariable.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  TkCheckButton.new() {&lt;br /&gt;
    variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be acheived dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
  require 'tk'&lt;br /&gt;
  l = TkLabel.new {&lt;br /&gt;
    text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
    color    &amp;quot;black&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
  l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[4]] &lt;br /&gt;
&lt;br /&gt;
==='''Canvas'''===&lt;br /&gt;
&lt;br /&gt;
The Canvas widget is used to draw any picture you want by mere pressing of a button and the movement of the mouse in which ever direction you want to. Once the button is released, a Post Script, which is nothing but the image drawn, is displayed. It is generally used if you want to draw large size pictures like outline of a house, single line diagram of any instrument or just a random drawing.&lt;br /&gt;
&lt;br /&gt;
==='''Scrolling'''===&lt;br /&gt;
&lt;br /&gt;
This is generally used when a subset or a smaller portion of an image is needed to work with. In that case, we set up scrollbars for the required class. The movement of the scroll bar changes the widget view and vice versa. Hence, they are inter-dependent or bidirectional.&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
#!/usr/bin/env ruby&lt;br /&gt;
&lt;br /&gt;
require 'fox16'&lt;br /&gt;
&lt;br /&gt;
include Fox&lt;br /&gt;
&lt;br /&gt;
application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
application.create()&lt;br /&gt;
main.show(PLACEMENT_SCREEN)&lt;br /&gt;
application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Qt'''===&lt;br /&gt;
&lt;br /&gt;
require 'Qt4'&lt;br /&gt;
&lt;br /&gt;
app = Qt::Application.new(ARGV)&lt;br /&gt;
&lt;br /&gt;
hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
hello.resize(100, 30)&lt;br /&gt;
hello.show()&lt;br /&gt;
&lt;br /&gt;
app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World(1).jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
require 'wx'&lt;br /&gt;
 &lt;br /&gt;
 class MyApp &amp;lt; Wx::App&lt;br /&gt;
   def on_init&lt;br /&gt;
     @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
     @frame.show&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 app = MyApp.new&lt;br /&gt;
 app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]]&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' -&amp;gt; It adds a menu item to the menu bar. Usually takes three arguments (ID, text to be displayed, keyboard shortcut, short  &lt;br /&gt;
            description (optional)) . The menu is appended by using two arguments (menu object, name of object)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
help = Wx::Menu.new&lt;br /&gt;
help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
menu.append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
status = Wx::StatusBar.new(self)&lt;br /&gt;
status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
   para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Shoes.Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
  flow :width =&amp;gt; 250 do&lt;br /&gt;
  button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
  button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
  button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
[[Image:123.jpg]]&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm [11]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
stack do&lt;br /&gt;
&lt;br /&gt;
image 'lilies.jpg'&lt;br /&gt;
image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33103</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33103"/>
		<updated>2010-09-07T05:49:08Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit For Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRub etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and  easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for  ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances  and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Tk'''===&lt;br /&gt;
&lt;br /&gt;
require 'tk'&lt;br /&gt;
  msg = TkRoot.new { title “Hello World!” }&lt;br /&gt;
Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;,which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
require 'tk'&lt;br /&gt;
 &lt;br /&gt;
root = TkRoot.new do&lt;br /&gt;
title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
minsize(250,250)&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
l1 = TkLabel.new(root) do&lt;br /&gt;
text 'Hello world!'&lt;br /&gt;
background 'blue'&lt;br /&gt;
pack { padx 15; pady 15; }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:Label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[3]]&lt;br /&gt;
&lt;br /&gt;
==='''CallBack and Binding Variables'''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
TkLabel.new()&lt;br /&gt;
{ text &amp;quot;Hi&amp;quot;&lt;br /&gt;
  command proc {l appcheck.value; exit }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check.&lt;br /&gt;
&lt;br /&gt;
appcheck = TkVariable.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TkCheckButton.new() {&lt;br /&gt;
  variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be acheived dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
require 'tk'&lt;br /&gt;
l = TkLabel.new {&lt;br /&gt;
  text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  color    &amp;quot;black&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[4]] &lt;br /&gt;
&lt;br /&gt;
==='''Canvas'''===&lt;br /&gt;
&lt;br /&gt;
The Canvas widget is used to draw any picture you want by mere pressing of a button and the movement of the mouse in which ever direction you want to. Once the button is released, a Post Script, which is nothing but the image drawn, is displayed. It is generally used if you want to draw large size pictures like outline of a house, single line diagram of any instrument or just a random drawing.&lt;br /&gt;
&lt;br /&gt;
==='''Scrolling'''===&lt;br /&gt;
&lt;br /&gt;
This is generally used when a subset or a smaller portion of an image is needed to work with. In that case, we set up scrollbars for the required class. The movement of the scroll bar changes the widget view and vice versa. Hence, they are inter-dependent or bidirectional.&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
#!/usr/bin/env ruby&lt;br /&gt;
&lt;br /&gt;
require 'fox16'&lt;br /&gt;
&lt;br /&gt;
include Fox&lt;br /&gt;
&lt;br /&gt;
application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
application.create()&lt;br /&gt;
main.show(PLACEMENT_SCREEN)&lt;br /&gt;
application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Qt'''===&lt;br /&gt;
&lt;br /&gt;
require 'Qt4'&lt;br /&gt;
&lt;br /&gt;
app = Qt::Application.new(ARGV)&lt;br /&gt;
&lt;br /&gt;
hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
hello.resize(100, 30)&lt;br /&gt;
hello.show()&lt;br /&gt;
&lt;br /&gt;
app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World(1).jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
require 'wx'&lt;br /&gt;
 &lt;br /&gt;
 class MyApp &amp;lt; Wx::App&lt;br /&gt;
   def on_init&lt;br /&gt;
     @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
     @frame.show&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 app = MyApp.new&lt;br /&gt;
 app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]]&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' -&amp;gt; It adds a menu item to the menu bar. Usually takes three arguments (ID, text to be displayed, keyboard shortcut, short  &lt;br /&gt;
            description (optional)) . The menu is appended by using two arguments (menu object, name of object)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
help = Wx::Menu.new&lt;br /&gt;
help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
menu.append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
status = Wx::StatusBar.new(self)&lt;br /&gt;
status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
   para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Shoes.Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
  flow :width =&amp;gt; 250 do&lt;br /&gt;
  button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
  button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
  button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
[[Image:123.jpg]]&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm [11]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
stack do&lt;br /&gt;
&lt;br /&gt;
image 'lilies.jpg'&lt;br /&gt;
image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33102</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33102"/>
		<updated>2010-09-07T05:47:45Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: /* '''References''' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit For Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRub etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and  easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for  ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances  and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Tk'''===&lt;br /&gt;
&lt;br /&gt;
require 'tk'&lt;br /&gt;
  msg = TkRoot.new { title “Hello World!” }&lt;br /&gt;
Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;,which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
require 'tk'&lt;br /&gt;
 &lt;br /&gt;
root = TkRoot.new do&lt;br /&gt;
title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
minsize(250,250)&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
l1 = TkLabel.new(root) do&lt;br /&gt;
text 'Hello world!'&lt;br /&gt;
background 'blue'&lt;br /&gt;
pack { padx 15; pady 15; }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:Label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[3]]&lt;br /&gt;
&lt;br /&gt;
==='''CallBack and Binding Variables'''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
TkLabel.new()&lt;br /&gt;
{ text &amp;quot;Hi&amp;quot;&lt;br /&gt;
  command proc {l appcheck.value; exit }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check.&lt;br /&gt;
&lt;br /&gt;
appcheck = TkVariable.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TkCheckButton.new() {&lt;br /&gt;
  variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be acheived dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
require 'tk'&lt;br /&gt;
l = TkLabel.new {&lt;br /&gt;
  text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  color    &amp;quot;black&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[4]] &lt;br /&gt;
&lt;br /&gt;
==='''Canvas'''===&lt;br /&gt;
&lt;br /&gt;
The Canvas widget is used to draw any picture you want by mere pressing of a button and the movement of the mouse in which ever direction you want to. Once the button is released, a Post Script, which is nothing but the image drawn, is displayed. It is generally used if you want to draw large size pictures like outline of a house, single line diagram of any instrument or just a random drawing.&lt;br /&gt;
&lt;br /&gt;
==='''Scrolling'''===&lt;br /&gt;
&lt;br /&gt;
This is generally used when a subset or a smaller portion of an image is needed to work with. In that case, we set up scrollbars for the required class. The movement of the scroll bar changes the widget view and vice versa. Hence, they are inter-dependent or bidirectional.&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
#!/usr/bin/env ruby&lt;br /&gt;
&lt;br /&gt;
require 'fox16'&lt;br /&gt;
&lt;br /&gt;
include Fox&lt;br /&gt;
&lt;br /&gt;
application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
application.create()&lt;br /&gt;
main.show(PLACEMENT_SCREEN)&lt;br /&gt;
application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Qt'''===&lt;br /&gt;
&lt;br /&gt;
require 'Qt4'&lt;br /&gt;
&lt;br /&gt;
app = Qt::Application.new(ARGV)&lt;br /&gt;
&lt;br /&gt;
hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
hello.resize(100, 30)&lt;br /&gt;
hello.show()&lt;br /&gt;
&lt;br /&gt;
app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World(1).jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
require 'wx'&lt;br /&gt;
 &lt;br /&gt;
 class MyApp &amp;lt; Wx::App&lt;br /&gt;
   def on_init&lt;br /&gt;
     @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
     @frame.show&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 app = MyApp.new&lt;br /&gt;
 app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]]&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' -&amp;gt; It adds a menu item to the menu bar. Usually takes three arguments (ID, text to be displayed, keyboard shortcut, short  &lt;br /&gt;
            description (optional)) . The menu is appended by using two arguments (menu object, name of object)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
help = Wx::Menu.new&lt;br /&gt;
help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
menu.append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
status = Wx::StatusBar.new(self)&lt;br /&gt;
status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
   para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Shoes.Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
  flow :width =&amp;gt; 250 do&lt;br /&gt;
  button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
  button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
  button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[[Image:123.jpg]]&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm [11]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
stack do&lt;br /&gt;
&lt;br /&gt;
image 'lilies.jpg'&lt;br /&gt;
image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ruby/programming-ruby Programing Ruby ] &lt;br /&gt;
&lt;br /&gt;
* [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false Cross-Platform GUI Programming with wxWidgets] &lt;br /&gt;
&lt;br /&gt;
* [http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx Ruby Shoes] &lt;br /&gt;
&lt;br /&gt;
* [http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby Rapid GUI Development with QtRuby] &lt;br /&gt;
&lt;br /&gt;
* [http://www.pragprog.com/titles/fxruby/fxruby Create Lean and Mean FxRuby GUIs]&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33101</id>
		<title>CSC/ECE 517 Fall 2010/ch1 S10 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch1_S10_MS&amp;diff=33101"/>
		<updated>2010-09-07T05:44:48Z</updated>

		<summary type="html">&lt;p&gt;Daffodil: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''GUI Toolkit For Ruby'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Introduction''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Widget_toolkit/ GUI toolkit] is a collection of set of [http://en.wikipedia.org/wiki/Application_programming_interface API's] which will produce graphical user interface [http://en.wikipedia.org/wiki/Graphical_user_interface (GUI)] for the end users to interact with. Generally, this toolkit creates separate windows, each with one application that makes use of a particular [http://en.wikipedia.org/wiki/Web_widget widget].  Ruby is an object oriented dynamically typed programming language. It is used extensively for developing web applications (mostly with Rails) and for utility scripting. Initially RUBY was not a well known language for developing desktop application GUIs as it did not have good GUI libraries.  With developments in Shoes, wxRuby, FXRub etc which are ruby library for creating web like desktop applications, Ruby GUI started picking up and became increasingly popular. Shoe is the most popular among all of these. This article describes different types of ruby GUI toolkits, their uses and their pros and cons.&lt;br /&gt;
&lt;br /&gt;
Ruby is a very useful language for writing end user application and most of the present day end user application makes use of GUI.  The main advantage of Ruby is that it enables [http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development].  Unlike the time consuming traditional programming languages where you code, compile and then test, Ruby scripts can be quickly and  easily changed to try new ideas. This is a big advantage when developing GUI applications using Ruby. The user interface can be constructed incrementally, adding new elements and then re-running the program to see how the user interface has changed  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Different Ruby GUI toolkits''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ruby does not have any real GUI System. The default GUI Toolkit used is Tk. Shoes is the most recent toolkit being used for Ruby. But the most advantageous among all is agreed to be wxRuby2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Tk'''==&lt;br /&gt;
&lt;br /&gt;
Tk, which is a standard and [http://en.wikipedia.org/wiki/Cross-platform cross platform] GUI for  ruby was used to develop desktop apps. It is generally installed by the Ruby Installer itself and has a complete documented API. It is relatively old, does not care about appearances  and is suitable only for simple GUI applications. But it is perfectly functional and is also easily available. It was not well documented and was not object oriented. &lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Tk'''===&lt;br /&gt;
&lt;br /&gt;
require 'tk'&lt;br /&gt;
  msg = TkRoot.new { title “Hello World!” }&lt;br /&gt;
Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
It is mandatory to instruct Ruby that it should &amp;quot;require tk&amp;quot; and &amp;quot;Tk.mainloop&amp;quot;,which is the [http://en.wikipedia.org/wiki/Event_handler event handler], is needed to start the GUI. All subsequent widgets will be contained in the root if their parent class is not specified.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[1]] &lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
==='''Getting and Setting Options'''===&lt;br /&gt;
&lt;br /&gt;
To proceed to a more detailed application, let us look at the following code -&lt;br /&gt;
&lt;br /&gt;
require 'tk'&lt;br /&gt;
 &lt;br /&gt;
root = TkRoot.new do&lt;br /&gt;
title &amp;quot;Hello world!&amp;quot; &lt;br /&gt;
minsize(250,250)&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
l1 = TkLabel.new(root) do&lt;br /&gt;
text 'Hello world!'&lt;br /&gt;
background 'blue'&lt;br /&gt;
pack { padx 15; pady 15; }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
Tk.mainloop&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI[2]]&lt;br /&gt;
&lt;br /&gt;
This creates a window of the specified size with the title Hello World and embeds a widget - Label,  with the text Hello World and the background in blue. The 'pack' is called the geometry manager and specifies the pixel co-ordinates along with the justification of the text inside. It usually takes hash arguments. &lt;br /&gt;
&lt;br /&gt;
[[Image:Label.jpg]]&lt;br /&gt;
&lt;br /&gt;
It is also possible to change the setting of options dynamically. &lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
command proc { ll.configure('text'=&amp;gt;&amp;quot;Bye Bye&amp;quot;) }&lt;br /&gt;
&lt;br /&gt;
The 'configure' method will change the text output to &amp;quot;Bye Bye&amp;quot; over writing &amp;quot;Hello World&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[3]]&lt;br /&gt;
&lt;br /&gt;
==='''CallBack and Binding Variables'''=== &lt;br /&gt;
&lt;br /&gt;
After we create a widget, it is necessary most of the time to get back data from it. This is done by using callback. Getting back data means to get back a '0' or '1' depending on whether the required application does what it is meant to do. Using callback, a proc Object is created which is called as soon as the callback starts.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
TkLabel.new()&lt;br /&gt;
{ text &amp;quot;Hi&amp;quot;&lt;br /&gt;
  command proc {l appcheck.value; exit }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The same thing is achieved by binding variables where a reference is created using TkVariable. This reference is then passed as an argument to the 'variable' option and output is obtained after the check.&lt;br /&gt;
&lt;br /&gt;
appcheck = TkVariable.new&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
TkCheckButton.new() {&lt;br /&gt;
  variable mycheck&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
This action of getting data can also be acheived dynamically using the cget(arg) method. &lt;br /&gt;
&lt;br /&gt;
require 'tk'&lt;br /&gt;
l = TkLabel.new {&lt;br /&gt;
  text     &amp;quot;Good Morning&amp;quot;&lt;br /&gt;
  color    &amp;quot;black&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
l.cget('text') 	» 	&amp;quot;Good Morning&amp;quot;&lt;br /&gt;
l.cget('color') » 	&amp;quot;black&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/[4]] &lt;br /&gt;
&lt;br /&gt;
==='''Canvas'''===&lt;br /&gt;
&lt;br /&gt;
The Canvas widget is used to draw any picture you want by mere pressing of a button and the movement of the mouse in which ever direction you want to. Once the button is released, a Post Script, which is nothing but the image drawn, is displayed. It is generally used if you want to draw large size pictures like outline of a house, single line diagram of any instrument or just a random drawing.&lt;br /&gt;
&lt;br /&gt;
==='''Scrolling'''===&lt;br /&gt;
&lt;br /&gt;
This is generally used when a subset or a smaller portion of an image is needed to work with. In that case, we set up scrollbars for the required class. The movement of the scroll bar changes the widget view and vice versa. Hence, they are inter-dependent or bidirectional.&lt;br /&gt;
&lt;br /&gt;
More information about Tk as GUI Toolkit and example programs can be found in the book [http://ruby-doc.org/docs/ProgrammingRuby/[5]]&lt;br /&gt;
&lt;br /&gt;
=='''FxRuby'''==&lt;br /&gt;
&lt;br /&gt;
This is another powerful GUI toolkit for Ruby that helps in developing user interfaces easily and effectively.  It makes use of [http://en.wikipedia.org/wiki/Fox_toolkit Free Objects for X (FOX) toolkit] which is a C++ open source library.  This uses the powerful features of Ruby at the same time takes benefits of functionality and performance of greatly optimized C++ toolkit.  Unlike Tk, none of the Linux distributions include FOX as a standard installation package. A prerequisite for programming with FXRuby is to have a working FOX installation after which the FXRuby source code can be downloaded from the FXRuby home page, and build and install that extension module.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using FxRuby'''===&lt;br /&gt;
&lt;br /&gt;
The hello.rb program can be used  as an example for understanding the basics of FXRuby program.&lt;br /&gt;
#!/usr/bin/env ruby&lt;br /&gt;
&lt;br /&gt;
require 'fox16'&lt;br /&gt;
&lt;br /&gt;
include Fox&lt;br /&gt;
&lt;br /&gt;
application = FXApp.new(&amp;quot;Hello&amp;quot;, &amp;quot;FoxTest&amp;quot;)&lt;br /&gt;
main = FXMainWindow.new(application, &amp;quot;Hello&amp;quot;, nil, nil, DECOR_ALL)&lt;br /&gt;
FXButton.new(main, &amp;quot;&amp;amp;Hello, World!&amp;quot;, nil, application, FXApp::ID_QUIT)&lt;br /&gt;
application.create()&lt;br /&gt;
main.show(PLACEMENT_SCREEN)&lt;br /&gt;
application.run()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Qt/Qt4'''==&lt;br /&gt;
&lt;br /&gt;
Qt is one of the leading cross-platform toolkits for creating web-enabled desktop, mobile and embedded GUI applications. It has Intuitive C++ class library. Web-enabled applications can be written once and deployed across desktop, mobile and embedded operating systems without rewriting the source code. It has high runtime performance with portability across desktop and embedded operating systems.&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using Qt'''===&lt;br /&gt;
&lt;br /&gt;
require 'Qt4'&lt;br /&gt;
&lt;br /&gt;
app = Qt::Application.new(ARGV)&lt;br /&gt;
&lt;br /&gt;
hello = Qt::PushButton.new('Hello World!')&lt;br /&gt;
hello.resize(100, 30)&lt;br /&gt;
hello.show()&lt;br /&gt;
&lt;br /&gt;
app.exec()&lt;br /&gt;
&lt;br /&gt;
[[Image:Hello World(1).jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''WxRuby2'''==&lt;br /&gt;
&lt;br /&gt;
WxRuby is an open source GUI toolkit for Ruby programming language. It allows creating cross platform desktop applications. It makes use of the C++ [http://en.wikipedia.org/wiki/ WxWidgetswxWidgets] GUI framework.  WxWidgets is an open source cross platform library in C++ that aids in creating application for Windows, OS X, Linux and UNIX on 32-bit and 64-bit architectures. It binds languages like python, perl, ruby etc. It has several advantages over other ruby GUI toolkits.  Being cross- platform , it has many advanced features with native look and feel. End users do not have to adjust to foreign interface. It is used by many users and actively developed with Unicode support&lt;br /&gt;
&lt;br /&gt;
==='''Sample HelloWorld Program using WxRuby2 '''===&lt;br /&gt;
&lt;br /&gt;
require 'wx'&lt;br /&gt;
 &lt;br /&gt;
 class MyApp &amp;lt; Wx::App&lt;br /&gt;
   def on_init&lt;br /&gt;
     @frame = Wx::Frame.new( nil, -1, &amp;quot;Application&amp;quot; )&lt;br /&gt;
     @frame.show&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 app = MyApp.new&lt;br /&gt;
 app.main_loop&lt;br /&gt;
&lt;br /&gt;
'wx' module is required to load WxRuby library. The class containing all the WxRuby applications must be inherited from the Wx::App class.&lt;br /&gt;
The on_init method is used to create any widget. The widget Frame here has three arguments (parent class, unique ID number, text to be displayed). The 'show' method has to be called for the Frame to be displayed. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm [6]]&lt;br /&gt;
&lt;br /&gt;
==='''Creating Menu'''===&lt;br /&gt;
&lt;br /&gt;
Wx::MenuBar object holds the menu and the Wx::Menu objects. Every menu option has a unique ID number assigned to it and its respective callback function is called every time that option is selected by the user. &lt;br /&gt;
&lt;br /&gt;
Types of ID are -&lt;br /&gt;
&lt;br /&gt;
Wx::ID_ANY -&amp;gt; This ID is used for dummy options when ID is not of significance.&lt;br /&gt;
Wx::ID_EXIT -&amp;gt; Allows user to perform any operation on the Exit option.&lt;br /&gt;
Wx::ID_LOWEST -&amp;gt; If any ID is lesser than the LOWEST, it creates no conflict with internal ID.&lt;br /&gt;
Wx::ID_HIGHEST -&amp;gt; If any ID is higher than the HIGHEST, it creates no conflict with internal ID.&lt;br /&gt;
&lt;br /&gt;
'append' -&amp;gt; It adds a menu item to the menu bar. Usually takes three arguments (ID, text to be displayed, keyboard shortcut, short  &lt;br /&gt;
            description (optional)) . The menu is appended by using two arguments (menu object, name of object)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&lt;br /&gt;
Creating a Help Menu -&lt;br /&gt;
help = Wx::Menu.new&lt;br /&gt;
help.append( Wx::ID_ABOUT, &amp;quot;&amp;amp;About...\tF1&amp;quot;, &amp;quot;Show about dialog&amp;quot; )&lt;br /&gt;
menu.append( help, &amp;quot;&amp;amp;Help&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm [7]]&lt;br /&gt;
&lt;br /&gt;
==='''Adding Status Bar'''===&lt;br /&gt;
&lt;br /&gt;
Status Bar is used to display any description of the option over which the mouse moves. The Status Bar Object can be created and assigned using status_bar attribute. Hence, there is no need for any variable and it can be retrieved anytime. It is generally manipulated as a stack where the displayed message is pushed to the stack and once finished, it is popped out. Top-most is usually displayed and after pop, the original message becomes the top-most.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
status = Wx::StatusBar.new(self)&lt;br /&gt;
status.push_status_text &amp;quot;Status is shown here&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm [8]]&lt;br /&gt;
&lt;br /&gt;
More information and example programs can be obtained from the tutorial [http://wxruby.rubyforge.org/wiki/wiki.pl? [9]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Shoes'''==&lt;br /&gt;
&lt;br /&gt;
It is not designed for serious, large-scale GUI applications. Shoes applications usually tend to be small, useful and clever programs, which can be used for online or offline purposes. The application is very simple with a shallow learning curve. It is the quickest way to create a useful GUI , and it is intuitive to boot.&lt;br /&gt;
&lt;br /&gt;
==='''Sample Hello World Program using Shoes'''===&lt;br /&gt;
&lt;br /&gt;
Shoes.app :width =&amp;gt; 250, :height =&amp;gt; 100 do&lt;br /&gt;
   para &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
The Shoes.app is the method which encapsulates the entire application and it takes width and height, in pixels, as parameters. Inside this method, any options can be set. Here, 'para' is a text container used to display the text &amp;quot;Hello World&amp;quot;. 'para' can also take multiple arguments. Formatting is possible by inserting the format operation even inside the 'para'. It is also possible to include other text containers such as 'title', 'subtitle', 'tagline', 'caption' etc. &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm [10]]&lt;br /&gt;
&lt;br /&gt;
[[Image:Shoes.Hello World.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Stack and Flow''' &lt;br /&gt;
&lt;br /&gt;
Shoes implement what are called 'stack' and 'flow'. Stack, as the name suggests, is used to arrange the GUI tools vertically on top of each other and flow does the same thing, horizontally. It is possible to assign the width for flow. When the limit exceeds, i.e., during overflow, stack creates a scroll bar to move down but flow does not create one to move across. It is also possible to create a Flow of Stacks and a Stack of Flows. The width and height are then defined in terms of % of the portion each flow/stack will take up horizontally.&lt;br /&gt;
 &lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
Shoes.app :width =&amp;gt; 400, :height =&amp;gt; 140 do&lt;br /&gt;
  flow :width =&amp;gt; 250 do&lt;br /&gt;
  button &amp;quot;Button 1&amp;quot;&lt;br /&gt;
  button &amp;quot;Button 2&amp;quot;&lt;br /&gt;
  button &amp;quot;Button 3&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
[[Image:123.jpg]]&lt;br /&gt;
&lt;br /&gt;
Replace 'flow' by 'stack' to get the stack of buttons. By default, the arrangement of the tools is 'flow'.&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm [11]]&lt;br /&gt;
&lt;br /&gt;
Images can be displayed, resized, set as background using 'stack' and 'flow'. It is also possible to provide the URL and the corresponding image is placed in the window.&lt;br /&gt;
&lt;br /&gt;
Example -&lt;br /&gt;
&lt;br /&gt;
stack do&lt;br /&gt;
&lt;br /&gt;
image 'lilies.jpg'&lt;br /&gt;
image 'lilies.jpg', :width =&amp;gt; '150%'&lt;br /&gt;
'background 'background.jpg'' # This has to be provided before all other statements. Otherwise, it overwrites them.&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_1.htm [12]]&lt;br /&gt;
&lt;br /&gt;
Shoes has some advantages and disadvantages. It has good graphics, simple interface, and control at a lower level. It can be used to distribute redistributables, used to have examples available. Disadvantages are-  maintainer AWOL, still rough around the edges since it attempts to support so many platforms. Lacks many of the more robust widgets common in other toolkit&lt;br /&gt;
&lt;br /&gt;
More information and examples about using Shoes GUI Toolkit for Ruby can be found at [http://ruby.about.com/od/shoes/Shoes.htm [13]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Other Ruby GUI toolkits'''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GTK -  Stable, Well Documented, used for [http://en.wikipedia.org/wiki/GNOME Gnome] problems. Requires hefty set of run time libraries.&lt;br /&gt;
 &lt;br /&gt;
FLTK - Ruby/FLTK is a Ruby binding for FLTK. Very fast and lightweight GUI toolkit. Can produce smallest binaries of all free toolkits here. But it is outdated and has unmaintained UTF8 patch and unicode patch.&lt;br /&gt;
&lt;br /&gt;
Ruby-Cocoa bridge - This is an open source project that produces web applications with MAC look and feel by combining features of Ruby and objective C programming languages. But this is not widely used because \RubyCocoa applications are very slow due to the added overhead of object conversion. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= '''Conclusion''' =&lt;br /&gt;
&lt;br /&gt;
= '''External Links''' =&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Window using Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/gi/o.htm?zi=1/XJ&amp;amp;zTi=1&amp;amp;sdn=ruby&amp;amp;cdn=compute&amp;amp;tm=113&amp;amp;f=10&amp;amp;tt=14&amp;amp;bt=0&amp;amp;bts=1&amp;amp;zu=http%3A//www.meshplex.org/wiki/Ruby/Basic_GUI]  Hello World Label in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Dynamic getter and setter in Tk&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] CallBack &lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/] Programming in Ruby Tutorial &lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubyworld.htm] Hello World Program using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/gui/qt/wxrubymenu.htm] Creating Menu using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/wxruby/qt/wxstatusbar.htm] Adding Status Bar using WxRuby&lt;br /&gt;
&lt;br /&gt;
[http://wxruby.rubyforge.org/wiki/wiki.pl?WxRuby_Tutorial] WxRuby tutorial&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes1_2.htm] Hello World Program using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes2.htm] Stack and Flow using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/ss/shoes4_2.htm] Creating Images and Background using Shoes&lt;br /&gt;
&lt;br /&gt;
[http://ruby.about.com/od/shoes/Shoes.htm] Shoes Tutorial&lt;br /&gt;
&lt;br /&gt;
[http://kylecordes.com/2007/ruby-gui-toolkits] ruby GUI toolkit&lt;br /&gt;
&lt;br /&gt;
= '''References''' =&lt;br /&gt;
&lt;br /&gt;
1) [http://pragprog.com/titles/ruby/programming-ruby] Programing Ruby &lt;br /&gt;
&lt;br /&gt;
2) [http://books.google.com/books?id=CyMsvtgnq0QC&amp;amp;dq=Cross-Platform+GUI+Programming+with+wxWidgets&amp;amp;printsec=frontcover&amp;amp;source=bn&amp;amp;hl=en&amp;amp;ei=ls-FTIWIGsWqlAfNj_kQ&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CCcQ6AEwAw#v=onepage&amp;amp;q&amp;amp;f=false] Cross-Platform GUI Programming with wxWidgets&lt;br /&gt;
&lt;br /&gt;
3)[http://www.hanselman.com/blog/TheWeeklySourceCode29RubyAndShoesAndTheFirstRubyVirus.aspx] Ruby Shoes&lt;br /&gt;
&lt;br /&gt;
4)[http://pragprog.com/titles/ctrubyqt/rapid-gui-development-with-qtruby] Rapid GUI Development with QtRuby&lt;br /&gt;
&lt;br /&gt;
5)[http://www.pragprog.com/titles/fxruby/fxruby] Create Lean and Mean FxRuby GUIs&lt;/div&gt;</summary>
		<author><name>Daffodil</name></author>
	</entry>
</feed>