Posted by
Stein Rørvik on
Oct 12, 2020; 2:58pm
URL: http://imagej.273.s1.nabble.com/Non-modal-dialog-with-Yes-No-Cancel-tp5024006p5024021.html
Thanks,
as a javascript this works fine.
I tried to wrap it in an ImageJ macro as follows:
script = "";
script += "gd = new NonBlockingGenericDialog('YesNoCancel Demo');\n";
script += "gd.addMessage('This is a Non-blocking YesNoCancel dialog');\n";
script += "gd.enableYesNoCancel('Do something', 'Do something else');\n";
script += "gd.showDialog();\n";
script += "reply = '';\n";
script += "if (gd.wasCanceled()) { reply = 'Cancel';}\n";
script += "else if (gd.wasOKed()) { reply = 'Yes';}\n";
script += "else {reply = 'No';}\n";
script += "reply;\n";
print(script);
reply = eval("script", script);
showMessage(reply);
The strange thing is that the Cancel condition does not work, but Yes and No work fine. It works however if I launch the macro from the command line using the -macro option. I don't understand why that should make a difference. It also works if I copy the assembled string as printed in the log window and run it from a text window as javascript.
I also tried eval("js", script); with the same behaviour.
What is the difference between eval("js", script); and eval("script", script); ?
I am using Windows 10/64 with Java 1.8.0_172 and the latest daily build.
Stein
-----Original Message-----
From: ImageJ Interest Group <
[hidden email]> On Behalf Of Wayne Rasband
Sent: 11. oktober 2020 22:42
To:
[hidden email]
Subject: Re: Non-modal dialog with Yes No Cancel
> 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:
https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=02%7C01%7Cstein.rorvik%40sintef.no%7Cc4102a0c938e4a00119c08d86e265784%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637380458253944105&sdata=uB3kHZ5EE2LVPQqEue0C019RMeHq0VpAiI4xK1SHFk0%3D&reserved=0--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html