Non-modal dialog with Yes No Cancel

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Non-modal dialog with Yes No Cancel

Stein Rørvik
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.

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
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Krs5
Dear Stein,

What about:

do{       //do some processing here, creating results to be inspected
           reply = getBoolean("Are the results ok?", "Yes", "No");
} while(!reply)
// continue


Best wishes

Kees


Dr Ir K.R. Straatman

Advanced Imaging Facility

University of Leicester
www.le.ac.uk/advanced-imaging-facility<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.le.ac.uk%2Fadvanced-imaging-facility&data=02%7C01%7Ckrs5%40leicester.ac.uk%7C7140559c900a4b0dd16608d86b88a757%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637377581956238143&sdata=Ry7Aeb%2FkHkgcgXqV%2FeUuW1Qmc002UXFnEK4x6%2FBTMi4%3D&reserved=0>


Sent: 09 October 2020 19:58
Subject: Non-modal dialog with Yes No Cancel

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.

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&amp;data=02%7C01%7Ckrs5%40leicester.ac.uk%7C88b13f6c6b39454e021608d86c8654de%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637378671491557112&amp;sdata=8uq0ccBsG%2FMkCQc7Uf9Q7ZVEXFjxSaZZvzDs019%2FnMM%3D&amp;reserved=0

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Stein Rørvik
Same effect as my first example, but still modal, which is my problem.
I need to change between images while the dialog is open to inspect them.

Stein

-----Original Message-----
Sent: 10. oktober 2020 13:25
Subject: Re: Non-modal dialog with Yes No Cancel

Dear Stein,

What about:

do{       //do some processing here, creating results to be inspected
           reply = getBoolean("Are the results ok?", "Yes", "No");
} while(!reply)
// continue


Best wishes

Kees


Dr Ir K.R. Straatman

Advanced Imaging Facility

University of Leicester
https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.le.ac.uk%2Fadvanced-imaging-facility&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7C8f8eed6e75374487464208d86d0f52ac%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637379259882198793&amp;sdata=uH5wvfqgMtBSCjxy5cxlHABVPV7O%2Bi3jalQer9dS1UI%3D&amp;reserved=0<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.le.ac.uk%2Fadvanced-imaging-facility&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7C8f8eed6e75374487464208d86d0f52ac%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637379259882198793&amp;sdata=uH5wvfqgMtBSCjxy5cxlHABVPV7O%2Bi3jalQer9dS1UI%3D&amp;reserved=0>


Sent: 09 October 2020 19:58
Subject: Non-modal dialog with Yes No Cancel

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.

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&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7C8f8eed6e75374487464208d86d0f52ac%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637379259882198793&amp;sdata=VCnsk%2BDwWTisYh00k%2FMFqgCc86SYwnHiBFU4Ai0%2F8jU%3D&amp;reserved=0

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7C8f8eed6e75374487464208d86d0f52ac%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637379259882198793&amp;sdata=VCnsk%2BDwWTisYh00k%2FMFqgCc86SYwnHiBFU4Ai0%2F8jU%3D&amp;reserved=0

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Wayne Rasband-2
In reply to this post by Stein Rørvik
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Stein Rørvik
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&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Cc4102a0c938e4a00119c08d86e265784%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637380458253944105&amp;sdata=uB3kHZ5EE2LVPQqEue0C019RMeHq0VpAiI4xK1SHFk0%3D&amp;reserved=0

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Herbie
Dear Stein,

I tried Wayne's suggestion yesterday and can confirm "that the Cancel
condition does not work" in the sense that it returns nothing as reply.
(That's on a Mac but shouldn't make a difference...)

Best

Herbie

::::::::::::::::::::::::::::::::::::::::::
Am 12.10.20 um 16:58 schrieb Stein Rørvik:

> 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&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Cc4102a0c938e4a00119c08d86e265784%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637380458253944105&amp;sdata=uB3kHZ5EE2LVPQqEue0C019RMeHq0VpAiI4xK1SHFk0%3D&amp;reserved=0
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Michael Schmid
In reply to this post by Stein Rørvik
Hi Stein,

the problem seems to be that <cancel> or <escape> terminates a running
macro or (in this case) script, as soon as "gd.wasCanceled()" is called.
Then, the Javascript returns nothing.

You can determine determine the 'canceled' condition by checking for an
empty reply String.
This it is a rather nasty hack, however, not necessarily guaranteed to
work in the future if the mechanism of handling the 'canceled' condition
should change.

Michael
________________________________________________________________


On 12.10.20 16:58, Stein Rørvik wrote:

> 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&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Cc4102a0c938e4a00119c08d86e265784%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637380458253944105&amp;sdata=uB3kHZ5EE2LVPQqEue0C019RMeHq0VpAiI4xK1SHFk0%3D&amp;reserved=0
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Stein Rørvik
Michael,

