Am Montag, den 11.02.2008, 18:19 -0500 schrieb Jacques Pelletier:
> On February 11, 2008 05:37:54 pm Vallone, Anthony wrote:
> > From:
> > "Vallone, Anthony" <anthony vallone lmco com>
> > To:
> > gtk-list gnome org
> > Myself, I avoid the enter/leave calls in favor of g_idle_add() as a
> > mechanism to queue all gui calls for the main event loop thread. Let
> > your other threads stick to performing the non-gui work, and you'll save
> > yourself from many headaches. (I wish someone told me that 3 years ago).
>
> Hi,
>
> I'm interested to know more about that. Is there some source code example that
> I can follow?
The pattern goes like this:
if (!g_thread_create (background_worker, job_data, joinable, &error))
{
report_error (error);
return;
}
....
static gpointer
background_worker (gpointer data)
{
JobStruct *job = data; /* extract job description from data */
/* do everything you like, EXPECT touching widgets */
g_idle_add (report_progress, progress_data);
/* still do what your want, EXPECT touching widgets */
return result;
}
....
static gboolean
report_progress (gpointer data)
{
ProgressData *progress = data; /* extract progress from data */
MamanBar *ui = progress->ui; /* retreive UI handle */
gtk_label_set_text (GTK_LABEL (ui->progress_label), progress->text);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (ui->progress_bar),
progress->fraction);
/* UI has been update. Do not call this function again, unless
* new progress happend. In this case the function is re-added
* to the idle queue with g_idle_add().
*/
return FALSE;
}
Ciao,
Mathias
--
Mathias Hasselmann <mathias hasselmann gmx de>
Openismus GmbH: http://www.openismus.com/
Personal Site: http://taschenorakel.de/
Attachment:
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil