Total Pageviews

Wednesday 16 April 2014

创建ruby程序的图形化工具-shoes

a tiny graphical app kit for ruby
Shoes is the best little DSL for cross-platform GUI programming there is. It feels like real Ruby, rather than just another C++ library wrapper. If Gtk or wxWidgets is Rails, Shoes is Sinatra.

Let me tell you a story about Shoes

Way way back in the day, there was a guy named _why. He created a project known as Hackety Hack to teach programming to everyone. In order to reach all corners of the earth, _why decided to make Hackety Hack work on Windows, Mac OS X, and Linux. This was a lot of work, and so _why decided to share his toolkit with the world. Thus, Shoes was born.
Everybody loved Shoes and many apps were made. But, one day, _why left. In his memory, Team Shoes assembled, and carried on making Shoes. They released Shoes 3 in late summer 2010.

Attention: Development moved to shoes4

Due to various issues (including compilation/release, stability) with this shoes implementation development moved on to shoes4. Shoes4 is a complete all Ruby rewrite of shoes. It's goal is to be as close to 100% backwards compatible as it can get e.g. it implements the same DSL.
So what does that mean? Well we accept pull requests but are not actively developing/releasing this shoes version. Our development efforts are now concentrated on shoes4, which is shaping up to become the new default implementation. It is already quite far and a lot of things already work.

So what do these Shoes look like?

Here's a little Shoes app. It's a stopwatch!
Shoes.app height: 150, width: 250 do
  background rgb(240, 250, 208)
  stack margin: 10 do
    button "Start" do
      @time = Time.now
      @label.replace "Stop watch started at #@time"
    end
    button "Stop" do
      @label.replace "Stopped, ", strong("#{Time.now - @time}"), " seconds elapsed."
    end
    @label = para "Press ", strong("start"), " to begin timing."
  end
end
Here's what it looks like:
shoes timer
Pretty simple! For more samples, the manual, and a free book, check out the Shoes website.

Using Shoes

If you'd like to use Shoes to develop some apps... awesome! It's super easy: Just go to the downloads page on the Shoes website and download a copy of Shoes for your platform. Mac OSX, Windows, and Linux supported!
After you install Shoes, run it! You'll get a window like this:
shoes main window
You can then open any .rb file with Shoes code inside by choosing "Open an App." It'll open it up and run it, right away.
Once you're happy with your app, you can choose "Package an App" to wrap up your app as a .exe, .app, or a .run. Then you can share it with someone without a pair of Shoes to call their own.

Making your own Shoes

You can make your own pair of Shoes with a little bit of elbow grease. Since there are different instructions on each platform, we've got a page up on the Shoes development wiki about it. It's right here.

Shoes Around the Web

If you want to keep up to date with what's going on with Shoes, you can find us in various places:
from https://github.com/shoes/shoes