Re: gtk progress bar and gdk_flush()



Hi Tom,

   In order to avoid hijacking of the main
event loop you could take an approach like this:

/***************************************************/
cooperative_loop_source_id =
   g_timeout_add(interval/* itteration frequency in millisecs */,
                           cooperative_loop, NULL);

gboolean cooperative_loop(gpointer data)
{
   static int i = 0;
   if (i == 0) {
       // initialize loop stuff ...
       // allocate resources...
   }
   if (i < MAX_ITTERATIONS) {
       // loop body
   }
   if (i >= MAX_ITTERATIONS) {
       // free resources
       // and maybe notify end of loop processing.
       return FALSE;
   }
   return TRUE;
}
/***************************************************/

And now you should have no problems updateing your UI.

Cheers,
                                       -Tristan


Tom Liu wrote:

Thank you for your answer, But the thing is that you update the progress
bar in a time_out call back.

I have to put the progress bar in a long loop, didn't return to
gtk_main.
Which most progress bar should been used in a long loop task to show how
many percentage is done, after the task finish, return to main loop.

Thanks.


-----Original Message-----
From: gtk-app-devel-list-admin gnome org
[mailto:gtk-app-devel-list-admin gnome org] On Behalf Of Carlos Pereira
Sent: Friday, October 24, 2003 12:22 PM
To: gtk-app-devel-list gnome org
Subject: Re: gtk progress bar and gdk_flush()

I am working on the progress bar, I can't my progress bar updated in a
loop:
Even the gdk_flush() can't make it update on screen.

This works on Gtk1.2 (continuous mode):
Carlos

----------------------------------------
int app_gtk_statusbar_progress (gpointer data)
{
double new_value;
GtkAdjustment *adj;

new_value = gtk_progress_get_value (GTK_PROGRESS (data)) + 1;
adj = GTK_PROGRESS (data)->adjustment;
if (new_value > adj->upper) new_value = adj->lower;
gtk_progress_set_value (GTK_PROGRESS (data), new_value);

return TRUE;
}

timer_progress = gtk_timeout_add (100,
app_gtk_statusbar_progress, progress_bar);
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list





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