The Viamentis Blog

Curious About Everything

The Viamentis Blog header image 1

Shoes - a ruby GUI toolkit

April 4th, 2008 · Posted by divya · 1 Comment

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

→ 1 CommentTags:··

Unni’s article gets featured in LinuxGazette

April 4th, 2008 · Posted by Vamsee · No Comments

As you might notice, my blogging has gone down a bit - and you might have also observed that there are lot more posts by Unni & Divya, my colleagues. Chalk that up to new projects, and lots of higher priority items. I’m slowly coming to realize, running an actual business is not so easy as they make it sound. But, it’s an amazing ride, for sure.

Coming to the point, I encourage our developers to take some time off at least once every week and do something they think is fun. Yes, it’s very much based on Google’s 20% time, but we try to make it a group event rather than an individual one. And Unni comes up with some pretty fun projects. One such project, which he blogged about here, was recently featured in LinuxGazette. He might be too modest to post about it here, so I’m doing it for him :) (check out the editor’s comment - pretty funny).

Good stuff guys, keep going.

→ No CommentsTags:·

Scriptaculous - a Javascript library

March 14th, 2008 · Posted by divya · No Comments

Scriptaculous is a Javascript library for providing Web 2.0 effects in web pages. Scriptaculous is built on top of the Prototype library(prototype.js).Effects provided by scriptaculous include Visual effects like Appear,Higlight, Shake etc of DOM elements. It also provides advanced functions like Slider, Drag & Drop and Autocomplete for text boxes.

A drop and drop shopping cart example can be see here

Scriptaculous can be downloaded from here

Download and link the scriptaculouos.js file to your html page. Using scriptaculous effects is very easy

Example:

Effect.Appear('element_id'); (element_id is the id of a DOM element)

Similar examples with demo can be seen here

Scriptaculous library by itself is simple, but Ruby on Rails makes it even simpler. Rails has wrappers around scriptacuolus methods.

Examples:
i :onclick => visual_effect(:highlight, 'msg', :duration => 1.0)

ii. <%= draggable_element 'idOne', :revert => true %>

→ No CommentsTags:···

JuggerNaut - Push Server for Rails

March 14th, 2008 · Posted by unni · No Comments

When we build a web page that contains data which gets updated very frequently (eg: Share price of Google, or score of a live cricket match), it would be extremely useful if we could ‘push’ data into the webpage, without the user having to ‘pull’ the data by reloading the page or requesting explicitly.

Juggernaut is a Ruby on Rails plugin that helps to implement this ‘push’ mechanism. Comet is the widely accepted technology for doing the same. Juggernaut claims to have a few advantages over comet. Details can be found here.

Apart from the Rails application, juggernaut runs a separate push server, which maintains persistent socket connection with all connected clients. Ruby app sends data to this push server, which pushes the data to all connected clients.

Juggernaut initiates a flash xmlsocket between server and browser allowing real time communication between the two. The open socket connection allows the server to ‘push’ base64 encoded javascript to the browser which is subsequently decoded and evaluated.

juggernaut.jpg

Installation and configuration of Juggernaut are explained in detail in the Juggrenaut page.

I tried to build a simple Juggernaut-Rails application that would push the current playing song name in my system(rails app runs on the same machine). It was fairly simple, current playing song name was extracted using the Dbus interface of Rhythmbox music player (More details on this can be found in my article on IPC with Dbus. Once the songname was obtained, pushing it to the browsers required only the following code in the controller:

 render :juggernaut do |page|
      page.replace_html 'song_name', "<b> #{song_name} </b>"
 end

→ No CommentsTags: