Re: Problem in updating progress bar
- From: Diego Zuccato <diego otello alma unibo it>
- To: DC A <adc4444 hotmail com>
- Cc: gtk-list gnome org
- Subject: Re: Problem in updating progress bar
- Date: Fri, 16 Jun 2006 07:39:02 +0200
DC A wrote:
> What could be the reason for using gtk_events_pending() and
> gtk_main_iteration() in the following code snippet:
>
>
> for( gflt=0; gflt<=1; ){
> gtk_progress_bar_update( (GtkProgressBar*)pbar, gflt );
> //update
> while (gtk_events_pending ())
> gtk_main_iteration ();
> gflt += 0.1;
> sleep(1);
> if ( gflt > 1 ) break;
> }
>
> why the code cannot update the progressbar without these two functions? I
> saw the API but still it is not clear to me.
'Cause you're blocking the main loop (which handles all the updating).
But that sleep(1) still blocks for a whole second any action: your GUI
will act quite strangely!
Could be really better to handle a timeout/idle callback.
If all you have to do is some lengthy operation, you could use a thread
that does it and updates a "percentage indicator" (a shared variable).
In the main program (the GUI manager) you set up a timeout callback (the
timeout is up to you: from .1 to tenths of seconds) that reads the
shared variable and updates the progress bar. This way you won't have to
bother about locks: just DON'T do anything GUI-related in the calc thread.
BYtE,
Diego.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]