1. Home
  2. Computing & Technology
  3. Ruby

How Can Shoes Have Buttons?

By Amanda & Michael Morin, About.com

4 of 4

A Graphical 'top' Frontend

A button can be used to grab text from an external command and display it as a para. The top command on Linux is used to show the CPU and memory utilization of all the processes running on the system. If you're not using Linux, you can replace the top command with any other command (including one of your Ruby scripts) to be displayed in the window.

The only thing different about this example is the font settings for the para. This is for two reasons. Firstly, a mono-space font must be used or the table displayed by the top command won't be formatted correctly. Secondly, a smaller font must be used or it won't all fit in the window.

Shoes.app :width => 600, :height => 400 do
  stack do
    button "What's eat up all of my memory?" do
      @p.clear do
        para `top -b -n1`, :font => 'Cou rier 12px'
      end
    end

    @p = flow
  end
end
Explore Ruby
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Ruby
  4. GUI
  5. Shoes
  6. A Graphical 'top' Frontend

©2009 About.com, a part of The New York Times Company.

All rights reserved.