Your explanation sounds reasonable, but why does the script indeed return 'Cancel' if run from the command line? I discovered this by accident as I use an external editor which launches ImageJ via the command line when writing or testing new macros.

But I will assume that checking for both an empty string and 'Cancel' will suffice.

Stein

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Michael Schmid
Sent: 12. oktober 2020 17:40
To: [hidden email]
Subject: Re: Non-modal dialog with Yes No Cancel

Hi Stein,

the problem seems to be that <cancel> or <escape> terminates a running macro or (in this case) script, as soon as "gd.wasCanceled()" is called.
Then, the Javascript returns nothing.

You can determine determine the 'canceled' condition by checking for an empty reply String.
This it is a rather nasty hack, however, not necessarily guaranteed to work in the future if the mechanism of handling the 'canceled' condition should change.

Michael
________________________________________________________________


On 12.10.20 16:58, Stein Rørvik wrote:

> 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%2Fimage
> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no
> %7Cfe249e976b484db1688008d86ec93da1%7Ce1f00f39604145b0b309e0210d8b32af
> %7C1%7C0%7C637381157893713821&amp;sdata=muV3RhcxuZcODLxCIIh5pY6XipIP80
> gdk8hsRLk6P8c%3D&amp;reserved=0
>
> --
> ImageJ mailing list:
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage
> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no
> %7Cfe249e976b484db1688008d86ec93da1%7Ce1f00f39604145b0b309e0210d8b32af
> %7C1%7C0%7C637381157893713821&amp;sdata=muV3RhcxuZcODLxCIIh5pY6XipIP80
> gdk8hsRLk6P8c%3D&amp;reserved=0
>

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Cfe249e976b484db1688008d86ec93da1%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637381157893713821&amp;sdata=muV3RhcxuZcODLxCIIh5pY6XipIP80gdk8hsRLk6P8c%3D&amp;reserved=0

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Stein Rørvik
Edit:

I tried this,

...
script += "gd.showDialog();\n";
script += "IJ.showMessage('Hello');\n";
script += "reply = '';\n";
...

and Hello is shown also when cancel was pressed. So the script execution does not stop.

Stein

-----Original Message-----
Sent: 12. oktober 2020 18:27
Subject: Re: Non-modal dialog with Yes No Cancel

Michael,

Your explanation sounds reasonable, but why does the script indeed return 'Cancel' if run from the command line? I discovered this by accident as I use an external editor which launches ImageJ via the command line when writing or testing new macros.

But I will assume that checking for both an empty string and 'Cancel' will suffice.

Stein

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Michael Schmid
Sent: 12. oktober 2020 17:40
To: [hidden email]
Subject: Re: Non-modal dialog with Yes No Cancel

Hi Stein,

the problem seems to be that <cancel> or <escape> terminates a running macro or (in this case) script, as soon as "gd.wasCanceled()" is called.
Then, the Javascript returns nothing.

You can determine determine the 'canceled' condition by checking for an empty reply String.
This it is a rather nasty hack, however, not necessarily guaranteed to work in the future if the mechanism of handling the 'canceled' condition should change.

Michael
________________________________________________________________


On 12.10.20 16:58, Stein Rørvik wrote:

> 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%2Fimage
> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no
> %7Cfe249e976b484db1688008d86ec93da1%7Ce1f00f39604145b0b309e0210d8b32af
> %7C1%7C0%7C637381157893713821&amp;sdata=muV3RhcxuZcODLxCIIh5pY6XipIP80
> gdk8hsRLk6P8c%3D&amp;reserved=0
>
> --
> ImageJ mailing list:
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage
> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no
> %7Cfe249e976b484db1688008d86ec93da1%7Ce1f00f39604145b0b309e0210d8b32af
> %7C1%7C0%7C637381157893713821&amp;sdata=muV3RhcxuZcODLxCIIh5pY6XipIP80
> gdk8hsRLk6P8c%3D&amp;reserved=0
>

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Cd4735cd3dc6e40df1fbb08d86ecc2f67%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637381170541104317&amp;sdata=I7HiRBrVNX6HYs6Ru%2F0BPlXruExSOntp0tIOLe55ZZQ%3D&amp;reserved=0

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Cd4735cd3dc6e40df1fbb08d86ecc2f67%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637381170541104317&amp;sdata=I7HiRBrVNX6HYs6Ru%2F0BPlXruExSOntp0tIOLe55ZZQ%3D&amp;reserved=0

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Michael Schmid
Hi Stijn,

to make it clear I should have written:

As soon as gd.wasCanceled() is called, the script or macro aborts if
<esc> or <cancel> was pressed.
The relevant piece of code terminating the script is in gd.wasCanceled().

