Re: progressbar updates
- From: Tim Evans <t evans aranz com>
- To: gtk-app-devel-list gnome org
- Subject: Re: progressbar updates
- Date: Mon, 06 Sep 2004 12:30:15 +1200
Felix Natter wrote:
"Brian J. Tarricone" <bjt23 cornell edu> writes:
the progress bar is only updated when the gtk main loop is run, which
only happens when any functions you are running give control back to the
main loop.
Ok, but isn't then the clean reason to start a subthread?
I get problems in the main thread when I access the progressbar
(set_fraction) and statusbar (push/pop) from the subthread (=> display
problems...). How can I synchronize this?
You can safely pass messages from the subthread to the main/gui thread
using g_idle_add:
typedef struct {
GtkWidget *progress_bar;
gdouble fraction;
} ProgressBarSetFraction;
gboolean idle_progress_bar_set_fraction (gpointer data)
{
ProgressBarSetFraction *p = data;
gtk_progress_bar_set_fraction (p->progress_bar, p->fraction);
g_free (p);
return FALSE;
}
int main (void)
{
...
g_thread_init (NULL);
...
}
In subthread:
ProgressBarSetFraction *p;
p = g_new (ProgressBarSetFraction, 1);
p->progress_bar = ...;
p->fraction = 0.5;
g_idle_add (gtk_progress_bar_set_fraction, p);
Note that the above code assumes that you do *not* call
gdk_threads_init. If you did, you would need to add
gdk_thread_enter/leave inside the idle function and all other idle and
timeout functions.
--
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]