Multi file selection UI

scijava
ij2command
imagej

#1

Hello,

Is there are UI element for IJ2 commands that would allow the user to select multiple files?

Best, Christian.


#2

dear Christian,
I don’t know for IJ2 but that was the reply I’ve got from @Wayne and @imagejan about multiple files selection


#3

Yes, this is possible since the Konstanz hackathon in September last year, thanks to a pair programming session with @ctrueden and myself, leading to these improvements:


You can now define a File[] input parameter, and it will generate a list field widget with drag-and-drop functionality:

#@ File[] (label = "Choose input files", style = "files, extensions:xls/xlsx") files

files.each { file ->
    println "Processing $file"
}

Some improvements are still pending, and I’d be happy to receive feedback about those:

If you’d volunteer to build and test those, I’d appreciate it.


EDIT: note that if you plan to implement some batch processing using this input parameter, I’d recommend to instead create your plugin/command/script using a single File parameter and then delegate the actual batch processing work to the Batch Processor:

Happy to help you getting started there.


#4

I like this multi-file window

However I do not manage to have it display if I use only
#@ File[](label="Select images", style="both") PathFiles
In this case I have a usual file input which is a bit less convenient

However if I add another script parameter (like a message displayed), it works (code below and screen cast above)

#@ String(visibility="MESSAGE", value="Select images") Title 
#@ File[](label="Select images", style="both") PathFiles
'''
Removing the first line result in having a usual input file window, not the list-like one of the screen cast
''' 

#5

This behavior is consistent with other parameters, such as File (i.e. not the array). When they’re the only parameter to be harvested, they open a file chooser dialog, but when other parameters are present, the widget will be shown.

Similarly, an ImagePlus is automatically filled with the “active” image when no other image parameter is present, but a drop-down choice widget will be shown if there are more than one.

For ImagePlus et al., you can write:

#@ ImagePlus (autoFill=false) imp

to avoid autofilling, but for File and File[] it would rather be a style= option yet to be defined, I think. Maybe we can implement something like:

#@ File[] (style="both, forceWidget") inputFiles

BTW, why are you setting style="both", i.e. looking for files and directories, when your label says “Select images”?


#6

Thanks for the answer,
I understand that the Image field automatically fills up if there is only one image, but it is less obvious why the File array should not show if there is no other parameters to collect.

Yes I just copy/paste the example from the wiki, I had not find the "files" style yet.