imagej / imagej/pyimagej

Make original ImageJ commands work as SciJava modules

Open
#134 7 comments 0 reactions 1 assignee Claimed by @elevans View on GitHub
enhancement
Dominant language
Python
Stars
534
Forks
95
PR merge metrics
No merged PRs in 30d

Description

[@ctrueden Edit] If we create a script wrapper for each original ImageJ command, they will be easier to use in SciJava-friendly contexts, such as napari-imagej's search bar, because the types of inputs and outputs will be properly declared. Once the script wrappers exist, we could also customize each command as needed, such as checking if headless and failing fast for commands that don't support it. The write-up below describes one possible path to automating the generation of these scripts, so that we can get an initial version of them all in existence as quickly as possible with a minimum of human error.

--------------------

Goal: create a `RecorderPlus` object in ImageJA that operates in parallel to the IJ1 `Recorder`. This class would be a static singleton. This work can live on a branch in IJA as it's not meant for distribution, just a simple workflow to generate scripts.

This object should have a number of fields based on the strings that we are harvesting (e.g. a list of `String`s corresponding to `GenericDialog#getNextString()`).

We will need to modify `GenericDialog` to populate our `RecorderPlus` object since not all information is being passed to the IJ1 `Recorder`.

Points of modification:
* [getNextString](https://github.com/imagej/ImageJA/blob/11b76d928d3988950c9a662b19345077aa8d53aa/src/main/java/ij/gui/GenericDialog.java#L1193)
* [getNextNumber](https://github.com/imagej/ImageJA/blob/11b76d928d3988950c9a662b19345077aa8d53aa/src/main/java/ij/gui/GenericDialog.java#L1088)
* [getNextChoice](https://github.com/imagej/ImageJA/blob/11b76d928d3988950c9a662b19345077aa8d53aa/src/main/java/ij/gui/GenericDialog.java#L1269)
* [getNextChoiceIndex](https://github.com/imagej/ImageJA/blob/11b76d928d3988950c9a662b19345077aa8d53aa/src/main/java/ij/gui/GenericDialog.java#L1287)
* [getNextRadioButton](https://github.com/imagej/ImageJA/blob/11b76d928d3988950c9a662b19345077aa8d53aa/src/main/java/ij/gui/GenericDialog.java#L1324)
* [getNextText](https://github.com/imagej/ImageJA/blob/11b76d928d3988950c9a662b19345077aa8d53aa/src/main/java/ij/gui/GenericDialog.java#L1361)

Each of these methods should be updated to populate a field of `RecorderPlus` with the information that would be sent to the `Recorder`.

Then in [Recorder.saveCommand](https://github.com/imagej/ImageJA/blob/11b76d928d3988950c9a662b19345077aa8d53aa/src/main/java/ij/plugin/frame/Recorder.java#L605-L606) we would call into RecorderPlus to write a `*.py` script based on its current state (and also noting the ImagePlus parameter if present). Then we will create a new repository to house these scripts (or add it to `imagej-legacy`, or something..)

Finally, I think tapping into [Recorder.resetCommandOptions](https://github.com/imagej/ImageJA/blob/11b76d928d3988950c9a662b19345077aa8d53aa/src/main/java/ij/plugin/frame/Recorder.java#L711) to also clear `RecorderPlus` would be sufficient.

Code skeleton:
```
public class RecorderPlus {

public static final RecorderPlus recorder = new RecorderPlus();

//TODO add some fields, with setters, based on GenericDialog.getNextXXXXX

//TODO add a reset method that clears the current fields

//TODO add a "writeScript" method that outputs a script based on RecorderPlus current state
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.