Subscribe to the MPC blog rss feed feed-icon-14x14
 

Using Shoes To Write A Platform Independent Desktop Client

Posted on 04:42AM on 09/27/2008
Tags: ruby, shoes

Lately I've been looking for ways to track my billable time. I stumbled upon Slim Timer a while back and the more I play with it, the more I like using it. Thanks to Richard White for making it available.

One small problem I have with it, though, is that I don't enjoy using a web interface for tracking my time. I don't know why, it just seems to break my workflow. According to the site, there is a Windows client called Bubbles that can be used; however, I run Linux, not Windows, so that option is out.

I had some free time, so I got to thinking about how I could easily write a desktop application that would run on a variety of platforms to interact with the Slim Timer API. My first thought was a Java Swing client, but that seemed inelegant.

Then I remembered Shoes. I had heard about Shoes a while back on Ruby Inside, but had not given it much thought.

On further investigation, though, it seemed like Shoes might be a good solution. A Shoes application is written using Ruby and can be compiled to run in Linux, Mac OS, and Windows. This is great in my opinion since I like Ruby and you never know when someone else on a different platform might be able to use the application

Another really cool feature of Shoes it that although you create desktop applications with it, in many ways it's a lot like creating a web application. Shoes has the concept of links that point to within (or without) the application. Shoes also has the concept of styles. Using styles is similar to styling HTML.

So far I've build a prototype of my Slim Timer On Shoes that works on Windows, Mac and Linux. It will likely take some time since I need to learn more about Shoes as I go!

Here's a very simple example of a Shoes application:

#SlimTimerOnShoes.rb
Shoes.setup do
  gem 'slimtimer4r'
end
$:.push(File.join(File.dirname(__FILE__), "lib"))

#loads a variety of additional helper classes - not shown
require 'loader'

class SlimTimerOnShoes < Shoes
 
  #'urls' within the application
  url '/', :index
  url '/task/new', :create_task
  url '/task/stop/(\\d+)', :stop_task
  url '/task/complete/(\\d+)', :complete_task
  url '/task/show/(\\d+)', :show_task
  
  @@actions = {
    :main => MainAction.new,
    :show => ShowAction.new,
    :configure => ConfigureAction.new,
    :complete => CompleteAction.new,
    :start => StartAction.new,
    :stop => StopAction.new,
    :create => CreateAction.new
  }
  
  def index
    Settings.configured? ? show_index : configure
  end
  
  def show_index
    run_action(:main)
  end
  
  def configure
    LoggerFacade.log("Application not configured. Bringing up configuration screen.", LoggerFacade::INFO)
    run_action(:configure)
  end
  
  def complete_task(task_id)
    run_action(:complete, task_id)
  end
  
  def start_task(task)
    run_action(:start, task)
  end
  
  def stop_task(task_id)
    run_action(:stop, task_id)
  end
  
  def create_task
    run_action(:create)
  end
  
  def show_task(task_id)
    run_action(:show, task_id)
  end
  
  private
  
  def run_action(action, *args)
    a = @@actions[action]
    a.app = self
    a.execute(*args)
  end
  
end

Shoes.app :title => "SlimTimer On Shoes", :width => 500, :height => 500, :resizable => true

2 Comments (Show) (Comments are closed for this post)

Please note that I am currently unavailable for any large, long term work.