我目前正在使用wxRuby和RubyMSN来学习如何编写桌面程序。我知道这是一项艰巨的任务,而不仅仅是装一个记事本等等,但我需要一个比记事本更大的任务。
我现在自己设法使用它们,但我不能让它们一起工作。问题出在循环上。
RubyMSN想要有一个无尽的循环,比如
while true
sleep 1
end或者使用GUI的主循环之类的
我目前有以下代码作为循环
TheApp.new.main_loop()
while true
sleep 1
end我让我的窗口正常工作,并且main_loop也在做一些事情。但是我无法登录,就像我没有任何循环(从the tutorial),我只得到一个调试行。但是,只要我关闭窗口,让无限的循环完成它的工作,它就像一个护身符一样工作。
有人吗?
发布于 2009-12-06 01:28:55
对我很管用。尝试这样做:从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当然,您需要对minimal目录内的msn目录进行符号链接,才能使require语句工作。
您不需要while true {sleep 1}循环;这只是为了防止程序退出,这样您的MSN线程就可以继续运行。wx主循环也实现了同样的目的。
https://stackoverflow.com/questions/1852273
复制相似问题