Re: Use of showImageWithCancel("message") ?

Posted by Rasband, Wayne (NIH/NIMH) [E] on
URL: http://imagej.273.s1.nabble.com/Use-of-showImageWithCancel-message-tp3689513p3689514.html

On Feb 3, 2010, at 12:21 PM, Alan Hewat wrote:

> According to the IJ doc
> http://rsbweb.nih.gov/ij/developer/api/ij/IJ.html
> showImageWithCancel("message")  should return "false" if
> CANCEL is clicked and otherwise "true".
>
> But in ImageJ 1.43o I get  the error "number or numeric function expected" for:
>
> if(!showMessageWithCancel("Is this OK?")) showMessage("You clicked CANCEL");
>
> I want to branch to alternative actions according to "OK" or "CANCEL".
> So far as I can see showMessageWithCancel() acts just like
> showMessage() except that it has a CANCEL button that simply
> exits the routine :-(

The API docs at
   http://rsbweb.nih.gov/ij/developer/api/ij/IJ.html
are for plugin and JavaScript writers. Macro writers should be looking at the descriptions of the built in macro functions at
   http://rsbweb.nih.gov/ij/developer/macro/functions.html

Here is the description of the showMessageWithCancel() function:

    showMessageWithCancel(["title",]"message")
       Displays "message" in a dialog box with "OK" and "Cancel"
       buttons. "Title" (optional) is the dialog box title. The macro
       exits if the user clicks "Cancel" button.

It won't work because it causes the macro to exit when the user clicks "Cancel". What you want is the getBoolean() macro function:

   getBoolean("message")
      Displays a dialog box containing the specified message and
      "Yes", "No" and "Cancel" buttons. Returns true (1) if the user
      clicks "Yes", returns false (0) if the user clicks "No" and exits
      the macro if the user clicks "Cancel".

Here is an example:

     if (!getBoolean("Is this OK?"))
        showMessage("The user clicked 'No'");

-wayne