Interesting. So g_idle_add can be safely called from a different thread? Does 
it have to be a gthread, or will a pthread work as well?

I've added gdk_threads_enter/leave around all my calls, and so far as I can 
tell, everything appears to be fine now.

Still, design-wise it might be nicer to use the g_idle_add pattern. 
Particularly since it would then make sense to have idle functions return 
false, and thus not be spinning the CPU when they don't actually have any work.

Unrelated question:
I have some number of draw_area widgets inside expanders, arranged in an hbox 
in my window. First, is there a way to get the outer window to reduce its size 
in correspondence with whether the expanders are open or closed? Second, is 
there some widget I can replace the hbox with, so that any number of windows 
can be placed into a finite space and they will be automatically resized and 
arranged to fit nicely in that space? It would be good to have this 
functionality, but I don't have time to code it myself. For instance, if there 
are two windows I'd like them large and side-by-size, but if there are four, 
I'd like them in a 2x2 pattern and smaller.
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" <[EMAIL PROTECTED]>
> >   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 <[EMAIL PROTECTED]>
Openismus GmbH: http://www.openismus.com/
Personal Site: http://taschenorakel.de/
_______________________________________________
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list
_______________________________________________
gtk-list mailing list
gtk-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to