[Glade-users] Update progressbar from forked child

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 :-)


================= CODE =================

void on_button6_released (GtkButton *button, gpointer user_data)
    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);


void update_progressbar (fraction)
    GtkWidget *progressbar = lookup_widget(GTK_WIDGET(main_widget),
    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+
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

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

 - In the thread you will loop through all the filenames and do the
   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
       main thread the next time the main thread is idle */

 - From the g_idle_add() callback that you registered from the worker
   but runs in the main thread (the gtk_main() thread that is), you will
   then proceed to call
   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 :)


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