2007-09-11
穿鞋上路
关键字: Shoes
Shoes是Ruby的一个简单的桌面程序库
下载Shoes,将shoes.exe加入path
看看Hello World例子hello.rb:
运行shoes hello.rb即可
再看看自带的计算器的例子:
用Block、Closure的方式来开发桌面程序,代码非常的清晰简洁
Shoes目前支持OS X、XP、Vista、Debian、Ubuntu,跨平台做的也非常不错
下载Shoes,将shoes.exe加入path
看看Hello World例子hello.rb:
Shoes.app do button "Press Me" do alert "Hello Shoes!" end end
运行shoes hello.rb即可
再看看自带的计算器的例子:
class Calc
def initialize
@number = 0
@previous = nil
@op = nil
end
def to_s
@number.to_s
end
(0..9).each do |n|
define_method "press_#{n}" do
@number = @number.to_i * 10 + n
end
end
def press_clear
@number = 0
end
{'add' => '+', 'sub' => '-', 'times' => '*', 'div' => '/'}.each do |meth, op|
define_method "press_#{meth}" do
if @op
press_equals
end
@op = op
@previous, @number = @number, nil
end
end
def press_equals
@number = @previous.send(@op, @number.to_i)
@op = nil
end
end
number_field = nil
number = Calc.new
Shoes.app :height => 250, :width => 200, :resizable => false do
background "#EEC".."#996", :radius => 5,
:top => 2, :left => 2, :width => -4, :height => -4
stack :margin => 4 do
stack :margin => 8 do
number_field = text "<b>#{number}</b>"
end
flow :width => 218, :margin => 4 do
%w(7 8 9 / 4 5 6 * 1 2 3 - 0 Clr = +).each do |btn|
button btn, :width => 46, :height => 46 do
method = case btn
when /[0-9]/: 'press_'+btn
when 'Clr': 'press_clear'
when '=': 'press_equals'
when '+': 'press_add'
when '-': 'press_sub'
when '*': 'press_times'
when '/': 'press_div'
end
number.send(method)
number_field.replace "<b>#{number} </b>"
end
end
end
end
end
用Block、Closure的方式来开发桌面程序,代码非常的清晰简洁
Shoes目前支持OS X、XP、Vista、Debian、Ubuntu,跨平台做的也非常不错
发表评论
- 浏览: 723134 次
- 性别:

- 来自: BJ

- 详细资料
搜索本博客
我的相册
screenshot
共 1 张
共 1 张
最近加入圈子
最新评论
-
Why OO sucks
看成去QQ SUCK 了
-- by xhanxhanxhan -
Rails的富文本编辑器插件 ...
有没有那个像textmate那种语法高亮的富文本编辑器?
-- by zllicho -
翻译www.djangobook.com之 ...
weiertzw 写道 1. >>> from django. ...
-- by chenjihua75 -
PHP、CakePHP哪凉快哪呆 ...
这孩子被java毒害太深。。。跳出java,你会发现外面的世界真的很大。
-- by woodless -
学习svn命令
只会用 apt-get 不是好孩子。
-- by smartly






评论排行榜