Login  Register

Re: Non-modal dialog with Yes No Cancel

Posted by Wayne Rasband-2 on Oct 11, 2020; 8:41pm
URL: http://imagej.273.s1.nabble.com/Non-modal-dialog-with-Yes-No-Cancel-tp5024006p5024018.html

> On Oct 9, 2020, at 2:58 PM, Stein Rørvik <[hidden email]> wrote:
>
> I am looking for a non-modal version of a Yes/No/Cancel dialog to use in a macro.
> I need a "No" choice that will provide the option to redo the processing instead of continuing or canceling, as the processing involves some manual input that can be adjusted.

Use eval(“js”,code) to call this JavaScript code:

  gd = new NonBlockingGenericDialog("YesNoCancel Demo");
  gd.addMessage("This is a Non-blocking YesNoCancel dialog");
  gd.enableYesNoCancel("Do something", "Do something else");
  gd.showDialog();
  if (gd.wasCanceled())
     IJ.log("User clicked 'Cancel'");
  else if (gd.wasOKed())
      IJ. log("User clicked 'Yes'");
  else
     IJ. log("User clicked 'No'”);

-wayne


> We have a getBoolean(message, yesLabel, noLabel) function which basically does what I want,
> but I need a non-modal dialog since the user should be allowed to select different windows to inspect that the results of the macro execution is as expected before continuing.
>
> Here is an example flow with the existing getBoolean dialog:
>
> //yes-no-cancel dialog works as desired, but it is only available modal
> reply = false;
> while (!reply) {
>                //do some processing here, creating results to be inspected
>                reply = getBoolean("Are the results ok?", "Yes", "No");
> }
> //continue
>
>
> We have a Dialog.createNonBlocking function that creates a non-modal dialog, but I find no way to add Yes / No / Cancel buttons to it.
>
> We can add a checkbox, but it looks clumsy:
>
> //workaround using checkbox
> no = true;
> while (no) {
>                //do some processing here, creating results to be inspected
>                Dialog.createNonBlocking("Verify");
>                Dialog.addMessage("Are the results ok?");
>                Dialog.addCheckbox("No", no);
>                Dialog.show();
>                no = Dialog.getCheckbox();
> }
> //continue
>
> We can also use radio buttons, but that looks equally clumsy:
>
> //workaround using radio buttons
> reply = "No";
> while (reply == "No") {
>                //do some processing here, creating results to be inspected
>                Dialog.createNonBlocking("Verify");
>                Dialog.addMessage("Are the results ok?");
>                Dialog.addRadioButtonGroup("Reply", newArray("Yes", "No", "Cancel"), 1, 3, reply);
>                Dialog.show;
>                reply = Dialog.getRadioButton;
>                if (reply == "Cancel") exit;
> }
> //continue
>
> Any ideas?
> Some JavaScript that can create the desired non-modal Yes/No/Cancel dialog?
>
> The best solution would be if we could have a way to add custom buttons in the Dialog.* functions in the macro language,
> like Dialog.addButton(text, isDefault).
>
> I am not sure the best way to have a return value from that, perhaps by passing a return value to Dialog.show;
> or having a  Dialog.getButton() function that returned the label of the custom button that was pressed on dialog exit.
> Then one could add buttons named like "Redo" or "Continue " which could lead to a different action than "OK" or "Cancel".
>
> Stein

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html