From: Joe V. D. <joe...@gm...> - 2006-01-28 02:00:36
|
require 'gtk2' Gdk::Threads::init Gtk::init def show_dialog window, text dialog =3D Gtk::MessageDialog.new window, 0, Gtk::MessageDialog::INFO, Gtk::MessageDialog::BUTTONS_CLOSE, text dialog.run dialog.destroy end window =3D Gtk::Window.new window.set_default_size 300, 300 button =3D Gtk::Button.new("Hm.. not much going on here") button.signal_connect("clicked") { show_dialog window, "from button click" = } window << button window.signal_connect("delete-event") { Gtk::main_quit } window.show_all Thread.new do sleep 5 puts "entering critical part here" Gdk::Threads::synchronize do show_dialog window, text, "from thread" end puts "leaving critical part here" end Gtk::main I want to show dialog boxes on a window from a different thread. Is that possible? The above program freezes when the thread tries to show the dialog. I can't seem to get it to work with the Gdk::Thread stuff or without. Thanks, Joe |
From: Joe V. D. <joe...@gm...> - 2006-01-28 02:12:20
|
On 1/27/06, Joe Van Dyk <joe...@gm...> wrote: > require 'gtk2' > > Gdk::Threads::init > Gtk::init > > def show_dialog window, text > dialog =3D Gtk::MessageDialog.new window, > 0, > Gtk::MessageDialog::INFO, > Gtk::MessageDialog::BUTTONS_CLOSE, > text > dialog.run > dialog.destroy > end > > window =3D Gtk::Window.new > window.set_default_size 300, 300 > button =3D Gtk::Button.new("Hm.. not much going on here") > button.signal_connect("clicked") { show_dialog window, "from button click= " } > window << button > > window.signal_connect("delete-event") { Gtk::main_quit } > window.show_all > > Thread.new do > sleep 5 > puts "entering critical part here" > Gdk::Threads::synchronize do > show_dialog window, text, "from thread" doh, that should've been show_dialog window, "from thread" This example now seems to work. But my real application is freezing when the thread tries to tell a dialog window to open. Hm.... > end > puts "leaving critical part here" > end > > Gtk::main > > > > > I want to show dialog boxes on a window from a different thread. Is > that possible? The above program freezes when the thread tries to > show the dialog. I can't seem to get it to work with the Gdk::Thread > stuff or without. > > Thanks, > Joe > |
From: Joe V. D. <joe...@gm...> - 2006-01-28 02:14:56
|
On 1/27/06, Joe Van Dyk <joe...@gm...> wrote: > On 1/27/06, Joe Van Dyk <joe...@gm...> wrote: > > require 'gtk2' > > > > Gdk::Threads::init > > Gtk::init > > > > def show_dialog window, text > > dialog =3D Gtk::MessageDialog.new window, > > 0, > > Gtk::MessageDialog::INFO, > > Gtk::MessageDialog::BUTTONS_CLOSE, > > text > > dialog.run > > dialog.destroy > > end > > > > window =3D Gtk::Window.new > > window.set_default_size 300, 300 > > button =3D Gtk::Button.new("Hm.. not much going on here") > > button.signal_connect("clicked") { show_dialog window, "from button cli= ck" } > > window << button > > > > window.signal_connect("delete-event") { Gtk::main_quit } > > window.show_all > > > > Thread.new do > > sleep 5 > > puts "entering critical part here" > > Gdk::Threads::synchronize do > > show_dialog window, text, "from thread" > > doh, that should've been > show_dialog window, "from thread" > > This example now seems to work. But my real application is freezing > when the thread tries to tell a dialog window to open. > > Hm.... Here's the error that I get when I try to show the dialog box in my applica= tion: GLib-WARNING **:g_main_context_prepare(): main loop already active in another thread |
From: Joe V. D. <joe...@gm...> - 2006-01-28 02:25:41
|
On 1/27/06, Joe Van Dyk <joe...@gm...> wrote: > On 1/27/06, Joe Van Dyk <joe...@gm...> wrote: > > On 1/27/06, Joe Van Dyk <joe...@gm...> wrote: > > > require 'gtk2' > > > > > > Gdk::Threads::init > > > Gtk::init > > > > > > def show_dialog window, text > > > dialog =3D Gtk::MessageDialog.new window, > > > 0, > > > Gtk::MessageDialog::INFO, > > > Gtk::MessageDialog::BUTTONS_CLOSE= , > > > text > > > dialog.run > > > dialog.destroy > > > end > > > > > > window =3D Gtk::Window.new > > > window.set_default_size 300, 300 > > > button =3D Gtk::Button.new("Hm.. not much going on here") > > > button.signal_connect("clicked") { show_dialog window, "from button c= lick" } > > > window << button > > > > > > window.signal_connect("delete-event") { Gtk::main_quit } > > > window.show_all > > > > > > Thread.new do > > > sleep 5 > > > puts "entering critical part here" > > > Gdk::Threads::synchronize do > > > show_dialog window, text, "from thread" > > > > doh, that should've been > > show_dialog window, "from thread" > > > > This example now seems to work. But my real application is freezing > > when the thread tries to tell a dialog window to open. > > > > Hm.... > > Here's the error that I get when I try to show the dialog box in my appli= cation: > > GLib-WARNING **:g_main_context_prepare(): main loop already active > in another thread > Hm... if I add Gtk::timeout_add(1) do true end right before the Gtk::main call, the following test program crashes when I try to have a separate thread show a dialog box: require 'gtk2' Gdk::Threads::init Gtk::init def show_dialog window, text dialog =3D Gtk::MessageDialog.new window, 0, Gtk::MessageDialog::INFO, Gtk::MessageDialog::BUTTONS_CLOSE, text dialog.run dialog.destroy end window =3D Gtk::Window.new window.set_default_size 300, 300 button =3D Gtk::Button.new("Hm.. not much going on here") button.signal_connect("clicked") { show_dialog window, "from button click" = } window << button window.signal_connect("delete-event") { Gtk::main_quit } window.show_all Thread.new do loop do sleep 3 puts "entering critical part here" Gdk::Threads::synchronize do show_dialog window, "from thread" end puts "leaving critical part here" end end Gtk::timeout_add(1) do true end Gtk::main |
From: Masao M. <mu...@hi...> - 2006-01-28 05:06:26
|
Hi, On Fri, 27 Jan 2006 18:25:38 -0800 Joe Van Dyk <joe...@gm...> wrote: > require 'gtk2' > > Gdk::Threads::init > Gtk::init > > def show_dialog window, text > dialog = Gtk::MessageDialog.new window, > 0, > Gtk::MessageDialog::INFO, > Gtk::MessageDialog::BUTTONS_CLOSE, > text > dialog.run > dialog.destroy > end > > window = Gtk::Window.new > window.set_default_size 300, 300 > button = Gtk::Button.new("Hm.. not much going on here") > button.signal_connect("clicked") { show_dialog window, "from button click" } > window << button > > window.signal_connect("delete-event") { Gtk::main_quit } > window.show_all > > Thread.new do > loop do > sleep 3 > puts "entering critical part here" > Gdk::Threads::synchronize do > show_dialog window, "from thread" > end > puts "leaving critical part here" > end > end > > Gtk::timeout_add(1) do > true > end > > Gtk::main You can't use Gtk::Dialog#run in the Thread. You need to call it in main thread. This is a restrict of Ruby-GNOME2 now. -- .:% Masao Mutoh<mu...@hi...> |
From: Joe V. D. <joe...@gm...> - 2006-01-28 20:07:10
|
On 1/27/06, Masao Mutoh <mu...@hi...> wrote: > Hi, > > On Fri, 27 Jan 2006 18:25:38 -0800 > Joe Van Dyk <joe...@gm...> wrote: > > > require 'gtk2' > > > > Gdk::Threads::init > > Gtk::init > > > > def show_dialog window, text > > dialog =3D Gtk::MessageDialog.new window, > > 0, > > Gtk::MessageDialog::INFO, > > Gtk::MessageDialog::BUTTONS_CLOSE, > > text > > dialog.run > > dialog.destroy > > end > > > > window =3D Gtk::Window.new > > window.set_default_size 300, 300 > > button =3D Gtk::Button.new("Hm.. not much going on here") > > button.signal_connect("clicked") { show_dialog window, "from button cli= ck" } > > window << button > > > > window.signal_connect("delete-event") { Gtk::main_quit } > > window.show_all > > > > Thread.new do > > loop do > > sleep 3 > > puts "entering critical part here" > > Gdk::Threads::synchronize do > > show_dialog window, "from thread" > > end > > puts "leaving critical part here" > > end > > end > > > > Gtk::timeout_add(1) do > > true > > end > > > > Gtk::main > > You can't use Gtk::Dialog#run in the Thread. > You need to call it in main thread. > > This is a restrict of Ruby-GNOME2 now. That's unfortunate. But thanks for the information. I want to add a messaging capability to my application, where other applications can send my application a message over the network and my application pops up a dialog and prompts the user to do something. So, I'm using GServer for the networking part. My serve function looks lik= e def serve client text =3D client.gets response =3D case text when /^INFO: (.+)/ # pop up an information dialog when /^QUESTION: (.+)/ # pop up a question dialog end client.puts response end Any ideas on a solution? I will sometimes need to get the response from the user to send back across the network. |
From: Masao M. <mu...@hi...> - 2006-01-31 17:33:27
|
Hi, On Sat, 28 Jan 2006 12:07:00 -0800 Joe Van Dyk <joe...@gm...> wrote: > > You can't use Gtk::Dialog#run in the Thread. > > You need to call it in main thread. > > > > This is a restrict of Ruby-GNOME2 now. > > That's unfortunate. But thanks for the information. Sure. Are there anyone who try to solve this issue? > I want to add a messaging capability to my application, where other > applications can send my application a message over the network and my > application pops up a dialog and prompts the user to do something. > > So, I'm using GServer for the networking part. My serve function looks like > def serve client > text = client.gets > > response = case text > when /^INFO: (.+)/ > # pop up an information dialog > when /^QUESTION: (.+)/ > # pop up a question dialog > end > > client.puts response > end > > Any ideas on a solution? I will sometimes need to get the response > from the user to send back across the network. I think it depends the application... I attached a server/client sample script. Run server.rb, and then run client.rb in another terminal like as: $ ruby client.rb "INFO: message" $ ruby client.rb "QUESTION: message" HTH. -- .:% Masao Mutoh<mu...@hi...> |
From: Joe V. D. <joe...@gm...> - 2006-01-31 17:41:25
|
On 1/31/06, Masao Mutoh <mu...@hi...> wrote: > Hi, > > On Sat, 28 Jan 2006 12:07:00 -0800 > Joe Van Dyk <joe...@gm...> wrote: > > > > You can't use Gtk::Dialog#run in the Thread. > > > You need to call it in main thread. > > > > > > This is a restrict of Ruby-GNOME2 now. > > > > That's unfortunate. But thanks for the information. > > Sure. Are there anyone who try to solve this issue? How does Ruby-GNOME2 restrict running Gtk::Dialog#run in a different thread than the main one? If I understood the problem better I could probably help fixing it. > > I want to add a messaging capability to my application, where other > > applications can send my application a message over the network and my > > application pops up a dialog and prompts the user to do something. > > > > So, I'm using GServer for the networking part. My serve function looks= like > > def serve client > > text =3D client.gets > > > > response =3D case text > > when /^INFO: (.+)/ > > # pop up an information dialog > > when /^QUESTION: (.+)/ > > # pop up a question dialog > > end > > > > client.puts response > > end > > > > Any ideas on a solution? I will sometimes need to get the response > > from the user to send back across the network. > > I think it depends the application... > > I attached a server/client sample script. > > Run server.rb, and then run client.rb in another terminal like as: > > $ ruby client.rb "INFO: message" > $ ruby client.rb "QUESTION: message" Thanks! I'll take a look. |
From: Mirko M. <mi...@li...> - 2006-01-31 19:52:24
|
Joe Van Dyk ha scritto: > On 1/31/06, Masao Mutoh <mu...@hi...> wrote: > >>Hi, >> >>On Sat, 28 Jan 2006 12:07:00 -0800 >>Joe Van Dyk <joe...@gm...> wrote: >> >> >>>>You can't use Gtk::Dialog#run in the Thread. >>>>You need to call it in main thread. >>>> >>>>This is a restrict of Ruby-GNOME2 now. >>> >>>That's unfortunate. But thanks for the information. >> >>Sure. Are there anyone who try to solve this issue? > > > How does Ruby-GNOME2 restrict running Gtk::Dialog#run in a different > thread than the main one? If I understood the problem better I could > probably help fixing it. > There was some discussion on the mailing list some time ago (sept-oct 05 IIRC), when i was digging a bug in gtk::mozembed with the help from other on this mailing list (i remebrer Guillame, Masao but i surely miss someone else). The problem is that you try to call run in a different ruby-thread, not in a different thread, but ruby-threads are userspace threads implemented inside ruby. The way ruby-threads can coexist with the main loop of the gtk is via a custom glib poll function ($ less ruby-gnome2/glib/src/rbglib_mainloop.c) Unfortunately, talking with Owen, Arendriael and other on #gtk and #ruby i discovered that the custom poll function does no longer permit to call it recursively in gtk+. The thing is complicated by the fact that the glib main loop behaves differently weather glib-threads are used or not. (but by no means one should need to initialize glib threads to use ruby-threads). All in all I think this in not a ruby-gnome2 limitation but a limitation in the main-loop interconnection between glib and other software that is relevant only to ruby since it's one of the few with user space threads. I may be wrong, but this is what i recall became evident from our past threads on this topic. -- Mirko Maischberger |
From: Mirko M. <mi...@li...> - 2006-01-31 20:32:48
|
Mirko Maischberger ha scritto: > There was some discussion on the mailing list some time ago (sept-oct 05 > IIRC), when i was digging a bug in gtk::mozembed with the help from other on > this mailing list (i remebrer Guillame, Masao but i surely miss someone else). It was not oct 2005 nor sept 2005. The discussion begun 21 february 2005 ("About threads") and lasted till this message from Guillame in June on gtk-devel: http://mail.gnome.org/archives/gtk-devel-list/2005-June/msg00025.html Mirko |
From: Mirko M. <mi...@li...> - 2006-01-31 19:52:48
|
Joe Van Dyk ha scritto: > On 1/31/06, Masao Mutoh <mu...@hi...> wrote: > >>Hi, >> >>On Sat, 28 Jan 2006 12:07:00 -0800 >>Joe Van Dyk <joe...@gm...> wrote: >> >> >>>>You can't use Gtk::Dialog#run in the Thread. >>>>You need to call it in main thread. >>>> >>>>This is a restrict of Ruby-GNOME2 now. >>> >>>That's unfortunate. But thanks for the information. >> >>Sure. Are there anyone who try to solve this issue? > > > How does Ruby-GNOME2 restrict running Gtk::Dialog#run in a different > thread than the main one? If I understood the problem better I could > probably help fixing it. > There was some discussion on the mailing list some time ago (sept-oct 05 IIRC), when i was digging a bug in gtk::mozembed with the help from other on this mailing list (i remebrer Guillame, Masao but i surely miss someone else). The problem is that you try to call run in a different ruby-thread, not in a different thread, but ruby-threads are userspace threads implemented inside ruby. The way ruby-threads can coexist with the main loop of the gtk is via a custom glib poll function ($ less ruby-gnome2/glib/src/rbglib_mainloop.c) Unfortunately, talking with Owen, Arendriael and other on #gtk and #ruby i discovered that the custom poll function does no longer permit to call it recursively in gtk+. The thing is complicated by the fact that the glib main loop behaves differently weather glib-threads are used or not. (but by no means one should need to initialize glib threads to use ruby-threads). All in all I think this in not a ruby-gnome2 limitation but a limitation in the main-loop interconnection between glib and other software that is relevant only to ruby since it's one of the few with user space threads. I may be wrong, but this is what i recall became evident from our past threads on this topic. -- Mirko Maischberger |
From: Masao M. <mu...@hi...> - 2006-01-28 05:00:49
|
Hi, On Fri, 27 Jan 2006 18:00:25 -0800 Joe Van Dyk <joe...@gm...> wrote: > I want to show dialog boxes on a window from a different thread. Is > that possible? The above program freezes when the thread tries to > show the dialog. I can't seem to get it to work with the Gdk::Thread > stuff or without. You shouldn't use Gdk::Thread if you don't know it well. See: http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk%3A%3AThreads -- .:% Masao Mutoh<mu...@hi...> |
From: Joe V. D. <joe...@gm...> - 2006-01-31 19:17:42
|
On 1/31/06, Joe Van Dyk <joe...@gm...> wrote: > On 1/31/06, Masao Mutoh <mu...@hi...> wrote: > > Hi, > > > > On Sat, 28 Jan 2006 12:07:00 -0800 > > Joe Van Dyk <joe...@gm...> wrote: > > > > > > You can't use Gtk::Dialog#run in the Thread. > > > > You need to call it in main thread. > > > > > > > > This is a restrict of Ruby-GNOME2 now. > > > > > > That's unfortunate. But thanks for the information. > > > > Sure. Are there anyone who try to solve this issue? > > How does Ruby-GNOME2 restrict running Gtk::Dialog#run in a different > thread than the main one? If I understood the problem better I could > probably help fixing it. > > > > I want to add a messaging capability to my application, where other > > > applications can send my application a message over the network and m= y > > > application pops up a dialog and prompts the user to do something. > > > > > > So, I'm using GServer for the networking part. My serve function loo= ks like > > > def serve client > > > text =3D client.gets > > > > > > response =3D case text > > > when /^INFO: (.+)/ > > > # pop up an information dialog > > > when /^QUESTION: (.+)/ > > > # pop up a question dialog > > > end > > > > > > client.puts response > > > end > > > > > > Any ideas on a solution? I will sometimes need to get the response > > > from the user to send back across the network. > > > > I think it depends the application... > > > > I attached a server/client sample script. > > > > Run server.rb, and then run client.rb in another terminal like as: > > > > $ ruby client.rb "INFO: message" > > $ ruby client.rb "QUESTION: message" > > Thanks! I'll take a look. One of the things that the application needs to do is popup a dialog for every message that it receives. So if two messages were received at the same time, I'd like to show two dialog boxes. To do that, I'd probably need to tell the main thread somehow that a message was received and that it should show a dialog box, and if it was a question dialog, the main thread needs to communicate back to the other thread with the user's answer. I'm not sure of the best way to do that yet. |
From: Masao M. <mu...@hi...> - 2006-02-01 15:30:27
|
Hi, On Tue, 31 Jan 2006 11:17:39 -0800 Joe Van Dyk <joe...@gm...> wrote: > On 1/31/06, Joe Van Dyk <joe...@gm...> wrote: > > On 1/31/06, Masao Mutoh <mu...@hi...> wrote: > > > Hi, > > > I think it depends the application... > > > > > > I attached a server/client sample script. > > > > > > Run server.rb, and then run client.rb in another terminal like as: > > > > > > $ ruby client.rb "INFO: message" > > > $ ruby client.rb "QUESTION: message" > > > > Thanks! I'll take a look. > > One of the things that the application needs to do is popup a dialog > for every message that it receives. So if two messages were received > at the same time, I'd like to show two dialog boxes. > > To do that, I'd probably need to tell the main thread somehow that a > message was received and that it should show a dialog box, and if it > was a question dialog, the main thread needs to communicate back to > the other thread with the user's answer. I'm not sure of the best way > to do that yet. I think to use fork/exec may be easier. Anyway, there is many way to solve your problem. -- .:% Masao Mutoh<mu...@hi...> |
From: Joe V. D. <joe...@gm...> - 2006-02-02 01:31:40
|
On 2/1/06, Masao Mutoh <mu...@hi...> wrote: > Hi, > > On Tue, 31 Jan 2006 11:17:39 -0800 > Joe Van Dyk <joe...@gm...> wrote: > > > On 1/31/06, Joe Van Dyk <joe...@gm...> wrote: > > > On 1/31/06, Masao Mutoh <mu...@hi...> wrote: > > > > Hi, > > > > > I think it depends the application... > > > > > > > > I attached a server/client sample script. > > > > > > > > Run server.rb, and then run client.rb in another terminal like as: > > > > > > > > $ ruby client.rb "INFO: message" > > > > $ ruby client.rb "QUESTION: message" > > > > > > Thanks! I'll take a look. > > > > One of the things that the application needs to do is popup a dialog > > for every message that it receives. So if two messages were received > > at the same time, I'd like to show two dialog boxes. > > > > To do that, I'd probably need to tell the main thread somehow that a > > message was received and that it should show a dialog box, and if it > > was a question dialog, the main thread needs to communicate back to > > the other thread with the user's answer. I'm not sure of the best way > > to do that yet. > > I think to use fork/exec may be easier. > > Anyway, there is many way to solve your problem. This crashes badly on my system: def serve client text =3D client.gets message =3D Message.new text fork do Gtk::init dialog =3D Gtk::MessageDialog.new nil, Gtk::Dialog::MODAL, message.type, Gtk::MessageDialog::BUTTONS_CLOSE, message.message dialog.run Gtk::main end end How would I use fork differently? |
From: Joe V. D. <joe...@gm...> - 2006-02-02 01:57:01
|
On 2/1/06, Joe Van Dyk <joe...@gm...> wrote: > On 2/1/06, Masao Mutoh <mu...@hi...> wrote: > > Hi, > > > > On Tue, 31 Jan 2006 11:17:39 -0800 > > Joe Van Dyk <joe...@gm...> wrote: > > > > > On 1/31/06, Joe Van Dyk <joe...@gm...> wrote: > > > > On 1/31/06, Masao Mutoh <mu...@hi...> wrote: > > > > > Hi, > > > > > > > I think it depends the application... > > > > > > > > > > I attached a server/client sample script. > > > > > > > > > > Run server.rb, and then run client.rb in another terminal like as= : > > > > > > > > > > $ ruby client.rb "INFO: message" > > > > > $ ruby client.rb "QUESTION: message" > > > > > > > > Thanks! I'll take a look. > > > > > > One of the things that the application needs to do is popup a dialog > > > for every message that it receives. So if two messages were received > > > at the same time, I'd like to show two dialog boxes. > > > > > > To do that, I'd probably need to tell the main thread somehow that a > > > message was received and that it should show a dialog box, and if it > > > was a question dialog, the main thread needs to communicate back to > > > the other thread with the user's answer. I'm not sure of the best wa= y > > > to do that yet. > > > > I think to use fork/exec may be easier. > > > > Anyway, there is many way to solve your problem. > > This crashes badly on my system: > > def serve client > text =3D client.gets > message =3D Message.new text > fork do > Gtk::init > dialog =3D Gtk::MessageDialog.new nil, > Gtk::Dialog::MODAL, > message.type, > Gtk::MessageDialog::BUTTONS_CLOSE, > message.message > dialog.run > Gtk::main > end > end > > How would I use fork differently? Also, if I use fork and exec a new process, how would that process know to position the dialog box over the application window? Joe |