[Glade-users] Update progressbar from forked child
Steven
steven at whoaa.be
Mon Nov 20 10:31:07 EST 2006
Hi Tristan,
Thx for your answer. I'll subscribe to the gtk lists.
I tried your solution, and it works half...
If I use vfork, my main window hangs until the child is done, and then
the progressbar is updated nicely
(but the function keeps running, despite the return FALSE;)
If I use fork, the main window doesn't hang but the idle_function isn't
executed (even not when the child exits)
Do you mind glancing an eye on my code ? I'm not used to program GUIs
and work with events etc, so I guess it's a stupid mistake somewhere.
And I'll be glad if you could point it out :-)
Thx
Steven
================= CODE =================
void on_button6_released (GtkButton *button, gpointer user_data)
{
blabla
int pid=fork();
if (pid == 0)
{
while (...)
{
int error_sig;
progress = ((counter*PBfraction)+PBfraction);
g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
NULL, NULL, NULL, &error_sig, NULL);
g_idle_add(update_progressbar, &progress);
counter++;
}
_exit(0);
}
}
void update_progressbar (fraction)
{
GtkWidget *progressbar = lookup_widget(GTK_WIDGET(main_widget),
"progressbar1");
gtk_progress_bar_set_fraction(progressbar, .5);
printf("Function called, fraction : %f\n", fraction);
return FALSE;
}
================= /CODE =================
Tristan Van Berkom wrote:
> Steven wrote:
>> Hi there,
>>
>> This is my first attempt to Gtk Programming in Glade. Although I know
>> php and a little VB, It's been a long time since I used ansi C and maybe
>> I'm doing stupid things. Please feel free to point them out :-)
>
> Hi Steven,
> First of all, you'll get a better suited audience for gtk+
> programming
> related questions on the gtk lists (gtk-app-devel-list at gnome.org). This
> list is more related to the glade tool & the glade files that the
> glade tool
> generates.
>
> What I sugest you do (and there are a few ways) is this:
>
> - Create a thread that is responsable for the entire process of
> converting the images - from this thread you will never call gtk+
> functions that deal with widgets (or progressbars) in the main GUI
> thread.
>
> - In the thread you will loop through all the filenames and do the
> following
> for each file:
> o call g_spawn_sync(/* program to convert one file */);
> o call g_idle_add() /* to add a function that will be called from
> the
> main thread the next time the main thread is idle */
>
> - From the g_idle_add() callback that you registered from the worker
> thread
> but runs in the main thread (the gtk_main() thread that is), you will
> then proceed to call
> "gtk_progress_bar_whatever_you_want_cause_its_safe_here()"
> and return FALSE to ensure the idle was a one shot deal for every
> time it
> was explicitly registered from the thread.
>
> There you have it :)
>
> Cheers,
> -Tristan
More information about the Glade-users
mailing list