【问题标题】:wxruby and rubymsnwxruby 和 ruby​​msn
【发布时间】:2009-12-05 14:01:17
【问题描述】:

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

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

RubyMSN 想要像这样的无限循环

while true
  sleep 1
end

或者使用 GUI 的主循环之类的东西

我目前将此代码作为循环

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

我的窗口正在工作,而 main_loop 正在做一些事情。但我无法登录,就像我没有任何循环(来自the tutorial),我只有一条调试线。但是一旦我关闭窗口并让无限循环完成它的工作,它就像一个魅力。

有人吗?

【问题讨论】:

    标签: ruby wxruby


    【解决方案1】:

    为我工作。试试这个:从 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 主循环完成同样的目的。

    【讨论】:

    • 似乎没有更进一步。这是我现在的代码:pastie.org/729297 它仍然在 "--> Sent: "VER 1 MSNP9 CVR0\r\n" " 之后停止
    • 可能是平台问题。你的代码在我的盒子(archlinux 上的 ruby​​ 1.9.1)上为我高兴地工作(在有和没有 wx 的情况下做了同样的事情)
    • 已更新至 ruby​​ 1.9.1 和 wxruby19,现在可以使用了 :) 谢谢 :)
    猜你喜欢
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多