0

私は 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

前もって感謝します!

4

2 に答える 2

1

GTK + 2 / wx/wxRubyがどのように機能するかをより深く理解しています。現状では、上記のコードは、これをテストするように設定したVirtual Boxマシンの構成でも、1000Hzカーネルコンパイルオプションとruby1.9.3p21を備えた開発マシンのUbuntu11.10x86_64でも機能しません。

GTK + 2エラーは、フレームの作成中にon_sizeイベントが発生したときに発生します。作成はまだ完了していないため、その時点でメッセージボックスには親がありません。コメントアウトすることでこれをテストできます(def on_size(event):

message("X = " + x.to_s + ", Y = " + y.to_s, "Size event")

と試してみてください:

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

標準出力でイベントの詳細を確認します。作成中に2つのイベントが発生することに気付くでしょう。初期サイズイベントとサイズ変更イベント

もう1つの注意点は、Unityをシステムにロックするアイドルループです。次のようにコードを変更することで、ロックアップなしでアイドルイベントが発生していることをテストできます。

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プラットフォーム)。次に、フレームクライアント領域内をクリックし、ボタンをクリックしないと、マウスイベントが表示されます。

幸運を !

于 2012-02-13T18:27:04.400 に答える
0

これは修正され、ubuntu 11.10で動作します:)

于 2011-12-06T23:51:27.267 に答える