<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hi Adrian, Jan and Curtis
<div class=""><br class="">
</div>
<div class="">I went through the tutorials and found about the initialisation method. Curtis was absolutely right about what I wanted to do. Thanks for the detailed explanations. In fact I was aiming for the use case 4) update parameter attributes several times
 during callbacks. Since the file chooser could have its input changed several times (typically a click accident, mistake of choice or such), It would be odd for the user if the UI get’s updated only once.</div>
<div class=""><br class="">
</div>
<div class="">The alternative of course is to use an OpenDialog previous to the configuration dialog. Or to program the the dialog from scratch (but this certainly does not improve reusability neither).</div>
<div class=""><br class="">
</div>
<div class="">The proposal <a href="https://github.com/scijava/scijava-common/issues/181" class="">https://github.com/scijava/scijava-common/issues/181</a> sounds like a promising idea to me. </div>
<div class=""><br class="">
</div>
<div class="">Felix</div>
<div class=""><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On 22 Aug 2015, at 6:10 , Curtis Rueden <<a href="mailto:ctrueden@wisc.edu" class="">ctrueden@wisc.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">Hi Adrian,
<div class=""><br class="">
</div>
<div class="">
<div class="">> Doesn't that allow doing what Felix would like to do, by populating</div>
<div class="">> the combobox through such an initialiser ?</div>
</div>
<div class=""><br class="">
</div>
<div class="">I think what Felix wants is to set a parameter's "choices" attribute -- i.e., the values that will appear in the input harvester UI's dropdown list box.</div>
<div class=""><br class="">
</div>
<div class="">It can be done with a DynamicCommand, but right now it only works from an initializer, not from a callback. So if you want to populate the choice once from, say, the active Dataset, it works. But if you want to update the choices e.g. every time
 the user moves a numerical slider, it will not work because the UI will not update.</div>
<div class=""><br class="">
</div>
<div class="">See also:</div>
<div class="">* <a href="https://github.com/scijava/scijava-common/issues/180" class="">
https://github.com/scijava/scijava-common/issues/180</a><br class="">
</div>
<div class="">
<div class="">* <a href="https://github.com/scijava/scijava-common/issues/181" class="">
https://github.com/scijava/scijava-common/issues/181</a><br class="">
</div>
</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">> Are the parameters populated/initialised in the order they appear? In</div>
<div class="">> particular, is the initialisation done serially or can there be</div>
<div class="">> parallel execution of initialisers ?</div>
</div>
<div class=""><br class="">
</div>
<div class="">Initialization is currently implemented serially [1].</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">> I have parameters a, b, c whose initialisation depend on a common</div>
<div class="">> calculation (depending on the image gotten through a previous</div>
<div class="">> @Parameter ImagePlus imp): can I do this calculation in the</div>
<div class="">> initialiser for the first parameter a, and then in the initialisers of</div>
<div class="">> b and c rely on the fact that the calculation was already done ?</div>
</div>
<div class=""><br class="">
</div>
<div class="">Perhaps simplest at the moment would be to give your command a global initializer -- i.e., set the initializer method in the @Plugin annotation itself, rather than on specific parameters. The ImagePlus will be populated by a preprocessor _before_
 the initialize method is called, so when your global initializer gets called you will already have access to the ImagePlus.</div>