If you have

 > script += "gd.showDialog();\n";
 > script += "IJ.showMessage('Hello');\n";
 > script += "wasCanceled = gd.wasCanceled();\n";
 > script += "IJ.showMessage('Hello again');\n";

and you press <cancel>, the 'Hello' message will be there, but you won't
see the 'Hello again'.

ImageJ determines whether a macro is active by the name of the thread.
For JavaScript that you start from a text editor window, that name is
'JavaScript'.
If you run it with 'eval' from a macro, the thread name will be 'Macro$'.
Im Macro.abort, an exception is thrown if the thread name ends with
'Macro$':
https://github.com/imagej/imagej1/blob/master/ij/Macro.java#L70

I agree that in principle, checking for 'cancel' or an empty String in
your macro should should be more tolerant to future changes than just
checking for an empty string.
Nevertheless, a cleaner solution (though some work for implementing it)
would be adding "Dialog.enableYesNoCancel(yesLabel, noLabel)" and
"Dialog.wasOKed()" macro functions, or adding an optional 'options'
field to getBoolean: getBoolean(message, yesLabel, noLabel, "nonblocking").
Any of these would terminate the macro when the user presses <cancel> or
<esc>.

So far a few thoughts...

Michael
________________________________________________________________
On 12.10.20 18:32, Stein Rørvik wrote:

> Edit:
>
> I tried this,
>
> ...
> script += "gd.showDialog();\n";
> script += "IJ.showMessage('Hello');\n";
> script += "reply = '';\n";
> ...
>
> and Hello is shown also when cancel was pressed. So the script execution does not stop.
>
> Stein
>
> -----Original Message-----
> Sent: 12. oktober 2020 18:27
> Subject: Re: Non-modal dialog with Yes No Cancel
>
> Michael,
>
> Your explanation sounds reasonable, but why does the script indeed return 'Cancel' if run from the command line? I discovered this by accident as I use an external editor which launches ImageJ via the command line when writing or testing new macros.
>
> But I will assume that checking for both an empty string and 'Cancel' will suffice.
>
> Stein
>
> -----Original Message-----
> From: ImageJ Interest Group <[hidden email]> On Behalf Of Michael Schmid
> Sent: 12. oktober 2020 17:40
> To: [hidden email]
> Subject: Re: Non-modal dialog with Yes No Cancel
>
> Hi Stein,
>
> the problem seems to be that <cancel> or <escape> terminates a running macro or (in this case) script, as soon as "gd.wasCanceled()" is called.
> Then, the Javascript returns nothing.
>
> You can determine determine the 'canceled' condition by checking for an empty reply String.
> This it is a rather nasty hack, however, not necessarily guaranteed to work in the future if the mechanism of handling the 'canceled' condition should change.
>
> Michael
> ________________________________________________________________
>
>
> On 12.10.20 16:58, Stein Rørvik wrote:
>> 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%2Fimage
>> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no
>> %7Cfe249e976b484db1688008d86ec93da1%7Ce1f00f39604145b0b309e0210d8b32af
>> %7C1%7C0%7C637381157893713821&amp;sdata=muV3RhcxuZcODLxCIIh5pY6XipIP80
>> gdk8hsRLk6P8c%3D&amp;reserved=0
>>
>> --
>> ImageJ mailing list:
>> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage
>> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no
>> %7Cfe249e976b484db1688008d86ec93da1%7Ce1f00f39604145b0b309e0210d8b32af
>> %7C1%7C0%7C637381157893713821&amp;sdata=muV3RhcxuZcODLxCIIh5pY6XipIP80
>> gdk8hsRLk6P8c%3D&amp;reserved=0
>>
>
> --
> ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Cd4735cd3dc6e40df1fbb08d86ecc2f67%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637381170541104317&amp;sdata=I7HiRBrVNX6HYs6Ru%2F0BPlXruExSOntp0tIOLe55ZZQ%3D&amp;reserved=0
>
> --
> ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Cd4735cd3dc6e40df1fbb08d86ecc2f67%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637381170541104317&amp;sdata=I7HiRBrVNX6HYs6Ru%2F0BPlXruExSOntp0tIOLe55ZZQ%3D&amp;reserved=0
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Fred Damen
In reply to this post by Stein Rørvik
Greetings,

I would like to compile and run a plugin in the currently running imagej
instance from the commandline.  The -o options tends not to work, i.e.,
left over lockfile(s) or lockfile pointing to imagej instance on another
workspace (linux).  Is there a ways to find an imagej instance's port
number from within imagej? The -p option seems to work if you guess the
port number correctly.

Thanks,

Fred

gvim:
map <silent> <F9> :silent w<bar>!imagej -o -e 'run("Compile and
Run...","compile=%:p");'<CR>

