From: Masao Mutoh Date: 2002-12-03T20:31:46+09:00 Subject: [ruby-list:36653] Re: Gtk.main むとうです。 2点ほど訂正です(^^;)。 On Tue, 3 Dec 2002 20:27:16 +0900 Masao Mutoh wrote: > むとうです。 > > On Tue, 3 Dec 2002 17:22:32 +0900 > TOYOFUKU Chikanobu wrote: > > > 豊福です。 > > > > なかださん > > > Gtk.mainを同時に二つは無理なのでは。こんなメッセージが怒涛のよ > > > うに出てきます。 > > > GLib-WARNING **: g_main_iterate(): main loop already active in another thread > > > > 一応 kill しているつもりなのですがやり方まずいですかね。 > > なかださんがすでにご指摘になっていますが、メインループ(Gtk.main)を > 別のスレッドで複数起こすというのはとってもマズイ気が...。 > > > やりたいことは重い処理をしている間ダイアログを出して待たせて > > (「重い処理中断」ボタンもつける)、ウィンドウが expose され > > たときのために再描画もさせたいということなのですがどのように > > 書くのがよいでしょうか。 > > 以下のサンプルは参考になりますでしょうか。 > > -------------------- > require 'gtk' > #require 'gtk2' > #Gtk.init > > start_button = Gtk::Button.new("start") > start_button.signal_connect("clicked") do > unless @th > @th = Thread.new { #ここに思い処理を書きます。 思い→重いですね(^^;) > (0...10).each { |cnt| > sleep(1) > puts "cnt = #{cnt}\n" > cnt += 1 > } > puts "finished" > @th = nil > } > end > end > stop_button = Gtk::Button.new("stop") > stop_button.signal_connect("clicked") do > if @th > @th.kill > puts "killed" > @th = nil > end > end > > box = Gtk::VBox.new.add(start_button).add(stop_button) > Gtk::Window.new.add(box).show_all > > Gtk.main > -------------------- > ダイアログを表示してから待たせておくにはGtk.main, Gtk.main_quitを > ネストして使います。 > こちらは、手前味噌ですが、 > http://www.sowhat.com/homepage/tips/gtk_dialog.html#sec:2 > を参考にしてみてください。 http://home2.highway.ne.jp/mutoh/tips/gtk_dialog.html#sec:2 の間違いです(^^;)。 > > 蛇足ですが、 > 最初の2つのコメントを外して1行目をコメントアウト > するとRuby/GTK2で動作します。 > > それでは。 > -- > .:% Masao Mutoh > > -- .:% Masao Mutoh