From: Olivier Andrieu MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17382.10638.543279.353714 at karryall.dnsalias.org> Date: Sun, 5 Feb 2006 17:36:30 +0100 To: David MENTRE Cc: lablgtk at math.nagoya-u.ac.jp Subject: Re: How to use a progress bar in a program loop In-Reply-To: <87vevurlyt.fsf at linux-france.org> References: <87vevurlyt.fsf at linux-france.org> 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 `---- > Or is there a better way to make this kind of code for a lengthy > computation? You could use threads. HTH, -- Olivier [1] http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html#g-main-iteration