Day of Ruby (Part 3)

May 20th, 2009

Due to difficulties getting Cucumber working on three different operating systems and various versions of Ruby gems, the next two sections were rather accelerated.

The next topic that Cory discussed involved creating client applications with a basic UI tool kit called Shoes.

Three shoe applications were shown: a simple button click application, a simple Hello World application using a stack and a more complicated binary clock.

Here’s the source code for the Hello World application using a stack. Stacks are used to organized layouts. In Java AWT (abstract window toolkit) terms, it is similar to a panel. It servers as a container that holds UI components and displays them by specified layout.

File: layout.rb

Shoes.app do

  background '#EFC'
  border 'BE8', :strokewidth => 6

  stack(:margin => 12) do
    para 'Enter your name'

    flow do
      @name = edit_line
      @ok = button 'OK'
    end
  end

  @ok.click do
    @name.text = "Hello #{@name.text}"
  end

end

Executing this application using Shoooes displays (without the name Joe pre-filled):

shoooes_20090520

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>