代码之家  ›  专栏  ›  技术社区  ›  ThoKra

WxRuby和RubyMSN

  •  1
  • ThoKra  · 技术社区  · 15 年前

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

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

    Rubymsn想要有一个无穷无尽的循环

    while true
      sleep 1
    end
    

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

    我现在用这个代码作为循环

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

    我让我的窗户工作,主回路做一些事情。但是我不能登录,好像我没有任何循环(从 the tutorial )我只得到一个调试行。但一旦我关上窗户,让无尽的循环完成它的工作,它就像一个魅力。

    有人吗?

    1 回复  |  直到 15 年前
        1
  •  2
  •   Martin DeMello    15 年前

    为我工作。试试这个:复制 minimal 从wxruby分布中采样,并修改 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 目录 极小值 当然,要使REQUEST语句工作的目录。

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