Odors from Shoes Curious in OS X 10.4

January 10, 2008. Filed under ruby 4 shoes 2

Just a few days ago, Why the Lucky Stiff put out a blog post about the first named edition of Shoes, and I am pretty excited about it. Despite not being an avid Ruby hacker, I have to admit, I like Shoes a lot. I genuinely enjoy making simple little applications in Shoes.

Thats why, with the release of Shoes Curious, I decided to write another program using Shoes and see how they are doing.

(ed note: writing about both Why and Shoes screws with my mind. Why becomes both adjective and noun.'Thats why!' could be a surprised proclimation upon seeing Why out in public. Or it might be the beginning of a dry and poorly written sentence explaining the release of a new version of Shoes. Shoes is... are... is equally problematic.)

I am writing a quick little application that I cleverly entitled The Lazy Internet that will collect links when I am away from an internet connection, and then download them when it finds an internet connection.

It is a simple tool, but one that I occasionally wish I had during my days working without an internet connection.

That said Shoes development on OS X is still fraught with peril. (I am still running OSX 10.4, which may or may not be part of the issue.) The key problem is that running the same Shoes program with the same Shoes interpreter can yield wildly different results.

Here are a few images that show varying results I have gotten from running the same code. (You can find the code under the pictures, if I am drowning in a soup I lovingly crafted myself, please let me know!)

How its supposed to look

A picture of the correct GUI appearance for The Lazy Internet

Please. No.

A picture of the correct GUI appearance for The Lazy Internet

Damnit all to hell

A picture of the correct GUI appearance for The Lazy Internet

I feel somewhat violated

A picture of the correct GUI appearance for The Lazy Internet

The source

QUEUED = []
DOWNLOADING = []
DOWNLOADED = []
BANDWIDTH_THROTTLE = 50
Shoes.app :title => "The Lazy Internet", 
  :width => 800, :height => 400 do
  background "071A17"
  stack :width => 780, :margin => 20 do
    flow :width => 1.0, :height => 40 do
      background "#071A17"
      @url = edit_line :width => 500, :margin_right => 50, :text => "http://"
      button "enqueue", :width => 100 do
        enqueue(@url.text)
        @url.text = "http://"
      end
    end
    stack :width => 1.0, :height => 100 do
      background "#A69561"
      @queued = para "queued downloads"
    end
    stack :width => 1.0, :height => 100 do
      background "#665C2C"
      @downloading = para "in progress downloads"
    end
    stack :width => 1.0, :height => 100 do
      background "#332E1E"
      @downloaded = para "finished downloads"
    end
  end
  def redraw_queued
    @queued.replace *(QUEUED.map { |url| url + "\n" })
  end
  def redraw_downloading
    @downloading.replace *(DOWNLOADING.map { |download| download + "\n" })
  end
  def redraw_downloaded
    @downloaded.replace *(DOWNLOADED.map { |download| download + "\n" })
  end
  def enqueue(url)
    QUEUED << url
    redraw_queued
  end
  def download
    dl = QUEUED[0]
    if dl != nil
      DOWNLOADING << dl
      QUEUED.delete dl
      redraw_queued
      redraw_downloading
    end
  end
  def complete(dl)
    DOWNLOADING.delete dl
    DOWNLOADED << dl
    redraw_downloaded
  end
  animate(8) do
    download
  end
end