On Fri, 24 Oct 2003 12:01:27 -0400 "Tom Liu" <tom liu flextrade com> wrote:
Hi, 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.
You don't give GTK+ the opportunity to update the screen. Remember GTK+ is event driven. Add the following code to your loop, and it should work.
int done; GtkWidget pg; char msg[100]; for (done=0;done<100;done+=20){ sprintf (msg,"%d was done" , done); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pg),msg); gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pg),(double)(done)/100);
/* Add the following code */ while (gtk_events_pending ()) { gtk_main_iteration (); }
gdk_flush();
/* remove the sleep call, it will block your application. */
/* sleep(1); */ // do something take a long time. }
A better strategy is to do the work (and update the progress bar) in a timeout function, with gtk_timeout_add(). Note that this timeout function should only do a small bit of work. It will be called repeatedly, so you can do part of your work every time the timeout is called by GTK+. Think of timeouts as loops with GTK+ assistance. Roland -- R.F. Smith /"\ ASCII Ribbon Campaign r s m i t h @ x s 4 a l l . n l \ / No HTML/RTF in email http://www.xs4all.nl/~rsmith/ X No Word docs in email / \ Respect for open standards
Attachment:
pgpPBe_8U_9X9.pgp
Description: PGP signature