获取"Gtk:ERROR"尝试运行WxRuby



我正在使用Ubuntu 10.04,我试图运行我从这个网站WxRubyWiki复制粘贴的WxRuby示例。我一直在网上寻找帮助,但我找不到任何类似的…

我得到这个错误…

Gtk:ERROR:/build/buildd/gtk+2.0-2.20.1/gtk/gtkwindow.c:6789:IA__gtk_window_present_with_time: assertion failed: (widget->window != NULL)
Aborted

这些是我正在使用的版本…

ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
gem list
...
wxruby (2.0.1 x86-linux)
...

这是我要运行的代码…

require 'rubygems' if RUBY_VERSION < '1.9'
require 'wx'
class EventFrame < Wx::Frame
    def initialize()
        super(nil, -1, "Event Frame")
        @idleCounter = 0
        evt_close {|event| on_close(event)}
        evt_idle {|event| on_idle(event)}
        evt_size {|event| on_size(event)}
        evt_key_down {|event| on_key(event)}
        evt_left_down {|event| on_left_down(event)}
        # You can still process these events, you just need to define a separate callback for middle_down and right_down
        # to process them as separate events
        evt_middle_down {|event| on_middle_down(event)}
        evt_right_down {|event| on_right_down(event)}
        button = Wx::Button.new(self, -1, "Push me")
        evt_button(button.get_id()) {|event| on_button(event)}
        show()
    end
    def message(text, title)
        m = Wx::MessageDialog.new(self, text, title, Wx::OK | Wx::ICON_INFORMATION)
        m.show_modal()
    end
    def on_close(event)
        message("This frame will be closed after you push ok", "Close event")
        #close(true) - Don't call this - it will call on_close again, and your application will be caught in an infinite loop
        # Either call event.skip() to allow the Frame to close, or call destroy(), as follows
        destroy()
    end
    def on_idle(event)
        @idleCounter += 1
        if @idleCounter > 15 # Without the counter to slow this down, Idle events would be firing every second
            message("The system is idle right now", "Idle event")
            @idleCounter = 0
        end
        event.request_more() # You must include this, otherwise the Idle event won't occur again
    end
    def on_size(event)
        size = event.get_size()
        x = size.x
        y = size.y
        message("X = " + x.to_s + ", Y = " + y.to_s, "Size event")
    end
    def on_key(event)
        message("Key pressed", "Key Event")
    end
    def on_left_down(event)
        button = ""
        if event.left_down()
            button = "Left"
        end
        message(button + " button was clicked", "Mouse event")
    end
    def on_middle_down(event)
        # This method hasn't been implemented yet...
        #if event.middle_down()
           #button = "Middle"
        #end
        message("Middle button was clicked", "Mouse event")
    end
    def on_right_down(event)
        # This method hasn't been implemented yet...
        #if event.right_down()
            #button = "Right"
        #end
        message("Right button was clicked", "Mouse event")
    end
    def on_button(event)
        message("Button was clicked", "Button event")
    end
end
class MyApp < Wx::App
    def on_init
        EventFrame.new()
    end
end
MyApp.new.main_loop

提前感谢!

更多的是对GTK+2/wx/wxRuby如何工作的理解。实际上,上面的代码在我用来测试它的虚拟机中的配置上不起作用,也不能在我的开发机器的Ubuntu 11.10 x86_64(带有1000Hz内核编译选项和ruby 1.9.3 p21)上运行。

当on_size事件在帧创建过程中触发时,GTK+2错误发生。创建尚未完成,因此消息框当时没有父窗体。您可以通过注释(in defon_size (event):

)来测试这一点。
message("X = " + x.to_s + ", Y = " + y.to_s, "Size event")

和尝试:

puts "Size event: X = #{x}, Y = #{y}"

查看标准输出的事件详细信息。您将注意到在创建过程中触发了两个事件;一个初始大小事件和一个调整大小事件

另一个警告是将Unity锁定在系统中的空闲循环。您可以通过更改以下代码来测试空闲事件是否在没有锁定的情况下发生:

:
create_status_bar(2)
self.status_text = "Welcome to wxRuby!"

then in idle_event:

def on_idle(event)
  @idleCounter += 1
  #if @idleCounter > 15 # Without the counter to slow this down, Idle events would be firing every second
  #    message("The system is idle right now", "Idle event")
  #    @idleCounter = 0
  #end
  set_status_text @idleCounter.to_s, 1
  event.request_more() # You must include this, otherwise the Idle event won't occur again
end

关于代码的最后一个警告是,您可能会注意到您没有看到键或鼠标按下事件创建它们的消息框。这是因为按钮控件填充了客户端区域,并捕获了键和按钮的框架事件。如果你在应用程序运行时调整帧的大小,默认情况下按钮不会随之调整大小(GTK+2平台)。如果在框架客户端区域内单击,而不是在按钮上单击,则会看到鼠标事件。

祝你好运

此修复并在ubuntu 11.10中工作:)

相关内容

  • 没有找到相关文章

最新更新