To: Olivier Andrieu Cc: lablgtk at math.nagoya-u.ac.jp, demexp-dev at nongnu.org Subject: Re: How to use a progress bar in a program loop References: <87vevurlyt.fsf at linux-france.org> <17382.10638.543279.353714@karryall.dnsalias.org> From: David MENTRE Organization: none Date: Mon, 06 Feb 2006 22:54:02 +0100 In-Reply-To: <17382.10638.543279.353714 at karryall.dnsalias.org> (Olivier Andrieu's message of "Sun, 5 Feb 2006 17:36:30 +0100") Message-ID: <87oe1k6tmt.fsf at linux-france.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Hello Olivier, Olivier Andrieu 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 5996 CC46 4612 9CA4 3562 D7AC 6C67 9E96 A3AD 7A2A