Delivered-To: lablgtk at yquem.inria.fr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; bh=cpW9orqr0T2GON3XzSfRYpSBpR2Cc/asjbF661jzo1Y=; b=QwRQUXLK2LGx9lsJFGM6dONpMZet5CZK4SH+Aj/Okypp9N2FQKa/sCwLh4sn8fzuwtaIB6VY/ssHcz0x33eq0X4TTG3OkuaWTzTBG8JnyStkn/rTJNYPtweOsND0gENLVRlXVD8FQzaSGQze88QY97xCJNbvct0JH2pdD6rbv0Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; b=wLZ+6P1Jx/1ROTIipFQXY8xz+CnDSdQ9Z9NrDHxQG6VX9J9nG96mPB7ZVIMtEynvIFV4UuIOC76OlBQxfsLNe6gw8SYQzMeb3wn1ZMbrq9268Ot8LGoXWOYSrEevdpRlcfIdPMstxyTMn4u7dbgbcLXfojVs6KRSybI+vo45oRo= Message-ID: <47B7A265.9000002 at gmail.com> Date: Sat, 16 Feb 2008 20:56:37 -0600 From: Edgar Friendly MIME-Version: 1.0 To: Angela Zhu , lablgtk at yquem.inria.fr Subject: Re: [Lablgtk] Cancel button or Status bar References: In-Reply-To: Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1 Content-Length: 1773 Angela Zhu wrote: > Hi, > > I am using OCaml to develop an interpreter with a GUI. > In the GUI, I have a "run" button, where when you click it, it > will call a function, say "eval prog1". > > Some time, the running time of "eval prog1" can be long, and > in case I want to add to the GUI the functionality that, > when click on another "cancel" button, it will terminate the > computation/evaluation immediately. (The user might don't > want to wait until the execution to finish. ) > > Anyone have some idea how to achieve this? > Many ways: 1) threads 2) break your mega computation into something that can get done in pieces and have [eval prog1] return true or false based on whether it has more work to do. Then schedule it using [Idle.add], and it'll keep running in chunks until it's done, but the GUI will still get time to process events (and allow you to kill the task by removing it from the idle loop). 3) like 2 but in reverse: in your computation, occasionally call [Glib.Main.iteration false] to give GTK control of things to check its signal handlers and see if it needs to cancel things (setting a global variable or something, I guess) > If this is impractical in OCaml, then how can I generate a > "status bar", which indicates how much of the program > (e.g. in percentage) has been finished, so you can have > an estimation on how much more you need to wait for the program > to finish. > > Thanks a lot in advance! Alternatively, you could make a progress bar ([GRange.progress_bar]), and pass it to your function to call the [#set_fraction] method with a float 0.0-1.0 to indicate % done. E _______________________________________________ Lablgtk mailing list Lablgtk@yquem.inria.fr http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk