demexp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Demexp-dev] Re: How to use a progress bar in a program loop


From: David MENTRE
Subject: [Demexp-dev] Re: How to use a progress bar in a program loop
Date: Mon, 06 Feb 2006 22:54:02 +0100
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Hello Olivier,

Olivier Andrieu <address@hidden> 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 <address@hidden>
 5996 CC46 4612 9CA4 3562  D7AC 6C67 9E96 A3AD 7A2A





reply via email to

[Prev in Thread] Current Thread [Next in Thread]