Macros for a plugin.

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

Macros for a plugin.

Edward Rosten
I'm currently writing a plugin, which I would like to make work with macros.

At the moment the workflow goes something like this:

1 run plugin from menu
2 dialog box comes up (derived from GenericDialog), and a bunch of
values are filled in
3 Press OK
4 Save-as dialog pops up (the analysis is long running and writes out
a log as it goes along)
5 Press OK (plugin starts, and pops up a SWT window showing the
current state of the analysis)

I tried recording a macro of those actions to see what happened, and
the macro essentially calls the plugin with the file to save in.

What I would like to happen when a macro is recorded is that it
records a call to the plugin with all the information from step 2
recorded. Is there any way of doing that?

Also, are there some functions for parsing the arguments passed by macros?

Regards

-Ed
Reply | Threaded
Open this post in threaded view
|

Re: Macros for a plugin.

Michael Schmid
Hi Ed,

a plugin that appears somewhere in a menu and has a Generic Dialog should nicely collaborate with macro recording and execution.
That is, with macro recording, you should get someting like

  run("My Plugin", "value1=15 value2=16 text1=abc");

You have to press 'OK' for recording and the plugin has to read the values by the usual getNextNumber() etc. methods of GenericDialog.
Macro recording won't work if your plugin terminates with an exception. There might be also a problem if another command is executed from the menu before your plugin has finished.

In a macro, the arguments will be sent to the GenericDialog automatically, so you need not parse them. The getNextNumber() etc. methods will deliver the values to your plugin. In the example above, it should behave as if the user had entered '15' into the 'value1' field of the GenericDialog, etc.

Note that only the first word of each label is recorded, so it won't work if you have fields 'value 1' and 'value 2'; both would be recorded as 'value'.
'value_1' and 'value_2' will work (and the underscore will be invisible when the dialog is displayed). Also, labels are not case sensitive.


Hope this helps,

Michael
________________________________________________________________

On Mar 16, 2012, at 15:27, Edward Rosten wrote:

> I'm currently writing a plugin, which I would like to make work with macros.
>
> At the moment the workflow goes something like this:
>
> 1 run plugin from menu
> 2 dialog box comes up (derived from GenericDialog), and a bunch of
> values are filled in
> 3 Press OK
> 4 Save-as dialog pops up (the analysis is long running and writes out
> a log as it goes along)
> 5 Press OK (plugin starts, and pops up a SWT window showing the
> current state of the analysis)
>
> I tried recording a macro of those actions to see what happened, and
> the macro essentially calls the plugin with the file to save in.
>
> What I would like to happen when a macro is recorded is that it
> records a call to the plugin with all the information from step 2
> recorded. Is there any way of doing that?
>
> Also, are there some functions for parsing the arguments passed by macros?
>
> Regards
>
> -Ed
Reply | Threaded
Open this post in threaded view
|

Re: Macros for a plugin.

Edward Rosten
Hi Michael,

On Fri, Mar 16, 2012 at 4:56 PM, Michael Schmid <[hidden email]> wrote:
> Hi Ed,
>
> a plugin that appears somewhere in a menu and has a Generic Dialog should nicely collaborate with macro recording and execution.
> That is, with macro recording, you should get someting like
>
>  run("My Plugin", "value1=15 value2=16 text1=abc");
>
> You have to press 'OK' for recording and the plugin has to read the values by the usual getNextNumber() etc. methods of GenericDialog.
> Macro recording won't work if your plugin terminates with an exception. There might be also a problem if another command is executed from the menu before your plugin has finished.

I think the problem is that in my case I pop up two dialog boxes,
first a generic one, then a file save one. The macro only seems to
remember the value from the last box, which is the file save name.

Is there a way to integrate the save-as bit into the main
genericdialog, or to tell the macro system manually what values I want
to be recorded?


Regards

-Ed
Reply | Threaded
Open this post in threaded view
|

Re: Macros for a plugin.

ctrueden
Hi Ed,

I think the problem is that in my case I pop up two dialog boxes,
> first a generic one, then a file save one. The macro only seems to
> remember the value from the last box, which is the file save name.
>

ImageJ's macro recording logic aggregates values from multiple dialog boxes
such as these. We use this with the Bio-Formats Importer and pop up several
GenericDialogs and an OpenDialog), all of which get combined into the final
recorded macro command.

Perhaps if you share your plugin code we can better diagnose what is going
wrong.

Regards,
Curtis


On Fri, Mar 16, 2012 at 12:26 PM, Edward Rosten <[hidden email]> wrote:

