imagej / ImageJ

Public domain software for processing and analyzing scientific images
http://imagej.org
Other
576 stars 227 forks source link

Feature Request: "WaitForUser" Functionality in GenericDialog from Macros #170

Closed jaredbrewer closed 2 years ago

jaredbrewer commented 2 years ago

Hello,

In my work with medium-throughput image processing, I have run into a feature that seems like it should be able to be implemented (and something I will look into for myself, although I know very little/no Java). The WaitForUserDialog class works wonderfully to execute a single purpose dialog that allows for user engagement with the underlying image; similarly, GenericDialog is very powerful in allowing for a wide range of user inputs that can then be used to process the images. Currently, I am implementing both utilities to perform a basic task: manual selection of slices for input into ZProjector for an entire folder of images.

My use case is as follows:

As an example of the dialog code I am using to prompt these behaviors (in Jython):

for i in imps:

imp = IJ.openImage(i)
waiter = WaitForUserDialog("Identify First/Last Slices")
waiter.show()

gui = GenericDialog("MIP Ranges")
gui.addNumericField("First Slice: ", 0, 0)
gui.addNumericField("Last Slice: ", 0, 0)
gui.showDialog()

...

Essentially, I would like to be able to interact with the image while the GenericDialog is open. Is there presently an option to enable this natively? I can see that this might be a bad behavior in some instances and the default should, perhaps, be for the GenericDialog to seize all user input until dismissed, but an option at initiation of the GenericDialog to allow for engaging the underlying ImagePlus would simplify this pipeline where most of the needed actions can be done programmatically with individual inputs needed with each loop cycle. Currently, everything works as expected but I wanted to present another potential application that could likely borrow heavily from the existing code base.

Edit:

After looking through the code, I see that GenericDialog is modal while WaitForUserDialog is non-modal, but my limited knowledge of Java makes it difficult to identify the particular aspects that generate this difference (although I presume they are buried in the logic of the differences in the methods showDialog() in GenericDialog and show() in WaitForUserDialog). It seems as if it should be somewhat straightforward to assign a given dialog to be either modal or non-modal as needed.

jaredbrewer commented 2 years ago

Correction:

This functionality is provided by the class NonBlockingGenericDialog and works great.