Posted by
Michael Schmid on
URL: http://imagej.273.s1.nabble.com/question-about-Windowmanager-toFront-tp5022379p5022380.html
Hi Aryeh,
a safer way to put an image to the foreground is
IJ.selectWindow(imp.getID())
Otherwise you may need to introduce time delays. Displaying a window and
bringing it to the foreground are asynchronous operations, which may be
slower than the execution of your code.
IJ.selectWindow has a loop with time delay to wait until the window is
really in the foreground.
Michael
________________________________________________________________
On 21.08.19 10:13, Aryeh Weiss wrote:
> I wish to select a window to be the front window in my display. to
do this I have function called setFrontWin() that checks if the image is
displayed, shows it if needed, and then moves it to the front. I tested
setFrontWin() using the script below, that loops through all of the open
windows and moves them to the front. This works fine.
>
> ################################
> def setFrontWin(imp):
> win = WindowManager.getWindow(imp.getTitle())
> if win == None:
> imp.show()
> win = WindowManager.getWindow(imp.getTitle())
> win.toFront()
> return win
>
> for w in WindowManager.getImageTitles():
> imp = WindowManager.getImage(w)
> setFrontWin(imp)
> wd=WaitForUserDialog("wait")
> wd.show()
> #################################
>
> Below is a script where this does not work. I open an image, make a
copy, and then want the original image
> to be displayed in front. However, this does not happen -- the copy
is left in front.
> The test script above moves these same images as expected, and I
cannot figure out where they are different.
>
> ######################
>
> import os
> from os import sys, sep, path, makedirs
>
> def open_image():
> """
> opens an image, returns an imagePlus object and its name in that
order
> """
> # Prompt user for the input image file.
> print "open_image begin"
> op = OpenDialog("Choose input image...", "")
> print op.getFileName()
>
> if op.getFileName() == None:
> sys.exit('User canceled dialog')
> # open selected image and prepare it for analysis
>
> inputName = op.getFileName()
> inputDirPath = op.getDirectory()
> inputPath = inputDirPath + inputName
>
> # Strip the suffix off of the input image name
> if inputName[-4] == ".":
> inputPrefix = inputName[:-4] # assumes that a suffix exists
> else:
> inputPrefix = inputName
>
> #opens image and returns it.
> inputImp = ImagePlus(inputPath)
>
> print "open_image finis"
> return inputImp, inputPrefix, inputDirPath
>
> def setFrontWin(imp):
> win = WindowManager.getWindow(imp.getTitle())
> if win == None:
> imp.show()
> win = WindowManager.getWindow(imp.getTitle())
> print win
> win.toFront()
> return win
>
> fullInputImp, inputPrefix, inputDirPath = open_image()
> fullInputImp.show()
> print fullInputImp, inputPrefix, inputDirPath
>
> inputImp = fullInputImp.duplicate()
> inputImp.show()
> inputImp.setTitle(inputPrefix+"_copy")
> fullInputImp.setTitle(inputPrefix+"_orig")
> setFrontWin(fullInputImp)
>
> #############################
>
> For testing purposes I am using auto-import, and these scripts should
be able to run anywhere.
>
> Where have I gone wrong?
>
> Tnx in advance
> --aryeh
>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html