Windows Manager does not work properly on jython?

Hi,

I am writing again because I have an issue with the Windows Manager function on my script.

The goal is to make the user select each windows to define wich one corresponds to FLIM or C1. Once it’s done, I ask the user to create a ROI to define the nucleus. (No possible Nucleus marker so it’s the best option I had.)
Now comes the problem : My script registrer the roi using roimanager and is supposed to bring to front the proper picture to perform the remaining process. But it doesn’t bring to front the picture. So the duplicate, and all the remaining process is done on the wrong picture, and even the second duplicate is done on the first processed picture.

Here is my script if you have some ideas :

from ij import IJ, ImagePlus, WindowManager as WM

#Selection of the windows
waitCA = WaitForUserDialog ("Waiting", "Select C1 picture")
waitCA.show()
impcawm=WM.getCurrentWindow()
impcaij=IJ.getImage()
waitFLIM = WaitForUserDialog ("Waiting", "Select FLIM picture")
waitFLIM.show()
impflimwm = WM.getCurrentWindow()
impflimij=IJ.getImage()

#ROI creation
WM.toFront(impcawm)
rm=RoiManager.getInstance()
if not rm:
	rm = RoiManager()
rm.runCommand("reset")
waitROI=WaitForUserDialog("Waiting", "Select the nucleus ROI")
waitROI.show()
roi=impcaij.getRoi()
rm.addRoi(roi)
IJ.run(impcaij, "Make Inverse", "")
roi2=impcaij.getRoi()
rm.addRoi(roi2)

IJ.run(impflimij, "Select None", "")
rm.runCommand(impflimij,"Show None");

#Process on picture impflimwm
WM.toFront(impflimwm)
IJ.run("Duplicate...","new_name")
clear=IJ.getImage()
clear.setRoi(roi)
IJ.run(clear, "Clear", "stack")

#Inverse process on picture impflimwm
WM.toFront(impflimwm)
IJ.run("Duplicate...","Inverse")
clearinv=IJ.getImage()
clearinv.setRoi(roi2)
IJ.run(clearinv, "Clear", "stack")

I don’t understand why it does it, I tried this script using blob sample picture, but this windows manager function used to always work, until now…

Thanks a lot for all you did for the beginner I am.
Regards.

Hello Virgile -

I don’t know how to use the WindowManager but I can
suggest another way to do what I think you want. (Perhaps
the WindowManger can do this – I just don’t know.)

I’ve always used things like IJ.getImage() and
IJ.selectWindow() for things like this. Here is a script that
illustrates this approach:

from ij import IJ
from ij.gui import Overlay
from ij.gui import TextRoi
from ij.gui import WaitForUserDialog

imp1 = IJ.createImage ('(image 1)', '8-bit ramp', 256, 256, 1)
imp2 = IJ.createImage ('(image 2)', '8-bit ramp', 256, 256, 1)
imp1.show()
imp2.show()

WaitForUserDialog ('Waiting', 'Select Image A').show()
impA = IJ.getImage()
impA.setTitle ('Image A')
impA.setOverlay (Overlay (TextRoi(40, 40, 'Image A')))
WaitForUserDialog ('Waiting', 'Select Image B').show()
impB = IJ.getImage()
impB.setTitle ('Image B')
impB.setOverlay (Overlay (TextRoi(40, 40, 'Image B')))

IJ.selectWindow ('Image A')
IJ.run ('Duplicate...', 'title=Duplicate-A')
IJ.selectWindow ('Image B')
IJ.run ('Duplicate...', 'title=Duplicate-B')

This script runs for me and selects the desired images and so on.
(This is running ImageJ 2.0.0-rc-69/1.52p; Java 1.8.0_172 [64-bit]
on ubuntu 16.04 LTS.)

Thanks, mm

1 Like

Very nice. I did not use this function simply because I did find WindowManager first. :grin:
And it also work using

IJ.selectWindow(imp1.title)

So it’s really nice, and much more intuitive than WM.

Thanks a lot, you’re always here to save me Mountain_man !

Yours,
Virgile.