<div class=""><br class="">
</div>
<div class="">But again, scijava/scijava-common#181 is very relevant here.</div>
<div class=""><br class="">
</div>
<div class="">Regards,</div>
<div class="">Curtis</div>
<div class=""><br class="">
</div>
<div class="">[1] <a href="https://github.com/scijava/scijava-common/blob/scijava-common-2.42.2/src/main/java/org/scijava/module/AbstractModule.java#L75-L88" class="">
https://github.com/scijava/scijava-common/blob/scijava-common-2.42.2/src/main/java/org/scijava/module/AbstractModule.java#L75-L88</a></div>
</div>
<div class="gmail_extra"><br class="">
<div class="gmail_quote">On Fri, Aug 21, 2015 at 6:18 AM, Adrian Daerr <span dir="ltr" class="">
<<a href="mailto:adrian.daerr@univ-paris-diderot.fr" target="_blank" class="">adrian.daerr@univ-paris-diderot.fr</a>></span> wrote:<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Curtis, Felix, Jan, and others,<br class="">
<br class="">
In the CommandWithPreview tutorial example[*] that Curtis sent to<br class="">
the list a few weeks back, there is a @Parameter which is<br class="">
initialised to a value depending on the initialisation of another<br class="">
parameter:<br class="">
<br class="">
@Parameter private ImagePlus imp;<br class="">
<br class="">
@Parameter(persist = false, initializer = "initTitle") private String title;<br class="">
<br class="">
/** Initializes the {@link #title} parameter. */<br class="">
protected void initTitle() {<br class="">
        title = initialTitle = imp.getTitle();<br class="">
}<br class="">
<br class="">
[*]<br class="">
<a href="https://github.com/imagej/imagej-tutorials/blob/master/commands-with-preview/src/main/java/CommandWithPreview.java" rel="noreferrer" target="_blank" class="">https://github.com/imagej/imagej-tutorials/blob/master/commands-with-preview/src/main/java/CommandWithPreview.java</a><br class="">
<br class="">
Doesn't that allow doing what Felix would like to do, by<br class="">
populating the combobox through such an initialiser ?<br class="">
<br class="">
Are the parameters populated/initialised in the order they<br class="">
appear? In particular, is the initialisation done serially or can<br class="">
there be parallel execution of initialisers ? I ask because I<br class="">
have parameters a, b, c whose initialisation depend on a common<br class="">
calculation (depending on the image gotten through a previous<br class="">
@Parameter ImagePlus imp): can I do this calculation in the<br class="">
initialiser for the first parameter a, and then in the<br class="">
initialisers of b and c rely on the fact that the calculation was<br class="">
already done ?<br class="">
<br class="">
cheers,<br class="">
Adrian
<div class="HOEnZb">
<div class="h5"><br class="">
<br class="">
<br class="">
<br class="">
On Thu, 20 Aug 2015 17:13:11 -0500<br class="">
 Curtis Rueden <<a href="mailto:ctrueden@wisc.edu" target="_blank" class="">ctrueden@wisc.edu</a>> wrote:<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Felix, Jan and everyone,<br class="">