On Mon, October 12, 2020 11:27 am, Stein Rørvik wrote:
...
> use an external editor which launches ImageJ via the command line when
> writing or testing new macros.
...

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Kenneth R Sloan-2
In reply to this post by Michael Schmid
Just a side note: why does a macro abort when gd.wasCanceled() is called?  If Cancel is supposed to abort the macro, why wait until the macro asks the question?  Does this mean that "Cancel" does NOTHING if the script doesn't ask the question?
--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Stein Rørvik
In reply to this post by Michael Schmid
Michael,

Thanks for the detailed explanation!

Yes I agree that for now, checking for empty string or 'cancel' should work.
New dialog functions would be great for the future. Modeless dialogs are very handy.

Perhaps an alternative could be to have the option to add additional buttons to the waitForUser function?

Stein

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Michael Schmid
Sent: 12. oktober 2020 19:32
To: [hidden email]
Subject: Re: Non-modal dialog with Yes No Cancel

Hi Stijn,

to make it clear I should have written:

As soon as gd.wasCanceled() is called, the script or macro aborts if <esc> or <cancel> was pressed.
The relevant piece of code terminating the script is in gd.wasCanceled().

If you have

 > script += "gd.showDialog();\n";
 > script += "IJ.showMessage('Hello');\n";  > script += "wasCanceled = gd.wasCanceled();\n";  > script += "IJ.showMessage('Hello again');\n";

and you press <cancel>, the 'Hello' message will be there, but you won't see the 'Hello again'.

ImageJ determines whether a macro is active by the name of the thread.
For JavaScript that you start from a text editor window, that name is 'JavaScript'.
If you run it with 'eval' from a macro, the thread name will be 'Macro$'.
Im Macro.abort, an exception is thrown if the thread name ends with
'Macro$':
https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fimagej%2Fimagej1%2Fblob%2Fmaster%2Fij%2FMacro.java%23L70&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Ca385988e77a74be54c2908d86ed4fc2b%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637381208346450747&amp;sdata=y0IPZbvz2aq8b6OxNjSAU4UYzBuE4ynn7B4PdoQcX8c%3D&amp;reserved=0

I agree that in principle, checking for 'cancel' or an empty String in your macro should should be more tolerant to future changes than just checking for an empty string.
Nevertheless, a cleaner solution (though some work for implementing it) would be adding "Dialog.enableYesNoCancel(yesLabel, noLabel)" and "Dialog.wasOKed()" macro functions, or adding an optional 'options'
field to getBoolean: getBoolean(message, yesLabel, noLabel, "nonblocking").
Any of these would terminate the macro when the user presses <cancel> or <esc>.

So far a few thoughts...

Michael
________________________________________________________________
On 12.10.20 18:32, Stein Rørvik wrote:

> Edit:
>
> I tried this,
>
> ...
> script += "gd.showDialog();\n";
> script += "IJ.showMessage('Hello');\n"; script += "reply = '';\n"; ...
>
> and Hello is shown also when cancel was pressed. So the script execution does not stop.
>
> Stein
>
> -----Original Message-----
> Sent: 12. oktober 2020 18:27
> Subject: Re: Non-modal dialog with Yes No Cancel
>
> Michael,
>
> Your explanation sounds reasonable, but why does the script indeed return 'Cancel' if run from the command line? I discovered this by accident as I use an external editor which launches ImageJ via the command line when writing or testing new macros.
>
> But I will assume that checking for both an empty string and 'Cancel' will suffice.
>
> Stein
>
> -----Original Message-----
> From: ImageJ Interest Group <[hidden email]> On Behalf Of Michael
> Schmid
> Sent: 12. oktober 2020 17:40
> To: [hidden email]
> Subject: Re: Non-modal dialog with Yes No Cancel
>
> Hi Stein,
>
> the problem seems to be that <cancel> or <escape> terminates a running macro or (in this case) script, as soon as "gd.wasCanceled()" is called.
> Then, the Javascript returns nothing.
>
> You can determine determine the 'canceled' condition by checking for an empty reply String.
> This it is a rather nasty hack, however, not necessarily guaranteed to work in the future if the mechanism of handling the 'canceled' condition should change.
>
> Michael
> ________________________________________________________________
>
>
> On 12.10.20 16:58, Stein Rørvik wrote:
>> 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%2Fimag
>> e
>> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.n
>> o
>> %7Cfe249e976b484db1688008d86ec93da1%7Ce1f00f39604145b0b309e0210d8b32a
>> f
>> %7C1%7C0%7C637381157893713821&amp;sdata=muV3RhcxuZcODLxCIIh5pY6XipIP8
>> 0
>> gdk8hsRLk6P8c%3D&amp;reserved=0
>>
>> --
>> ImageJ mailing list:
>> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimag
>> e
>> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.n
>> o
>> %7Cfe249e976b484db1688008d86ec93da1%7Ce1f00f39604145b0b309e0210d8b32a
>> f
>> %7C1%7C0%7C637381157893713821&amp;sdata=muV3RhcxuZcODLxCIIh5pY6XipIP8
>> 0
>> gdk8hsRLk6P8c%3D&amp;reserved=0
>>
>
> --
> ImageJ mailing list:
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage
> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no
> %7Ca385988e77a74be54c2908d86ed4fc2b%7Ce1f00f39604145b0b309e0210d8b32af
> %7C1%7C0%7C637381208346460704&amp;sdata=EtJDa9WO%2FZR9L0wRUzbGumON7rSo
> mLVavy3YqT8hUss%3D&amp;reserved=0
>
> --
> ImageJ mailing list:
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage
> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no
> %7Ca385988e77a74be54c2908d86ed4fc2b%7Ce1f00f39604145b0b309e0210d8b32af
> %7C1%7C0%7C637381208346460704&amp;sdata=EtJDa9WO%2FZR9L0wRUzbGumON7rSo
> mLVavy3YqT8hUss%3D&amp;reserved=0
>
> --
> ImageJ mailing list:
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage
> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no
> %7Ca385988e77a74be54c2908d86ed4fc2b%7Ce1f00f39604145b0b309e0210d8b32af
> %7C1%7C0%7C637381208346460704&amp;sdata=EtJDa9WO%2FZR9L0wRUzbGumON7rSo
> mLVavy3YqT8hUss%3D&amp;reserved=0
>

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7Ca385988e77a74be54c2908d86ed4fc2b%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637381208346460704&amp;sdata=EtJDa9WO%2FZR9L0wRUzbGumON7rSomLVavy3YqT8hUss%3D&amp;reserved=0

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Stein Rørvik
In reply to this post by Fred Damen
I do this today from the command line via a small wrapper macro. I have the "multiple instances listener" on.
The command line options I use from my external editor (EditPlus) is

