我正在使用Ubuntu10.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提前感谢!
发布于 2011-12-07 07:51:27
这个问题已经修复并在ubuntu 11.10中运行:)
发布于 2012-02-14 02:27:04
它更多的是理解GTK+2/wx/wxRuby是如何工作的。如上所述,上面的代码既不能在我设置用于测试的Virtual Box机器上运行,也不能在我的开发机的带有1000‘s内核编译选项和Ruby1.9.3 p21的Ubuntu11.10 x86_64上运行。
当在帧创建过程中激发on_size事件时,将发生GTK+2错误。创建尚未完成,因此消息框此时没有父级。可以通过注释掉(在def on_size(Event)中)来测试这一点:
message("X = " + x.to_s + ", Y = " + y.to_s, "Size event")并尝试:
puts "Size event: X = #{x}, Y = #{y}"查看标准输出上的事件详细信息。您将注意到在创建过程中触发了两个事件:初始大小事件和调整大小事件
另一个警告是空闲循环,它会锁定Unity o my system。您可以通过如下所示更改代码来测试idle事件是否在没有锁定的情况下发生:
在def initialize中,在show()之前添加以下内容:
create_status_bar(2)
self.status_text = "Welcome to wxRuby!"然后在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 platform)。如果您随后在frame客户端区内单击,但没有单击按钮,您将看到鼠标事件。
祝你好运!
https://stackoverflow.com/questions/7418972
复制相似问题