Kim Jongha wrote: > Greeting, > > progress bar is updated "only" using timeouts ? > > I read some big file and want to show up the progress how much App. > read file. so I use progress bar like below > > > double val; > for(i = 0; i< SOME_NUMBER; i++) > { > val = (100.0 /SOME_NUMBER)* i /100.0; > gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pbar), val); > gtk_widget_show(pbar); > } > > No error, 'val' value is greater than 0.0 less than 1.0. but it > doesn't work while app. read file. when app read file completly, then > progress bar filled fully is shown up. > I try to use timeouts, and that how can I read file.. ? > > give me a advise, thank you. > _______________________________________________ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list >
I don't think timeouts will work in this case, or if they can be used, I don't know how to do it. I would create a separate thread to do the file reading that sends "progress reports" to the main thread in order to update the progress bar. I wouldn't try to update the progress bar directly from the file loading thread, I've seen too many people have problems in this list when they try to work with the GUI from threads other than the main one. My method, which I suspect is very non-standard if not outright bizarre seems to work for me... During setup, before calling gtk_main: /* create a pipe to receive messages from threads glmsgs is global, declared as gint glmsgs[2] */ pipe( glmsgs ) /* set up a callback to the function 'gotmessage' whenever anything is readable in the pipe */ gdk_input_add( glmsgs[0], GDK_INPUT_READ, gotmessage, NULL ); Create a callback function to deal with the messages: void gotmessage( gpointer data, gint fd, GdkInputCondition condition ) { gint msg; gpointer ptr1; gpointer ptr2; read( fd, &msg, sizeof( gint )); read( fd, &ptr1, sizeof( gpointer )); read( fd, &ptr2, sizeof( gpointer )); switch( msg ) { ... as you can see, the 'message' actually consists of a message-number and two void pointers. I know, this looks like the message passing mechanism of OS/2 (and Windows) - my roots are showing... When the file reading thread needs to let the main thread know about the progress of the read, it writes a gint and two pointers to the pipe. In your program, the two pointers could be eliminated, and the message number itself could convey all you want to know. 0-100 is percent of file read, and -1 is read failure, or something like that. If there may be more than one thread writing to the pipe, be sure to protect the writing with a mutex. Only the callback function ever reads the pipe, so it should be fine without a mutex. Now, if someone could illustrate a more accepted method for doing this sort of thing - I'm listening. I've tried to see how others have solved this problem, but I'm not very good at understanding other folks code without *lots* of comments explaining what's going on, and why. -- Tony _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list