-macro "C:/Users/steinr/ImageJ/Generic/Macro Compile Plugin.ijm" "$(FilePath)"

And the content of "Macro Compile Plugin.ijm" is

file = getArgument();
print("compile=" + file);
run("Compile and Run...", "compile=" + file);

The use of an extra macro causes a delay of a second or two but it is still much faster than doing it via the GUI. Multiple compiles do not launch a separate instance. I still need to activate ImageJ though as it is not brought to the foreground (and it should not).  

I am doing this on Windows but it should work on any system.

Regarding ports, I usually have three instances of ImageJ running when working at the lab. I launch these using the -port option from my Windows scripts that controls the workflow. So I have a dedicated port number for batch jobs that may take hours to execute, a second one for medium long import-and-export jobs that may take a couple of minutes, and a third "normal" one with the default port number and multiple instance listener active for everything else that was launched without specifying a port number. This works great and there are zero conflicts.

I use a small JavaScript snippet to change the title of each ImageJ main window to be able to separate these, to avoid closing the long job instance by mistake. The two dedicated batch instances have batch mode always on, so that no windows pop up from these. I can inspect their progress in the Log window. I do nearly everything from the command line or registry connected scripts, so that I can just right click a file or folder and specify what to do. The only drawback from this is that there is no easy way to identify which ImageJ instance each of the three Log window belongs to. So I always have something verbose written there, so I can see which job the window is running.

Stein

-----Original Message-----
Sent: 12. oktober 2020 21:54
Subject: Re: Non-modal dialog with Yes No Cancel

Greetings,

I would like to compile and run a plugin in the currently running imagej instance from the commandline.  The -o options tends not to work, i.e., left over lockfile(s) or lockfile pointing to imagej instance on another workspace (linux).  Is there a ways to find an imagej instance's port number from within imagej? The -p option seems to work if you guess the port number correctly.

Thanks,

Fred

gvim:
map <silent> <F9> :silent w<bar>!imagej -o -e 'run("Compile and Run...","compile=%:p");'<CR>

On Mon, October 12, 2020 11:27 am, Stein Rørvik wrote:
...
> use an external editor which launches ImageJ via the command line when
> writing or testing new macros.
...

---

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Michael Schmid
In reply to this post by Kenneth R Sloan-2
On 12.10.20 21:56, Kenneth Sloan wrote:
> Just a side note: why does a macro abort when gd.wasCanceled() is called?  If Cancel is supposed to abort the macro, why wait until the macro asks the question?  Does this mean that "Cancel" does NOTHING if the script doesn't ask the question?

Hi Kenneth,

hmm, I guess that the idea is that user plugins that don't care about
gd.wasCanceled() should also not get the macro interrupted if the user
presses <cancel>.
I fear, however, that plugins that allow the user to press <cancel>, but
to not terminate in that case, will use gd.wasCanceled() anyhow, to
determine whether they should process the dialog input or not.

