wxruby和rubymsn

时间:2009-12-05 14:01:18

标签: ruby wxruby

我目前正在玩wxRuby和RubyMSN来学习编写桌面程序。我知道这是一项艰巨的任务,而不仅仅是装箱记事本等,但我需要一个比记事本更大的任务。

我现在设法让他们自己使用它们,但我不能让它们一起工作。问题是循环。

RubyMSN希望拥有像

这样的无限循环
while true
  sleep 1
end

或使用GUI的主循环或其他东西

我目前将此代码作为循环

TheApp.new.main_loop()
while true
  sleep 1
end

我的窗口工作,main_loop做了一些事情。但是我无法登录,就像我没有任何循环(来自the tutorial),我只得到一个调试行。但是当我关闭窗户并让无限循环完成它的工作时,它就像一个魅力。

有人吗?

1 个答案:

答案 0 :(得分:2)

为我工作。试试这个:从wxruby发行版中复制minimal示例,并修改minimal.rb,以便在wx主循环之前启动你的msn线程:

require 'msn/msn'

conn = MSNConnection.new("rubybot@channelwood.org", "secretpassword123")
conn.start

# Wx::App is the container class for any wxruby app. To start an
# application, either define a subclass of Wx::App, create an instance,
# and call its main_loop method, OR, simply call the Wx::App.run class
# method, as shown here.
Wx::App.run do 
  self.app_name = 'Minimal'
  frame = MinimalFrame.new("Minimal wxRuby App")
  frame.show
end

当然,您需要对msn目录中的minimal目录进行符号链接以使require语句正常工作。

您不需要while true {sleep 1}循环;这只是为了防止程序退出,以便你的msn线程可以继续运行。 wx主循环实现了相同的目的。