Plugin parameters for macros without using GenericDialog

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

Plugin parameters for macros without using GenericDialog

Josh Doe
Hi,
I have a file import plugin that I've written which shows a dialog
where the user can select the start frame, number of frames, skip
interval, and whether to open as a virtual stack. I have logic in the
dialog so that users can't specify incorrect values, and changing one
of nFrames or endFrame will update the other. I can't do this with
GenericDialog, so have used a JDialog. However this means I can't
record a macro using this plugin, and I can't execute this plugin from
a macro by specifying the parameters.

How can a plugin accept parameters from macros and also have commands recorded?

For recording macros, I've looked at Recorder, and it seems I could
emulate what GenericDialog does by calling setCommand(),
recordOption() and then saveCommand(). However I'm not sure how my
plugin can get the values when run("MyPlugin", "nFrames=50
startFrame=1 ...") is called.

Thanks,
-Josh
Reply | Threaded
Open this post in threaded view
|

Re: Plugin parameters for macros without using GenericDialog

Michael Schmid
Hi Josh,

you can have a GenericDialog where the user cannot enter invalid data  
- if you implement the DialogListener interface, you can disable  
pressing 'OK' if the data are not OK by returning false.

GenericDialog also has methods to get vectors with references to the  
input elements (TextFields, Checkboxes, etc.), which will help you in  
such a case.

There is only one nasty bug in Java on Mac OS X that may interfere  
with such programs (whether GenericDialog or any other dialog):
If there are two modifications of elements in a GenericDialog, it may  
happen that only one is done, the other has to wait for the next  
update of the dialog. So, if you change e.g. some text or enable/
disable a dialog element in response to user action, and then the OK  
button should be enabled/disabled, it may happen that the OK button  
remains in the wrong state. This can be fixed only by introducing  
some delays (50...100 millisec) before the last change is done. One  
typical workaround that I use is alternatingly adding and removing a  
space at the end of some static text 100 ms after the last change to  
force updating the dialog.

Michael
________________________________________________________________

On 24 Aug 2011, at 20:38, Josh Doe wrote:

> Hi,
> I have a file import plugin that I've written which shows a dialog
> where the user can select the start frame, number of frames, skip
> interval, and whether to open as a virtual stack. I have logic in the
> dialog so that users can't specify incorrect values, and changing one
> of nFrames or endFrame will update the other. I can't do this with
> GenericDialog, so have used a JDialog. However this means I can't
> record a macro using this plugin, and I can't execute this plugin from
> a macro by specifying the parameters.
>
> How can a plugin accept parameters from macros and also have  
> commands recorded?
>
> For recording macros, I've looked at Recorder, and it seems I could
> emulate what GenericDialog does by calling setCommand(),
> recordOption() and then saveCommand(). However I'm not sure how my
> plugin can get the values when run("MyPlugin", "nFrames=50
> startFrame=1 ...") is called.
>
> Thanks,
> -Josh
Reply | Threaded
Open this post in threaded view
|

Re: Plugin parameters for macros without using GenericDialog

Josh Doe
Hi Michael,
Thanks for the suggestion. As it wasn't clear to me how to do what you
suggested with GenericDialog, and I didn't care as much for the record
functionality as I did for the macro executing functionality, I took
the easy route and implemented a setProperty method like MTrack2 does:
http://valelab.ucsf.edu/~nico/IJplugins/MTrack2.html

Thanks,
-Josh

On Wed, Aug 24, 2011 at 2:58 PM, Michael Schmid <[hidden email]> wrote:

> Hi Josh,
>
> you can have a GenericDialog where the user cannot enter invalid data - if
> you implement the DialogListener interface, you can disable pressing 'OK' if
> the data are not OK by returning false.
>
> GenericDialog also has methods to get vectors with references to the input
> elements (TextFields, Checkboxes, etc.), which will help you in such a case.
>
> There is only one nasty bug in Java on Mac OS X that may interfere with such
> programs (whether GenericDialog or any other dialog):
> If there are two modifications of elements in a GenericDialog, it may happen
> that only one is done, the other has to wait for the next update of the
> dialog. So, if you change e.g. some text or enable/disable a dialog element
> in response to user action, and then the OK button should be
> enabled/disabled, it may happen that the OK button remains in the wrong
> state. This can be fixed only by introducing some delays (50...100 millisec)
> before the last change is done. One typical workaround that I use is
> alternatingly adding and removing a space at the end of some static text 100
> ms after the last change to force updating the dialog.
>
> Michael
> ________________________________________________________________
>
> On 24 Aug 2011, at 20:38, Josh Doe wrote:
>
>> Hi,
>> I have a file import plugin that I've written which shows a dialog
>> where the user can select the start frame, number of frames, skip
>> interval, and whether to open as a virtual stack. I have logic in the
>> dialog so that users can't specify incorrect values, and changing one
>> of nFrames or endFrame will update the other. I can't do this with
>> GenericDialog, so have used a JDialog. However this means I can't
>> record a macro using this plugin, and I can't execute this plugin from
>> a macro by specifying the parameters.
>>
>> How can a plugin accept parameters from macros and also have commands
>> recorded?
>>
>> For recording macros, I've looked at Recorder, and it seems I could
>> emulate what GenericDialog does by calling setCommand(),
>> recordOption() and then saveCommand(). However I'm not sure how my
>> plugin can get the values when run("MyPlugin", "nFrames=50
>> startFrame=1 ...") is called.
>>
>> Thanks,
>> -Josh
>