If you use a dialog in a *macro*, Dialog.show() will check for
gd.wasCanceled(). E.g in the following macro
   Dialog.create("test dialog");
   Dialog.show();
   print("dialog done");
you won't get the 'dialog done' output if the user has pressed <cancel>.

Michael

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Fred Damen
In reply to this post by Stein Rørvik
Greetings Stein,

Thanks.  I didn't realize that the -p option will open a new imagej panel
and assign it the specified port number; obvious now.

As I am able to run the "Compile and Run..." menu item directly from the
command line, I am curious as to why you use a middle man approach?
The GVim.rc setting(imagej commandline) I use is:
map <silent> <F9> :silent w<bar>!imagej -o -e 'run("Compile and
Run...","compile=%:p");'<CR>
which does the equivalent of Ctrl-R inside imagej, albeit using F9 instead.

You can get a handle to the Log window using
WindowManager.getAllNonImageWindows(); and change its title.

Thanks,

Fred

On Mon, October 12, 2020 5:45 pm, Stein Rørvik wrote:

> I do this today from the command line via a small wrapper macro. I have
> the "multiple instances listener" on.
> The command line options I use from my external editor (EditPlus) is
>
> -macro "C:/Users/steinr/ImageJ/Generic/Macro Compile Plugin.ijm"
> "$(FilePath)"
>
> And the content of "Macro Compile Plugin.ijm" is
>
> file = getArgument();
> print("compile=" + file);
> run("Compile and Run...", "compile=" + file);
>
> The use of an extra macro causes a delay of a second or two but it is
> still much faster than doing it via the GUI. Multiple compiles do not
> launch a separate instance. I still need to activate ImageJ though as it
> is not brought to the foreground (and it should not).
>
> I am doing this on Windows but it should work on any system.
>
> Regarding ports, I usually have three instances of ImageJ running when
> working at the lab. I launch these using the -port option from my Windows
> scripts that controls the workflow. So I have a dedicated port number for
> batch jobs that may take hours to execute, a second one for medium long
> import-and-export jobs that may take a couple of minutes, and a third
> "normal" one with the default port number and multiple instance listener
> active for everything else that was launched without specifying a port
> number. This works great and there are zero conflicts.
>
> I use a small JavaScript snippet to change the title of each ImageJ main
> window to be able to separate these, to avoid closing the long job
> instance by mistake. The two dedicated batch instances have batch mode
> always on, so that no windows pop up from these. I can inspect their
> progress in the Log window. I do nearly everything from the command line
> or registry connected scripts, so that I can just right click a file or
> folder and specify what to do. The only drawback from this is that there
> is no easy way to identify which ImageJ instance each of the three Log
> window belongs to. So I always have something verbose written there, so I
> can see which job the window is running.
>
> Stein
>
> -----Original Message-----
> Sent: 12. oktober 2020 21:54
> Subject: Re: Non-modal dialog with Yes No Cancel
>
> Greetings,
>
> I would like to compile and run a plugin in the currently running imagej
> instance from the commandline.  The -o options tends not to work, i.e.,
> left over lockfile(s) or lockfile pointing to imagej instance on another
> workspace (linux).  Is there a ways to find an imagej instance's port
> number from within imagej? The -p option seems to work if you guess the
> port number correctly.
>
> Thanks,
>
> Fred
>
> gvim:
> map <silent> <F9> :silent w<bar>!imagej -o -e 'run("Compile and
> Run...","compile=%:p");'<CR>
>
> On Mon, October 12, 2020 11:27 am, Stein Rørvik wrote:
> ...
>> use an external editor which launches ImageJ via the command line when
>> writing or testing new macros.
> ...
>
> ---
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Stein Rørvik
Yes, the -p option will make the port number refer to a specific ImageJ instance, so you can chain several commands to that. And no port specified means new instance every time, or same instance every time (and not the same as the one specified with -p) if you have instance listener enabled in Options. This behaviour is extremely useful in a pipelined multi-tasking scenario as the one I described.

