Re: gnome_dialog_hell



Hi Luciano

Thanks for your response your theory sounds good I will definitely give it a
bash.

Many thanks

Ian Frawley

----- Original Message -----
From: "Luciano Chavez" <lnx1138 us ibm com>
To: "Ian Frawley" <ifrawley opaltelecom co uk>
Cc: <gtk-app-devel-list gnome org>
Sent: Wednesday, May 29, 2002 7:04 PM
Subject: Re: gnome_dialog_hell


On Wed, 2002-05-29 at 09:53, Ian Frawley wrote:
Bloomin eck I cannot get this going. I am having right problems with
invoking a gnome dialog from a thread. I have tried sticking it into a
call-back and now I see it for a second and then it disappears and leaves me
with the following message:

GLib-WARNING **: g_main_run(): called recursively from within a source's
check() or prepare() member or from a second thread, iteration not possible

huh what's this all about? Any help would be wicked.

Ian,

I'm only guessing, not having used Gnome widgets just standard GTK
widgets, but its probable that the Gnome dialog widget you are using is
the type that doesn't return until a response (button) is give
(clicked).

If so, I imagine they make the operation appear synchronous by entering
an inner main event loop in order to process events and signals for the
dialog and exiting this inner loop when the dialog is
dismissed/destroyed.

If this is the case then attempting to run an inner main loop doesn't
work if you are not running off the main event loop/thread.

A suggestion that has worked for me and mentioned before is to "inject"
the widget calls to run in the main event loop thread using an one-time
run idle function. Something like this:

non main event loop thread does this:

gtk_idle_add ((GtkFunction) display_message_window_from_main_thread,
args);

Now, in the main event loop you idle function might run and do stuff
like:

gboolean display_message_window_from_main_thread (gpointer user_data)
{
    gdk_threads_enter ();
    /*
     * GTK calls go here.
     */
    gdk_threads_leave ();

    return FALSE;
}

Now, being that this example is for an asynchronous dialog (like for an
alert message), this may not be exactly what you want. To give the
appearance of being synchronous, you may need to create a condition
semaphore (see g_cond_new()) in the other thread before calling
gtk_idle_add() and pass this semaphore info to the idle function so that
when the dialog call returns, it signals to the other thread that the
dialog got a response.

No one said writing multi-threaded apps with GTK was easy. In fact,
everyone told me to use pipes and processes but I find that just as
kludgy. I like threads (speaks the OS/2 programmer in me where threads
were common-place).

--
regards,

Luciano Chavez

lnx1138 us ibm com
http://evms.sourceforge.net







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]