Re: question about Windowmanager.toFront()

Posted by Aryeh Weiss on
URL: http://imagej.273.s1.nabble.com/question-about-Windowmanager-toFront-tp5022379p5022388.html

Thanks for your reply. I tested identical scripts. That print statement
was added after they produced different results just to make sure that
the expected image window was being used as the argument.

--aryeh

On 21/08/2019 18:00, Kenneth Sloan wrote:

> I'm not a script hacker, but...
>
> You have two definitions of setFrontWin.  One has a "print  win" in it - the other does not.
>
> "of course" this is irrelevant, but my first step would be to make the two definitions of setFrontWind
> exactly identical.
>
> Even better, I would combine the two tests into one script, using only ONE definition of setFrontWin.
>
> Perhaps irrelevant, but I hope this is helpful.
>
> --
> Kenneth Sloan
> [hidden email]
> Vision is the art of seeing what is invisible to others.
>
>
>
>
>
>> On Aug 21, 2019, at 03:49, Aryeh Weiss <[hidden email]> wrote:
>>
>> Hi Michael,
>>
>> Thank you for your quick reply. I replaced the WindowManager.toFront() call with the IJ.selectWindow() call,.
>>
>> As before, the simple test script that loops through the windows works, while the second test script that duplicates the input window does not.
>>
>> Best regards
>> --aryeh
>>
>>
>> On 21/08/2019 11:36, Michael Schmid wrote:
>>> 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
>>>
>> --
>> Aryeh Weiss
>> Faculty of Engineering
>> Bar Ilan University
>> Ramat Gan 52900 Israel
>>
>> Ph:  972-3-5317638
>> FAX: 972-3-7384051
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> .
>

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html