Re: Gtk ProgressBar problem
- From: Todd Fisher <taf2 lehigh edu>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Gtk ProgressBar problem
- Date: Wed, 23 Jun 2004 12:19:09 -0400
Tristan Van Berkom wrote:
christophe meyer wrote:
Hi all,
In my glade designed project i need to update a progressbar when a
callback function is called like in this short example:
void on_button_clicked (GtkButton * button, gpointer user_data)
{
GtkWidget *Progress_Bar = lookup_widget (GTK_WIDGET (button),
"progressbar");
action_function1();
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (Progress_Bar), 0.2);
action_function2();
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (Progress_Bar), 0.4);
action_function3();
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (Progress_Bar), 0.6);
action_function4();
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (Progress_Bar), 0.8);
action_function5();
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (Progress_Bar), 1.0);
}
Each action_function() takes 2 or 3 seconds to finish.
The matter is that when the callback function is called, nothing
happens between the action_functions() with the bar, and at the end,
once action_function5() is finished the progressbar updates directly
to 100%.
Home can i gradualy update my progressbar while executing my callback
function ?
while (gtk_events_pending()) gtk_main_iteration_do(FALSE);
This pretty line of code will process all gtk pending events by
nesting the mainloop (as opposed to simply returning to it).
You could go about this in a number of ways, here are a few:
- you could start a timout func that calls your action_func() once every
timout and then you wouldn't need to nest the main loop
- you could insert that handy afore mentioned line between
action_func()s
- if you want to be really meticulous and have your UI responsive
*during* the action func's, then you could use threads.
- if you want your ui to stay responsive but want to avoid the trouble
and/or complexity that comes with using threads, then you could
open up
action_func.c and scatter that afore mentioned handy line all over
the place.
Cheers,
-Tristan
Hi,
Here's an example I put together to help myself understand how to use
threads and
progressbars together. Hopefully, it will help you too :-)
http://severna.homeip.net/source/examples/progress-5-21-2004.tar.gz
-todd
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]