Shoes – a ruby GUI toolkit

Friday, April 4th, 2008

Ruby is not only showing its power in Rails but also applications like “shoes” ,”shoes” is graphics and windowing toolkit. It will run on all platforms like Windows, Mac OS X and Linux , which help you to build desktop applications easily.Its creating GUI components some what similar to web applications.shoes library making our task easier by providing lots of methods to build a desktop item.Ruby Shoes is written in C and uses Ruby native extensions to allow interaction with Ruby code.
First of all you need to install ruby “shoes” ,available here download

1.Download source

2.Extract(unzip)

3.Install

Now run

$ shoes

Which will give take you to a graphical mode there you can choose your ruby file for shoes.Or run your shoes file by

$ shoes <filename.rb>

Here is examples to show the simplicity and elegance of ruby shoes.Start with a small ones

Example for a button click
Shoes.app {
button("Hello") { alert("You have clicked on hello") }
}

example for drop down box
shape = nil
Shoes.app do
shape = list_box :items => ["Square", "Oval", "Rectangle"]
button "Report" do
Shoes.p [shape.text]
end
end

You can see all the methods available for shoes “CLICK ME” or type on command line
$ shoes --manual - you can see a helper.

Ideal example to see the power of shoes is given below , in those few lines its doing a big job !!
Shoes.app :width => 500, :height => 100, :margin => 10 do
def answer(v)
@answer.replace v.inspect
end
button "Ask" do
answer ask("Enter your name")
end
button "Confirm" do
answer confirm("Like to proceed??")
end
button "Open File" do
answer ask_open_file
end
button "Save File" do
answer ask_save_file
end
button "Select Your Color" do
answer ask_color("Select yours")
end
@answer = para "Answers appear here"
end

Print

Anvil: GUI development Framework in Ruby

Monday, January 14th, 2008

Recently i have done a small experimentation on Anvil – A ruby framework to create GUI based applications.The back bone of Anvil is WxRuby. At a glance i thought it will be very easy, so decided to to give a try :)

sudo apt-get install anvil

This installs anvil and all the other required gems. Then running the command

anvil my_editor

Creates a project my_editor. Anvil follows MVC architecture. Browsing through the new project’s folder structure, we can see folders and files for inserting our Models, Views and controllers.

cd my_editor
anvil

A window pops up..! Now we just need to add GUI components as we require, in the respective views and controllers.

I was very excited to see the ease with which i could build an GUI application with Anvil but i couldn’t finish by the end of the day as i had wished. I was getting some errors while using “button” method. It was saying NoMethod error :( . But couldn’t find any error that time & tried a lot then i came to know that the WxRuby that got installed was the latest version and in documentation of Anvil was with an older version. Then i tried with “evt_button” of the new version and it worked.

I found Anvil and WxRuby very useful in building GUI applications.

Print