Windows Manager does not work properly on jython?


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")
waitFLIM = WaitForUserDialog ("Waiting", "Select FLIM picture")
impflimwm = WM.getCurrentWindow()

#ROI creation
if not rm:
	rm = RoiManager()
waitROI=WaitForUserDialog("Waiting", "Select the nucleus ROI")
rm.addRoi(roi), "Make Inverse", "")
rm.addRoi(roi2), "Select None", "")
rm.runCommand(impflimij,"Show None");

#Process on picture impflimwm
clear.setRoi(roi), "Clear", "stack")

#Inverse process on picture impflimwm
clearinv.setRoi(roi2), "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.

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)

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') ('Duplicate...', 'title=Duplicate-A')
IJ.selectWindow ('Image B') ('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


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

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