> Hi Michael,
>
> On Fri, Mar 16, 2012 at 4:56 PM, Michael Schmid <[hidden email]>
> wrote:
> > Hi Ed,
> >
> > a plugin that appears somewhere in a menu and has a Generic Dialog
> should nicely collaborate with macro recording and execution.
> > That is, with macro recording, you should get someting like
> >
> >  run("My Plugin", "value1=15 value2=16 text1=abc");
> >
> > You have to press 'OK' for recording and the plugin has to read the
> values by the usual getNextNumber() etc. methods of GenericDialog.
> > Macro recording won't work if your plugin terminates with an exception.
> There might be also a problem if another command is executed from the menu
> before your plugin has finished.
>
> I think the problem is that in my case I pop up two dialog boxes,
> first a generic one, then a file save one. The macro only seems to
> remember the value from the last box, which is the file save name.
>
> Is there a way to integrate the save-as bit into the main
> genericdialog, or to tell the macro system manually what values I want
> to be recorded?
>
>
> Regards
>
> -Ed
>
Reply | Threaded
Open this post in threaded view
|

Re: Macros for a plugin.

ctrueden
Hi Ed,

Here is a minimal example demonstrating the parameter aggregation I
mentioned:

--snip--
import ij.IJ;
import ij.gui.GenericDialog;
import ij.io.SaveDialog;
import ij.plugin.PlugIn;

import java.io.File;

public class Test_Dialogs implements PlugIn {
    public void run(String arg) {
        GenericDialog gd = new GenericDialog("Parameters");
        gd.addMessage("Please fill out this form.");
        gd.addNumericField("Number", 2.7, 3);
        gd.addStringField("Text", "Change me");
        gd.showDialog();
        if (gd.wasCanceled()) return;

        double number = gd.getNextNumber();
        String text = gd.getNextString();

        SaveDialog save = new SaveDialog("File to save", "output", ".txt");
        File file = new File(save.getDirectory(), save.getFileName());

        IJ.log("number = " + number + ", text = " + text +
            ", file = " + file.getAbsolutePath());
    }
}
--snap--

When I run this program with default values with the Macro Recorder turned
on, it records the following string:

run("Test Dialogs", "number=2.700 text=[Change me]
file=/Users/curtis/Desktop/output.txt");

Regards,
Curtis


On Fri, Mar 16, 2012 at 12:50 PM, Curtis Rueden <[hidden email]> wrote:

> Hi Ed,
>
>
> I think the problem is that in my case I pop up two dialog boxes,
>> first a generic one, then a file save one. The macro only seems to
>> remember the value from the last box, which is the file save name.
>>
>
> ImageJ's macro recording logic aggregates values from multiple dialog
> boxes such as these. We use this with the Bio-Formats Importer and pop up
> several GenericDialogs and an OpenDialog), all of which get combined into
> the final recorded macro command.
>
> Perhaps if you share your plugin code we can better diagnose what is going
> wrong.
>
> Regards,
> Curtis
>
>
>
> On Fri, Mar 16, 2012 at 12:26 PM, Edward Rosten <[hidden email]>wrote:
>
>> Hi Michael,
>>
>> On Fri, Mar 16, 2012 at 4:56 PM, Michael Schmid <[hidden email]>
>> wrote:
>> > Hi Ed,
>> >
>> > a plugin that appears somewhere in a menu and has a Generic Dialog
>> should nicely collaborate with macro recording and execution.
>> > That is, with macro recording, you should get someting like
>> >
>> >  run("My Plugin", "value1=15 value2=16 text1=abc");
>> >
>> > You have to press 'OK' for recording and the plugin has to read the
>> values by the usual getNextNumber() etc. methods of GenericDialog.
>> > Macro recording won't work if your plugin terminates with an exception.
>> There might be also a problem if another command is executed from the menu
>> before your plugin has finished.
>>
>> I think the problem is that in my case I pop up two dialog boxes,
>> first a generic one, then a file save one. The macro only seems to
>> remember the value from the last box, which is the file save name.
>>
>> Is there a way to integrate the save-as bit into the main
>> genericdialog, or to tell the macro system manually what values I want
>> to be recorded?
>>
>>
>> Regards
>>
>> -Ed
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Macros for a plugin.

Edward Rosten-2
Hi Curtis,

Thanks for the sample code. I'll get it up and running and see if
anything pops out in an obvious way.

Regards

-Ed


On Fri, Mar 16, 2012 at 9:14 PM, Curtis Rueden <[hidden email]> wrote:

> Hi Ed,
>
> Here is a minimal example demonstrating the parameter aggregation I
> mentioned:
>
> --snip--
> import ij.IJ;
> import ij.gui.GenericDialog;
> import ij.io.SaveDialog;
> import ij.plugin.PlugIn;
>
> import java.io.File;
>
> public class Test_Dialogs implements PlugIn {
>    public void run(String arg) {
>        GenericDialog gd = new GenericDialog("Parameters");
>        gd.addMessage("Please fill out this form.");
>        gd.addNumericField("Number", 2.7, 3);
>        gd.addStringField("Text", "Change me");
>        gd.showDialog();
>        if (gd.wasCanceled()) return;
>
>        double number = gd.getNextNumber();
>        String text = gd.getNextString();
>
>        SaveDialog save = new SaveDialog("File to save", "output", ".txt");
>        File file = new File(save.getDirectory(), save.getFileName());
>
>        IJ.log("number = " + number + ", text = " + text +
>            ", file = " + file.getAbsolutePath());
>    }
> }
> --snap--
>
> When I run this program with default values with the Macro Recorder turned
> on, it records the following string:
>
> run("Test Dialogs", "number=2.700 text=[Change me]
> file=/Users/curtis/Desktop/output.txt");
>
> Regards,
> Curtis
>
>
> On Fri, Mar 16, 2012 at 12:50 PM, Curtis Rueden <[hidden email]> wrote:
>
>> Hi Ed,
>>
>>
>> I think the problem is that in my case I pop up two dialog boxes,
>>> first a generic one, then a file save one. The macro only seems to
>>> remember the value from the last box, which is the file save name.
>>>
>>
>> ImageJ's macro recording logic aggregates values from multiple dialog
>> boxes such as these. We use this with the Bio-Formats Importer and pop up
>> several GenericDialogs and an OpenDialog), all of which get combined into
>> the final recorded macro command.
>>
>> Perhaps if you share your plugin code we can better diagnose what is going
>> wrong.
>>
>> Regards,
>> Curtis
>>
>>
>>
>> On Fri, Mar 16, 2012 at 12:26 PM, Edward Rosten <[hidden email]>wrote:
>>
>>> Hi Michael,
>>>
>>> On Fri, Mar 16, 2012 at 4:56 PM, Michael Schmid <[hidden email]>
>>> wrote:
>>> > Hi Ed,
>>> >
>>> > a plugin that appears somewhere in a menu and has a Generic Dialog
>>> should nicely collaborate with macro recording and execution.
>>> > That is, with macro recording, you should get someting like
>>> >
>>> >  run("My Plugin", "value1=15 value2=16 text1=abc");
>>> >
>>> > You have to press 'OK' for recording and the plugin has to read the
>>> values by the usual getNextNumber() etc. methods of GenericDialog.
>>> > Macro recording won't work if your plugin terminates with an exception.
>>> There might be also a problem if another command is executed from the menu
>>> before your plugin has finished.
>>>
>>> I think the problem is that in my case I pop up two dialog boxes,
>>> first a generic one, then a file save one. The macro only seems to
>>> remember the value from the last box, which is the file save name.
>>>
>>> Is there a way to integrate the save-as bit into the main
>>> genericdialog, or to tell the macro system manually what values I want
>>> to be recorded?
>>>
>>>
>>> Regards
>>>
>>> -Ed
>>>
>>
>>



--
(You can't go wrong with psycho-rats.)  (http://mi.eng.cam.ac.uk/~er258)

/d{def}def/f{/Times findfont s scalefont setfont}d/s{11}d/r{roll}d f 2/m
{moveto}d -1 r 230 350 m 0 1 179{1 index show 88 rotate 4 mul 0 rmoveto}
 for /s 12 d f pop 235 420 translate 0 0 moveto 1 2 scale show showpage
Reply | Threaded
Open this post in threaded view
|

Re: Macros for a plugin.

Edward Rosten-2
In reply to this post by ctrueden
Hi Curtis,

Thanks again for the code sample.

It seems that the reason that macro recording wasn't working was
because I wasn't using getNextNumber() in genericDialog, instead I was
using getNumericFields() manually. It would appear that the macro
recording mechanism only works correctly if the getNext methods are
used.


Regards

-Ed


On 16 March 2012 21:14, Curtis Rueden <[hidden email]> wrote:

> Hi Ed,
>
> Here is a minimal example demonstrating the parameter aggregation I
> mentioned:
>
> --snip--
> import ij.IJ;
> import ij.gui.GenericDialog;
> import ij.io.SaveDialog;
> import ij.plugin.PlugIn;
>
> import java.io.File;
>
> public class Test_Dialogs implements PlugIn {
>    public void run(String arg) {
>        GenericDialog gd = new GenericDialog("Parameters");
>        gd.addMessage("Please fill out this form.");
>        gd.addNumericField("Number", 2.7, 3);
>        gd.addStringField("Text", "Change me");
>        gd.showDialog();
>        if (gd.wasCanceled()) return;
>
>        double number = gd.getNextNumber();
>        String text = gd.getNextString();
>
>        SaveDialog save = new SaveDialog("File to save", "output", ".txt");
>        File file = new File(save.getDirectory(), save.getFileName());
>
>        IJ.log("number = " + number + ", text = " + text +
>            ", file = " + file.getAbsolutePath());
>    }
> }
> --snap--
>
> When I run this program with default values with the Macro Recorder turned
> on, it records the following string:
>
> run("Test Dialogs", "number=2.700 text=[Change me]
> file=/Users/curtis/Desktop/output.txt");
>
> Regards,
> Curtis
>