Hello Olivier,

Olivier Andrieu <[EMAIL PROTECTED]> writes:

> Hi David,
>
>  David MENTRE [Sunday 5 February 2006] :
>  > My program is doing lengthy computations or network access and I
>  > would like to add a progress bar showing progress. I have tried
>  > following code:
>  > 
>  > The main issue is that a gray area corresponding to the progress
>  > bar appears but the progress bar is never updated. I suppose this
>  > is because the GTK main loop is not called and the display is not
>  > refreshed.
>
> Yes.
>
>  > Is there any way to force such a refresh? 
>
> Yes, you just need to interrupt your lengthy computation regularly and
> call GTK so that it can process the events in its queue (including the
> event redawing the progess bar). You can do a single iteration of the
> GTK main loop using g_main_iteration [1].
> I use this function in one of my programs:
>
> ,----
> | let pump () =
> |   while Glib.Main.iteration false do () done
> `----

Many thanks. It works quite well.

>  > Or is there a better way to make this kind of code for a lengthy
>  > computation?
>
> You could use threads.

Well. In fact the lengthy update comes from network access time. I
wanted to avoid thread issues for my relatively simple client
application (I already have enough issues without chasing thread bugs
;). Maybe one day I'll redesign it with the GUI on one side and all the
network/computation code on the other side, to allow for asynchronous
behavior.

Best wishes,
d.
-- 
pub  1024D/A3AD7A2A 2004-10-03 David MENTRE <[EMAIL PROTECTED]>
 5996 CC46 4612 9CA4 3562  D7AC 6C67 9E96 A3AD 7A2A



_______________________________________________
Demexp-dev mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/demexp-dev

Répondre à