The reason I have a separate compile-and-run macro is a Windows issue: The program I am using passes the filepath to the command line using single backslashes that are lost (interpreted as escape characters) when using the -eval command. But the -macro command handles this correctly, so I can use getArgument() to retrieve the filename. If I type the command manually on the command line I can use forward slashes with -eval command and then run("Compile and Run..." works without a macro, but that is not an option in the editor I am using. On a Linux or Mac system the intermediate macro is probably not needed.

Stein

-----Original Message-----
Sent: 13. oktober 2020 18:43
Subject: Re: Non-modal dialog with Yes No Cancel

Greetings Stein,

Thanks.  I didn't realize that the -p option will open a new imagej panel and assign it the specified port number; obvious now.

As I am able to run the "Compile and Run..." menu item directly from the command line, I am curious as to why you use a middle man approach?
The GVim.rc setting(imagej commandline) I use is:
map <silent> <F9> :silent w<bar>!imagej -o -e 'run("Compile and Run...","compile=%:p");'<CR> which does the equivalent of Ctrl-R inside imagej, albeit using F9 instead.

You can get a handle to the Log window using WindowManager.getAllNonImageWindows(); and change its title.

Thanks,

Fred

On Mon, October 12, 2020 5:45 pm, Stein Rørvik wrote:

> I do this today from the command line via a small wrapper macro. I
> have the "multiple instances listener" on.
> The command line options I use from my external editor (EditPlus) is
>
> -macro "C:/Users/steinr/ImageJ/Generic/Macro Compile Plugin.ijm"
> "$(FilePath)"
>
> And the content of "Macro Compile Plugin.ijm" is
>
> file = getArgument();
> print("compile=" + file);
> run("Compile and Run...", "compile=" + file);
>
> The use of an extra macro causes a delay of a second or two but it is
> still much faster than doing it via the GUI. Multiple compiles do not
> launch a separate instance. I still need to activate ImageJ though as
> it is not brought to the foreground (and it should not).
>
> I am doing this on Windows but it should work on any system.
>
> Regarding ports, I usually have three instances of ImageJ running when
> working at the lab. I launch these using the -port option from my
> Windows scripts that controls the workflow. So I have a dedicated port
> number for batch jobs that may take hours to execute, a second one for
> medium long import-and-export jobs that may take a couple of minutes,
> and a third "normal" one with the default port number and multiple
> instance listener active for everything else that was launched without
> specifying a port number. This works great and there are zero conflicts.
>
> I use a small JavaScript snippet to change the title of each ImageJ
> main window to be able to separate these, to avoid closing the long
> job instance by mistake. The two dedicated batch instances have batch
> mode always on, so that no windows pop up from these. I can inspect
> their progress in the Log window. I do nearly everything from the
> command line or registry connected scripts, so that I can just right
> click a file or folder and specify what to do. The only drawback from
> this is that there is no easy way to identify which ImageJ instance
> each of the three Log window belongs to. So I always have something
> verbose written there, so I can see which job the window is running.
>
> Stein
>
> -----Original Message-----
> Sent: 12. oktober 2020 21:54
> Subject: Re: Non-modal dialog with Yes No Cancel
>
> Greetings,
>
> I would like to compile and run a plugin in the currently running
> imagej instance from the commandline.  The -o options tends not to
> work, i.e., left over lockfile(s) or lockfile pointing to imagej
> instance on another workspace (linux).  Is there a ways to find an
> imagej instance's port number from within imagej? The -p option seems
> to work if you guess the port number correctly.
>
> Thanks,
>
> Fred
>
> gvim:
> map <silent> <F9> :silent w<bar>!imagej -o -e 'run("Compile and
> Run...","compile=%:p");'<CR>
>
> On Mon, October 12, 2020 11:27 am, Stein Rørvik wrote:
> ...
>> use an external editor which launches ImageJ via the command line
>> when writing or testing new macros.
> ...
>
> ---
>
> --
> ImageJ mailing list:
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage
> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no
> %7C26163f642c534eea4aca08d86f977183%7Ce1f00f39604145b0b309e0210d8b32af
> %7C1%7C0%7C637382043540302398&amp;sdata=wFA5refdQClMPjs8k6AnQjOxGzmtd6
> PP2uTPlnkiVnM%3D&amp;reserved=0
>

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7C26163f642c534eea4aca08d86f977183%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637382043540302398&amp;sdata=wFA5refdQClMPjs8k6AnQjOxGzmtd6PP2uTPlnkiVnM%3D&amp;reserved=0

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-modal dialog with Yes No Cancel

Stein Rørvik
Edit:

I re-read the documentation for the command line and see this:
  -port
     Specifies the port ImageJ uses to determine if another instance is running
     Example 1: -port1 (use default port address + 1)
     Example 2: -port2 (use default port address + 2)
     Example 3: -port0 (don't check for another instance)

So what I described only works when the instance listener is enabled. This means that if ImageJ was launched on with option -port2, that instance will grab new commands who were also launched using -port2 option.

Stein

-----Original Message-----
Sent: 13. oktober 2020 23:26
Subject: Re: Non-modal dialog with Yes No Cancel

Yes, the -p option will make the port number refer to a specific ImageJ instance, so you can chain several commands to that. And no port specified means new instance every time, or same instance every time (and not the same as the one specified with -p) if you have instance listener enabled in Options. This behaviour is extremely useful in a pipelined multi-tasking scenario as the one I described.

The reason I have a separate compile-and-run macro is a Windows issue: The program I am using passes the filepath to the command line using single backslashes that are lost (interpreted as escape characters) when using the -eval command. But the -macro command handles this correctly, so I can use getArgument() to retrieve the filename. If I type the command manually on the command line I can use forward slashes with -eval command and then run("Compile and Run..." works without a macro, but that is not an option in the editor I am using. On a Linux or Mac system the intermediate macro is probably not needed.

Stein

-----Original Message-----
Sent: 13. oktober 2020 18:43
Subject: Re: Non-modal dialog with Yes No Cancel

Greetings Stein,

Thanks.  I didn't realize that the -p option will open a new imagej panel and assign it the specified port number; obvious now.

As I am able to run the "Compile and Run..." menu item directly from the command line, I am curious as to why you use a middle man approach?
The GVim.rc setting(imagej commandline) I use is:
map <silent> <F9> :silent w<bar>!imagej -o -e 'run("Compile and Run...","compile=%:p");'<CR> which does the equivalent of Ctrl-R inside imagej, albeit using F9 instead.

You can get a handle to the Log window using WindowManager.getAllNonImageWindows(); and change its title.

Thanks,

Fred

On Mon, October 12, 2020 5:45 pm, Stein Rørvik wrote:

> I do this today from the command line via a small wrapper macro. I
> have the "multiple instances listener" on.
> The command line options I use from my external editor (EditPlus) is
>
> -macro "C:/Users/steinr/ImageJ/Generic/Macro Compile Plugin.ijm"
> "$(FilePath)"
>
> And the content of "Macro Compile Plugin.ijm" is
>
> file = getArgument();
> print("compile=" + file);
> run("Compile and Run...", "compile=" + file);
>
> The use of an extra macro causes a delay of a second or two but it is
> still much faster than doing it via the GUI. Multiple compiles do not
> launch a separate instance. I still need to activate ImageJ though as
> it is not brought to the foreground (and it should not).
>
> I am doing this on Windows but it should work on any system.
>
> Regarding ports, I usually have three instances of ImageJ running when
> working at the lab. I launch these using the -port option from my
> Windows scripts that controls the workflow. So I have a dedicated port
> number for batch jobs that may take hours to execute, a second one for
> medium long import-and-export jobs that may take a couple of minutes,
> and a third "normal" one with the default port number and multiple
> instance listener active for everything else that was launched without
> specifying a port number. This works great and there are zero conflicts.
>
> I use a small JavaScript snippet to change the title of each ImageJ
> main window to be able to separate these, to avoid closing the long
> job instance by mistake. The two dedicated batch instances have batch
> mode always on, so that no windows pop up from these. I can inspect
> their progress in the Log window. I do nearly everything from the
> command line or registry connected scripts, so that I can just right
> click a file or folder and specify what to do. The only drawback from
> this is that there is no easy way to identify which ImageJ instance
> each of the three Log window belongs to. So I always have something
> verbose written there, so I can see which job the window is running.
>
> Stein
>
> -----Original Message-----
> Sent: 12. oktober 2020 21:54
> Subject: Re: Non-modal dialog with Yes No Cancel
>
> Greetings,
>
> I would like to compile and run a plugin in the currently running
> imagej instance from the commandline.  The -o options tends not to
> work, i.e., left over lockfile(s) or lockfile pointing to imagej
> instance on another workspace (linux).  Is there a ways to find an
> imagej instance's port number from within imagej? The -p option seems
> to work if you guess the port number correctly.
>
> Thanks,
>
> Fred
>
> gvim:
> map <silent> <F9> :silent w<bar>!imagej -o -e 'run("Compile and
> Run...","compile=%:p");'<CR>
>
> On Mon, October 12, 2020 11:27 am, Stein Rørvik wrote:
> ...
>> use an external editor which launches ImageJ via the command line
>> when writing or testing new macros.
> ...
>
> ---
>
> --
> ImageJ mailing list:
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage
> j.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no
> %7C26163f642c534eea4aca08d86f977183%7Ce1f00f39604145b0b309e0210d8b32af
> %7C1%7C0%7C637382043540302398&amp;sdata=wFA5refdQClMPjs8k6AnQjOxGzmtd6
> PP2uTPlnkiVnM%3D&amp;reserved=0
>

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7C70c81f4a8ffb431acb8008d86fbefaf2%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637382213339037376&amp;sdata=deB%2BfYYZL17qS%2FuFbvXMQ0RUqLBht4mcUyroEXtMsu4%3D&amp;reserved=0

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7Cstein.rorvik%40sintef.no%7C70c81f4a8ffb431acb8008d86fbefaf2%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637382213339037376&amp;sdata=deB%2BfYYZL17qS%2FuFbvXMQ0RUqLBht4mcUyroEXtMsu4%3D&amp;reserved=0

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