<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I couldn’t find any hint that it is possible to update the choices of<br class="">
a parameter (declared with the annotator) in a callback that for<br class="">
another parameter.<br class="">
</blockquote>
<br class="">
It is possible to dynamically adjust parameters from Java code [1]. You can<br class="">
also dynamically add and remove parameters. Such commands extend the<br class="">
DynamicCommand class.<br class="">
<br class="">
There are many examples currently in the imagej-plugins-commands project;<br class="">
e.g.:<br class="">
<a href="https://github.com/imagej/imagej-plugins-commands/blob/imagej-plugins-commands-0.5.1/src/main/java/net/imagej/plugins/commands/restructure/AddAxis.java" rel="noreferrer" target="_blank" class="">https://github.com/imagej/imagej-plugins-commands/blob/imagej-plugins-commands-0.5.1/src/main/java/net/imagej/plugins/commands/restructure/AddAxis.java</a><br class="">
<br class="">
However, a couple of notes:<br class="">
<br class="">
- This pattern makes the command less reusable from other contexts, because<br class="">
some contexts require a priori knowledge about the number and types of<br class="">
input and output parameters.<br class="">
<br class="">
- The user interface currently does not properly refresh the input<br class="">
harvester dialog if changes are made to parameters from a callback. So<br class="">
while you can technically do things like change the choices array of a<br class="">
multiple-choice input, the user will not actually see it.<br class="">
<br class="">
- What does work currently is to determine the multiple-choice values at<br class="">
initialization time, based on the values of parameters which have already<br class="">
been populated earlier, such as an active dataset. This is what many of the<br class="">
DynamicCommand implementations in imagej-plugins-commands do.<br class="">
<br class="">
Really, there are _five_ different classes of commands here:<br class="">
<br class="">
1) Totally fixed, with inputs and outputs known in advance.<br class="">
2) Updates parameter attributes (such as choices—but not # or type of<br class="">
inputs/outputs) once during initialization.<br class="">
3) Updates parameter number and type (i.e., adding/removing inputs/outputs)<br class="">
once during initialization.<br class="">
4) Updates parameter attributes repeatedly e.g. during callbacks.<br class="">
5) Updates parameter number and type repeatedly e.g. during callbacks.<br class="">
<br class="">
Of these, type #1 is most desirable for a variety of reasons. Failing that,<br class="">
types #2 and #3 can be done right now using DynamicCommand and it works<br class="">
properly from the ImageJ UI—but not from other contexts like CellProfiler,<br class="">
KNIME, etc. Types #4 and #5 can also be coded but will not work properly<br class="">
from the UI in ImageJ because the input harvester is not rebuilt on<br class="">
callbacks.<br class="">
<br class="">
See also:<br class="">
* <a href="https://github.com/scijava/scijava-common/issues/42" rel="noreferrer" target="_blank" class="">
https://github.com/scijava/scijava-common/issues/42</a><br class="">
* <a href="https://github.com/scijava/scijava-common/issues/43" rel="noreferrer" target="_blank" class="">
https://github.com/scijava/scijava-common/issues/43</a><br class="">
* <a href="https://github.com/CellProfiler/CellProfiler/issues/647" rel="noreferrer" target="_blank" class="">
https://github.com/CellProfiler/CellProfiler/issues/647</a><br class="">
<br class="">
Regards,<br class="">
Curtis<br class="">
<br class="">
[1] Dynamically updating parameters from scripts would be a different<br class="">
story. No plans to do that any time soon...<br class="">
<br class="">
On Thu, Aug 20, 2015 at 6:50 AM, Jan Eglinger <<a href="mailto:jan.eglinger@gmail.com" target="_blank" class="">jan.eglinger@gmail.com</a>><br class="">
wrote:<br class="">
<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Felix and all,<br class="">
<br class="">
On 20.08.2015 10:06, MEYENHOFER Felix wrote:<br class="">
<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I couldn’t find any hint that it is possible to update the choices of a<br class="">
parameter (declared with the annotator) in a callback that for another<br class="">
parameter. For example; I have a file chooser and once a file hase been<br class="">
chosen, I want to read some file metadata and then update the choices of<br class="">
the combobox that allows to select the images series.<br class="">
Since I could not figure a way to do it, I wanted to ask here if it is<br class="">
possible at all?<br class="">
<br class="">
<br class="">
</blockquote>
I think dynamic adjustment of parameters isn't possible currently, but I<br class="">
agree that it would be a great thing to have.<br class="">
<br class="">
I know quite some use cases where either a DialogListener or a series of<br class="">
subsequent dialogs are used in ImageJ 1.x plugins to adjust parameter<br class="">
choice to previously harvested input.<br class="">
<br class="">
Furthermore, is it possible to get a directory chooser instead of a file<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
chooser in the configuration dialog of a command using the @Parameter<br class="">
annotation?<br class="">
<br class="">
<br class="">
</blockquote>
Yes, by using the<br class="">
    style = "directory"<br class="">
attribute. See *Templates > Python > Process Folder* in the script editor,<br class="">
and this related discussion:<br class="">
  <a href="https://github.com/imagej/imagej-legacy/pull/114" rel="noreferrer" target="_blank" class="">
https://github.com/imagej/imagej-legacy/pull/114</a><br class="">
<br class="">
Best,<br class="">
Jan<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
ImageJ-devel mailing list<br class="">
<a href="mailto:ImageJ-devel@imagej.net" target="_blank" class="">ImageJ-devel@imagej.net</a><br class="">
<a href="http://imagej.net/mailman/listinfo/imagej-devel" rel="noreferrer" target="_blank" class="">http://imagej.net/mailman/listinfo/imagej-devel</a><br class="">
<br class="">
</blockquote>
</blockquote>
<br class="">
</div>
</div>
<span class="HOEnZb"><font color="#888888" class="">-- <br class="">
<a href="http://www.msc.univ-paris-diderot.fr/~daerr/" rel="noreferrer" target="_blank" class="">http://www.msc.univ-paris-diderot.fr/~daerr/</a><br class="">
</font></span></blockquote>
</div>
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>