To: lablgtk at math.nagoya-u.ac.jp Subject: How to use a progress bar in a program loop From: David MENTRE Organization: none Date: Sun, 05 Feb 2006 14:09:30 +0100 Message-ID: <87vevurlyt.fsf at linux-france.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Hello, 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: let open_progress_bar ~title = let pb = new Demexp_gladeui.progress_bar_window () in pb#toplevel#set_title title; pb#the_progress_bar#set_text title; pb#toplevel#show; pb let progress_bar_set_fraction ~pb ~frac = pb#the_progress_bar#set_fraction frac let close_progress_bar ~pb = pb#toplevel#destroy () [... latter, when a window opens ...] let pb = MiscUI.open_progress_bar ~title:"Title" in for i = 1 to 1000 do let frac = (1000.0 -. float_of_int i) /. 1000.0 in MiscUI.progress_bar_set_fraction ~pb ~frac done; MiscUI.close_progress_bar ~pb 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. Is there any way to force such a refresh? Or is there a better way to make this kind of code for a lengthy computation? There is an example progressbar.ml in Lablgtk examples but the refresh is done with a timer (let ptimer = Timeout.add ~ms:50 ~callback:(fun () -> pbar#pulse(); true) in). It seems easier to me to do the refresh explicitely. Best wishes, d. -- pub 1024D/A3AD7A2A 2004-10-03 David MENTRE 5996 CC46 4612 9CA4 3562 D7AC 6C67 9E96 A3AD 7A2A