Dear all,
Please consider the following plugin: run("Blobs (25K)"); imageName = getTitle(); print(getInfo("window.title")); Dialog.createNonBlocking("New Image"); Dialog.addString("Title:","Untitled"); Dialog.show(); print(getInfo("window.title")); selectWindow(imageName); print(getInfo("window.title")); Knowing that the dialog is nonBlocking, it is still not possible to get the "Blobs" picture as selected (or in focus). This issue came from a plugin where I have stack which I would like to put as selected in order to the user to be able to browse through the stack without having the user to manually put the stack picture in focus. Thus is what I'm trying to do possible and if yes, how? I thank you very much in advance for your lighting on this. My best regards, Philippe Philippe CARL Laboratoire de Bioimagerie et Pathologies UMR 7021 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 41 84 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Philippe,
if you create a non-blocking dialog in a macro, it means that the user can do everything else while the dialog is open, but the macro does not proceed until the user presses "ok". So the non-blocking dialog is a bit like "waitForUser(message)", just that the "waitForUser" dialog has no possibilities for input and no cancel button. With a macro, I see no way to select the image after creating the dialog. But I think this is not desirable anyhow, because the image might hide the dialog! It often makes sense to select a certain image *before* showing the dialog, so that the user has the image he/she needs for whatever should be done in the dialog. Michael ________________________________________________________________ On 02.12.19 14:19, CARL Philippe (LBP) wrote: > Dear all, > Please consider the following plugin: > run("Blobs (25K)"); > imageName = getTitle(); > print(getInfo("window.title")); > Dialog.createNonBlocking("New Image"); > Dialog.addString("Title:","Untitled"); > Dialog.show(); > print(getInfo("window.title")); > selectWindow(imageName); > print(getInfo("window.title")); > Knowing that the dialog is nonBlocking, it is still not possible to get the "Blobs" picture as selected (or in focus). > This issue came from a plugin where I have stack which I would like to put as selected in order to the user to be able to browse through the stack without having the user to manually put the stack picture in focus. > Thus is what I'm trying to do possible and if yes, how? > I thank you very much in advance for your lighting on this. > My best regards, > Philippe > > > Philippe CARL > Laboratoire de Bioimagerie et Pathologies > UMR 7021 CNRS - Université de Strasbourg > Faculté de Pharmacie > 74 route du Rhin > 67401 ILLKIRCH > Tel : +33(0)3 68 85 41 84 > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Michael,
I agree completely with your comments on the fact that a non-blocking dialog is a waitForUser like dialog. Nevertheless, I would rather like to come back to your following comment: > With a macro, I see no way to select the image after creating the dialog. Does it mean that there is a way to select a picture using a java code within a plugin? I only wrote a macro for illustration but I really want to use such a code within a plugin, not a macro. My best regards, Philippe ----- Mail original ----- De: "Michael Schmid" <[hidden email]> À: "imagej" <[hidden email]> Envoyé: Lundi 2 Décembre 2019 19:26:19 Objet: Re: How to put a picture as selected Hi Philippe, if you create a non-blocking dialog in a macro, it means that the user can do everything else while the dialog is open, but the macro does not proceed until the user presses "ok". So the non-blocking dialog is a bit like "waitForUser(message)", just that the "waitForUser" dialog has no possibilities for input and no cancel button. With a macro, I see no way to select the image after creating the dialog. But I think this is not desirable anyhow, because the image might hide the dialog! It often makes sense to select a certain image *before* showing the dialog, so that the user has the image he/she needs for whatever should be done in the dialog. Michael ________________________________________________________________ On 02.12.19 14:19, CARL Philippe (LBP) wrote: > Dear all, > Please consider the following plugin: > run("Blobs (25K)"); > imageName = getTitle(); > print(getInfo("window.title")); > Dialog.createNonBlocking("New Image"); > Dialog.addString("Title:","Untitled"); > Dialog.show(); > print(getInfo("window.title")); > selectWindow(imageName); > print(getInfo("window.title")); > Knowing that the dialog is nonBlocking, it is still not possible to get the "Blobs" picture as selected (or in focus). > This issue came from a plugin where I have stack which I would like to put as selected in order to the user to be able to browse through the stack without having the user to manually put the stack picture in focus. > Thus is what I'm trying to do possible and if yes, how? > I thank you very much in advance for your lighting on this. > My best regards, > Philippe > > > Philippe CARL > Laboratoire de Bioimagerie et Pathologies > UMR 7021 CNRS - Université de Strasbourg > Faculté de Pharmacie > 74 route du Rhin > 67401 ILLKIRCH > Tel : +33(0)3 68 85 41 84 > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Philippe,
if you need to put something forward immediately after a NonBlockingGenericDialog is shown, one option is to use a second thread. That thread could wait in a loop until the dialog is in the foreground, with repeated calls to WindowManager.getFrontWindow(), then put the other window to the front and terminate. Have a small delay in the loop, e.g. IJ.wait(10), to avoid unnecessary CPU load. It is not 100% bulletproof. With bad luck one could click on another window and bring it to the front a microsecond after the dialog gets shown, then the other thread never detects the dialog coming to the front and runs forever. On could handle this with a timeout. Michael ________________________________________________________________ On 02.12.19 22:03, CARL Philippe (LBP) wrote: > Hi Michael, > I agree completely with your comments on the fact that a non-blocking dialog is a waitForUser like dialog. > Nevertheless, I would rather like to come back to your following comment: >> With a macro, I see no way to select the image after creating the dialog. > Does it mean that there is a way to select a picture using a java code within a plugin? > I only wrote a macro for illustration but I really want to use such a code within a plugin, not a macro. > My best regards, > Philippe > > ----- Mail original ----- > De: "Michael Schmid" <[hidden email]> > À: "imagej" <[hidden email]> > Envoyé: Lundi 2 Décembre 2019 19:26:19 > Objet: Re: How to put a picture as selected > > Hi Philippe, > > if you create a non-blocking dialog in a macro, it means that the user > can do everything else while the dialog is open, but the macro does not > proceed until the user presses "ok". > > So the non-blocking dialog is a bit like "waitForUser(message)", just > that the "waitForUser" dialog has no possibilities for input and no > cancel button. > > With a macro, I see no way to select the image after creating the > dialog. But I think this is not desirable anyhow, because the image > might hide the dialog! > It often makes sense to select a certain image *before* showing the > dialog, so that the user has the image he/she needs for whatever should > be done in the dialog. > > > Michael > ________________________________________________________________ > On 02.12.19 14:19, CARL Philippe (LBP) wrote: >> Dear all, >> Please consider the following plugin: >> run("Blobs (25K)"); >> imageName = getTitle(); >> print(getInfo("window.title")); >> Dialog.createNonBlocking("New Image"); >> Dialog.addString("Title:","Untitled"); >> Dialog.show(); >> print(getInfo("window.title")); >> selectWindow(imageName); >> print(getInfo("window.title")); >> Knowing that the dialog is nonBlocking, it is still not possible to get the "Blobs" picture as selected (or in focus). >> This issue came from a plugin where I have stack which I would like to put as selected in order to the user to be able to browse through the stack without having the user to manually put the stack picture in focus. >> Thus is what I'm trying to do possible and if yes, how? >> I thank you very much in advance for your lighting on this. >> My best regards, >> Philippe >> >> >> Philippe CARL >> Laboratoire de Bioimagerie et Pathologies >> UMR 7021 CNRS - Université de Strasbourg >> Faculté de Pharmacie >> 74 route du Rhin >> 67401 ILLKIRCH >> Tel : +33(0)3 68 85 41 84 >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Michael,
I may very probably only be missing a little something, but I'm not fully able to follow your recommandations. So within my main code, I wrote: Thread bgThread = new Thread(this, "Window in front"); bgThread.setPriority(Math.max(bgThread.getPriority() - 3, Thread.MIN_PRIORITY)); bgThread.start(); NonBlockingGenericDialog nbgd = new NonBlockingGenericDialog("Action Required"); nbgd.addMessage("Message"); nbgd.addCheckbox("Choice", choice); synchronized(this) { nbgd.showDialog(); } if (nbgd.wasCanceled()) { return; } bgThread.interrupt(); bgThread = null; together with the following void: public void run() { while (WindowManager.getActiveWindow() != stackWindow) { IJ.wait(10); WindowManager.setWindow(stackWindow); } } So if I have an IJ.log where ever within the run() void (i.e. within the while loop or before) the code is working as expected. But stackWindow isn't anymore put in front if I don't have any IJ.log within the run() void. Thus what is my mistake? I thank you very much in advance for your (as always!) very bright lighting. Have a nice week-end, Philippe Philippe CARL Laboratoire de Bioimagerie et Pathologies UMR 7021 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 41 84 ----- Mail original ----- De: "Michael Schmid" <[hidden email]> À: "imagej" <[hidden email]> Envoyé: Mardi 3 Décembre 2019 21:09:12 Objet: Re: How to put a picture as selected Hi Philippe, if you need to put something forward immediately after a NonBlockingGenericDialog is shown, one option is to use a second thread. That thread could wait in a loop until the dialog is in the foreground, with repeated calls to WindowManager.getFrontWindow(), then put the other window to the front and terminate. Have a small delay in the loop, e.g. IJ.wait(10), to avoid unnecessary CPU load. It is not 100% bulletproof. With bad luck one could click on another window and bring it to the front a microsecond after the dialog gets shown, then the other thread never detects the dialog coming to the front and runs forever. On could handle this with a timeout. Michael ________________________________________________________________ On 02.12.19 22:03, CARL Philippe (LBP) wrote: > Hi Michael, > I agree completely with your comments on the fact that a non-blocking dialog is a waitForUser like dialog. > Nevertheless, I would rather like to come back to your following comment: >> With a macro, I see no way to select the image after creating the dialog. > Does it mean that there is a way to select a picture using a java code within a plugin? > I only wrote a macro for illustration but I really want to use such a code within a plugin, not a macro. > My best regards, > Philippe > > ----- Mail original ----- > De: "Michael Schmid" <[hidden email]> > À: "imagej" <[hidden email]> > Envoyé: Lundi 2 Décembre 2019 19:26:19 > Objet: Re: How to put a picture as selected > > Hi Philippe, > > if you create a non-blocking dialog in a macro, it means that the user > can do everything else while the dialog is open, but the macro does not > proceed until the user presses "ok". > > So the non-blocking dialog is a bit like "waitForUser(message)", just > that the "waitForUser" dialog has no possibilities for input and no > cancel button. > > With a macro, I see no way to select the image after creating the > dialog. But I think this is not desirable anyhow, because the image > might hide the dialog! > It often makes sense to select a certain image *before* showing the > dialog, so that the user has the image he/she needs for whatever should > be done in the dialog. > > > Michael > ________________________________________________________________ > On 02.12.19 14:19, CARL Philippe (LBP) wrote: >> Dear all, >> Please consider the following plugin: >> run("Blobs (25K)"); >> imageName = getTitle(); >> print(getInfo("window.title")); >> Dialog.createNonBlocking("New Image"); >> Dialog.addString("Title:","Untitled"); >> Dialog.show(); >> print(getInfo("window.title")); >> selectWindow(imageName); >> print(getInfo("window.title")); >> Knowing that the dialog is nonBlocking, it is still not possible to get the "Blobs" picture as selected (or in focus). >> This issue came from a plugin where I have stack which I would like to put as selected in order to the user to be able to browse through the stack without having the user to manually put the stack picture in focus. >> Thus is what I'm trying to do possible and if yes, how? >> I thank you very much in advance for your lighting on this. >> My best regards, >> Philippe >> >> >> Philippe CARL >> Laboratoire de Bioimagerie et Pathologies >> UMR 7021 CNRS - Université de Strasbourg >> Faculté de Pharmacie >> 74 route du Rhin >> 67401 ILLKIRCH >> Tel : +33(0)3 68 85 41 84 >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Philippe,
could it be that you start with stackWindow being the front window? Then the background thread will terminate immediately. Michael ________________________________________________________________ On 06.12.19 16:28, CARL Philippe (LBP) wrote: > Dear Michael, > I may very probably only be missing a little something, but I'm not fully able to follow your recommandations. > So within my main code, I wrote: > Thread bgThread = new Thread(this, "Window in front"); > bgThread.setPriority(Math.max(bgThread.getPriority() - 3, Thread.MIN_PRIORITY)); > bgThread.start(); > > NonBlockingGenericDialog nbgd = new NonBlockingGenericDialog("Action Required"); > nbgd.addMessage("Message"); > nbgd.addCheckbox("Choice", choice); > synchronized(this) > { > nbgd.showDialog(); > } > if (nbgd.wasCanceled()) > { > return; > } > bgThread.interrupt(); > bgThread = null; > together with the following void: > public void run() > { > while (WindowManager.getActiveWindow() != stackWindow) > { > IJ.wait(10); > WindowManager.setWindow(stackWindow); > } > } > So if I have an IJ.log where ever within the run() void (i.e. within the while loop or before) the code is working as expected. > But stackWindow isn't anymore put in front if I don't have any IJ.log within the run() void. > Thus what is my mistake? > I thank you very much in advance for your (as always!) very bright lighting. > Have a nice week-end, > Philippe > > Philippe CARL > Laboratoire de Bioimagerie et Pathologies > UMR 7021 CNRS - Université de Strasbourg > Faculté de Pharmacie > 74 route du Rhin > 67401 ILLKIRCH > Tel : +33(0)3 68 85 41 84 > > ----- Mail original ----- > De: "Michael Schmid" <[hidden email]> > À: "imagej" <[hidden email]> > Envoyé: Mardi 3 Décembre 2019 21:09:12 > Objet: Re: How to put a picture as selected > > Hi Philippe, > > if you need to put something forward immediately after a > NonBlockingGenericDialog is shown, one option is to use a second thread. > That thread could wait in a loop until the dialog is in the foreground, > with repeated calls to WindowManager.getFrontWindow(), then put the > other window to the front and terminate. > > Have a small delay in the loop, e.g. IJ.wait(10), to avoid unnecessary > CPU load. > > It is not 100% bulletproof. With bad luck one could click on another > window and bring it to the front a microsecond after the dialog gets > shown, then the other thread never detects the dialog coming to the > front and runs forever. On could handle this with a timeout. > > > Michael > ________________________________________________________________ > On 02.12.19 22:03, CARL Philippe (LBP) wrote: >> Hi Michael, >> I agree completely with your comments on the fact that a non-blocking dialog is a waitForUser like dialog. >> Nevertheless, I would rather like to come back to your following comment: >>> With a macro, I see no way to select the image after creating the dialog. >> Does it mean that there is a way to select a picture using a java code within a plugin? >> I only wrote a macro for illustration but I really want to use such a code within a plugin, not a macro. >> My best regards, >> Philippe >> >> ----- Mail original ----- >> De: "Michael Schmid" <[hidden email]> >> À: "imagej" <[hidden email]> >> Envoyé: Lundi 2 Décembre 2019 19:26:19 >> Objet: Re: How to put a picture as selected >> >> Hi Philippe, >> >> if you create a non-blocking dialog in a macro, it means that the user >> can do everything else while the dialog is open, but the macro does not >> proceed until the user presses "ok". >> >> So the non-blocking dialog is a bit like "waitForUser(message)", just >> that the "waitForUser" dialog has no possibilities for input and no >> cancel button. >> >> With a macro, I see no way to select the image after creating the >> dialog. But I think this is not desirable anyhow, because the image >> might hide the dialog! >> It often makes sense to select a certain image *before* showing the >> dialog, so that the user has the image he/she needs for whatever should >> be done in the dialog. >> >> >> Michael >> ________________________________________________________________ >> On 02.12.19 14:19, CARL Philippe (LBP) wrote: >>> Dear all, >>> Please consider the following plugin: >>> run("Blobs (25K)"); >>> imageName = getTitle(); >>> print(getInfo("window.title")); >>> Dialog.createNonBlocking("New Image"); >>> Dialog.addString("Title:","Untitled"); >>> Dialog.show(); >>> print(getInfo("window.title")); >>> selectWindow(imageName); >>> print(getInfo("window.title")); >>> Knowing that the dialog is nonBlocking, it is still not possible to get the "Blobs" picture as selected (or in focus). >>> This issue came from a plugin where I have stack which I would like to put as selected in order to the user to be able to browse through the stack without having the user to manually put the stack picture in focus. >>> Thus is what I'm trying to do possible and if yes, how? >>> I thank you very much in advance for your lighting on this. >>> My best regards, >>> Philippe >>> >>> >>> Philippe CARL >>> Laboratoire de Bioimagerie et Pathologies >>> UMR 7021 CNRS - Université de Strasbourg >>> Faculté de Pharmacie >>> 74 route du Rhin >>> 67401 ILLKIRCH >>> Tel : +33(0)3 68 85 41 84 >>> >>> -- >>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >>> >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi again Michael,
I have only 3 windows open within the plugin: - stackWindow - roiManager - the created NonBlockingGenericDialog Thus your idea may indeed be right. Nevertheless by adding a: WindowManager.setWindow(RoiManager.getInstance()); prior to the NonBlockingGenericDialog nbgd definition or even just before the synchronized(this) { nbgd.showDialog(); } it isn't working as well. My best regards, Philippe ----- Mail original ----- De: "Michael Schmid" <[hidden email]> À: "imagej" <[hidden email]> Envoyé: Vendredi 6 Décembre 2019 17:30:21 Objet: Re: How to put a picture as selected Hi Philippe, could it be that you start with stackWindow being the front window? Then the background thread will terminate immediately. Michael ________________________________________________________________ On 06.12.19 16:28, CARL Philippe (LBP) wrote: > Dear Michael, > I may very probably only be missing a little something, but I'm not fully able to follow your recommandations. > So within my main code, I wrote: > Thread bgThread = new Thread(this, "Window in front"); > bgThread.setPriority(Math.max(bgThread.getPriority() - 3, Thread.MIN_PRIORITY)); > bgThread.start(); > > NonBlockingGenericDialog nbgd = new NonBlockingGenericDialog("Action Required"); > nbgd.addMessage("Message"); > nbgd.addCheckbox("Choice", choice); > synchronized(this) > { > nbgd.showDialog(); > } > if (nbgd.wasCanceled()) > { > return; > } > bgThread.interrupt(); > bgThread = null; > together with the following void: > public void run() > { > while (WindowManager.getActiveWindow() != stackWindow) > { > IJ.wait(10); > WindowManager.setWindow(stackWindow); > } > } > So if I have an IJ.log where ever within the run() void (i.e. within the while loop or before) the code is working as expected. > But stackWindow isn't anymore put in front if I don't have any IJ.log within the run() void. > Thus what is my mistake? > I thank you very much in advance for your (as always!) very bright lighting. > Have a nice week-end, > Philippe > > Philippe CARL > Laboratoire de Bioimagerie et Pathologies > UMR 7021 CNRS - Université de Strasbourg > Faculté de Pharmacie > 74 route du Rhin > 67401 ILLKIRCH > Tel : +33(0)3 68 85 41 84 > > ----- Mail original ----- > De: "Michael Schmid" <[hidden email]> > À: "imagej" <[hidden email]> > Envoyé: Mardi 3 Décembre 2019 21:09:12 > Objet: Re: How to put a picture as selected > > Hi Philippe, > > if you need to put something forward immediately after a > NonBlockingGenericDialog is shown, one option is to use a second thread. > That thread could wait in a loop until the dialog is in the foreground, > with repeated calls to WindowManager.getFrontWindow(), then put the > other window to the front and terminate. > > Have a small delay in the loop, e.g. IJ.wait(10), to avoid unnecessary > CPU load. > > It is not 100% bulletproof. With bad luck one could click on another > window and bring it to the front a microsecond after the dialog gets > shown, then the other thread never detects the dialog coming to the > front and runs forever. On could handle this with a timeout. > > > Michael > ________________________________________________________________ > On 02.12.19 22:03, CARL Philippe (LBP) wrote: >> Hi Michael, >> I agree completely with your comments on the fact that a non-blocking dialog is a waitForUser like dialog. >> Nevertheless, I would rather like to come back to your following comment: >>> With a macro, I see no way to select the image after creating the dialog. >> Does it mean that there is a way to select a picture using a java code within a plugin? >> I only wrote a macro for illustration but I really want to use such a code within a plugin, not a macro. >> My best regards, >> Philippe >> >> ----- Mail original ----- >> De: "Michael Schmid" <[hidden email]> >> À: "imagej" <[hidden email]> >> Envoyé: Lundi 2 Décembre 2019 19:26:19 >> Objet: Re: How to put a picture as selected >> >> Hi Philippe, >> >> if you create a non-blocking dialog in a macro, it means that the user >> can do everything else while the dialog is open, but the macro does not >> proceed until the user presses "ok". >> >> So the non-blocking dialog is a bit like "waitForUser(message)", just >> that the "waitForUser" dialog has no possibilities for input and no >> cancel button. >> >> With a macro, I see no way to select the image after creating the >> dialog. But I think this is not desirable anyhow, because the image >> might hide the dialog! >> It often makes sense to select a certain image *before* showing the >> dialog, so that the user has the image he/she needs for whatever should >> be done in the dialog. >> >> >> Michael >> ________________________________________________________________ >> On 02.12.19 14:19, CARL Philippe (LBP) wrote: >>> Dear all, >>> Please consider the following plugin: >>> run("Blobs (25K)"); >>> imageName = getTitle(); >>> print(getInfo("window.title")); >>> Dialog.createNonBlocking("New Image"); >>> Dialog.addString("Title:","Untitled"); >>> Dialog.show(); >>> print(getInfo("window.title")); >>> selectWindow(imageName); >>> print(getInfo("window.title")); >>> Knowing that the dialog is nonBlocking, it is still not possible to get the "Blobs" picture as selected (or in focus). >>> This issue came from a plugin where I have stack which I would like to put as selected in order to the user to be able to browse through the stack without having the user to manually put the stack picture in focus. >>> Thus is what I'm trying to do possible and if yes, how? >>> I thank you very much in advance for your lighting on this. >>> My best regards, >>> Philippe >>> >>> >>> Philippe CARL >>> Laboratoire de Bioimagerie et Pathologies >>> UMR 7021 CNRS - Université de Strasbourg >>> Faculté de Pharmacie >>> 74 route du Rhin >>> 67401 ILLKIRCH >>> Tel : +33(0)3 68 85 41 84 >>> >>> -- >>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >>> >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Michael,
In order to look deeper into the issue without "introducing artifacts", I replaced the IJ.log outputing "WindowManager.getActiveWindow();" within the run() void by outputs in a saved file. And when I look within the outputed ASCII file, the roiManager was selected at first and then the stackWindow gets selected accordingly my wishes. But still within the GUI, it is the NonBlockingGenericDialog that is in front. So I even tried pushed things further by adding a run(); within the synchronized(this), i.e. writing this: synchronized(this) { nbgd.showDialog(); run(); } And in this case the window selected by WindowManager.getActiveWindow() was first null and became then as well the stackWindow. But still within the GUI, it is the NonBlockingGenericDialog that is in front. So I'm kind of puzzled of what is going on. Do you have some further ideas? My best regards, Philippe ----- Mail original ----- De: "CARL Philippe, LBP" <[hidden email]> À: "imagej" <[hidden email]> Envoyé: Vendredi 6 Décembre 2019 18:42:39 Objet: Re: How to put a picture as selected Hi again Michael, I have only 3 windows open within the plugin: - stackWindow - roiManager - the created NonBlockingGenericDialog Thus your idea may indeed be right. Nevertheless by adding a: WindowManager.setWindow(RoiManager.getInstance()); prior to the NonBlockingGenericDialog nbgd definition or even just before the synchronized(this) { nbgd.showDialog(); } it isn't working as well. My best regards, Philippe ----- Mail original ----- De: "Michael Schmid" <[hidden email]> À: "imagej" <[hidden email]> Envoyé: Vendredi 6 Décembre 2019 17:30:21 Objet: Re: How to put a picture as selected Hi Philippe, could it be that you start with stackWindow being the front window? Then the background thread will terminate immediately. Michael ________________________________________________________________ On 06.12.19 16:28, CARL Philippe (LBP) wrote: > Dear Michael, > I may very probably only be missing a little something, but I'm not fully able to follow your recommandations. > So within my main code, I wrote: > Thread bgThread = new Thread(this, "Window in front"); > bgThread.setPriority(Math.max(bgThread.getPriority() - 3, Thread.MIN_PRIORITY)); > bgThread.start(); > > NonBlockingGenericDialog nbgd = new NonBlockingGenericDialog("Action Required"); > nbgd.addMessage("Message"); > nbgd.addCheckbox("Choice", choice); > synchronized(this) > { > nbgd.showDialog(); > } > if (nbgd.wasCanceled()) > { > return; > } > bgThread.interrupt(); > bgThread = null; > together with the following void: > public void run() > { > while (WindowManager.getActiveWindow() != stackWindow) > { > IJ.wait(10); > WindowManager.setWindow(stackWindow); > } > } > So if I have an IJ.log where ever within the run() void (i.e. within the while loop or before) the code is working as expected. > But stackWindow isn't anymore put in front if I don't have any IJ.log within the run() void. > Thus what is my mistake? > I thank you very much in advance for your (as always!) very bright lighting. > Have a nice week-end, > Philippe > > Philippe CARL > Laboratoire de Bioimagerie et Pathologies > UMR 7021 CNRS - Université de Strasbourg > Faculté de Pharmacie > 74 route du Rhin > 67401 ILLKIRCH > Tel : +33(0)3 68 85 41 84 > > ----- Mail original ----- > De: "Michael Schmid" <[hidden email]> > À: "imagej" <[hidden email]> > Envoyé: Mardi 3 Décembre 2019 21:09:12 > Objet: Re: How to put a picture as selected > > Hi Philippe, > > if you need to put something forward immediately after a > NonBlockingGenericDialog is shown, one option is to use a second thread. > That thread could wait in a loop until the dialog is in the foreground, > with repeated calls to WindowManager.getFrontWindow(), then put the > other window to the front and terminate. > > Have a small delay in the loop, e.g. IJ.wait(10), to avoid unnecessary > CPU load. > > It is not 100% bulletproof. With bad luck one could click on another > window and bring it to the front a microsecond after the dialog gets > shown, then the other thread never detects the dialog coming to the > front and runs forever. On could handle this with a timeout. > > > Michael > ________________________________________________________________ > On 02.12.19 22:03, CARL Philippe (LBP) wrote: >> Hi Michael, >> I agree completely with your comments on the fact that a non-blocking dialog is a waitForUser like dialog. >> Nevertheless, I would rather like to come back to your following comment: >>> With a macro, I see no way to select the image after creating the dialog. >> Does it mean that there is a way to select a picture using a java code within a plugin? >> I only wrote a macro for illustration but I really want to use such a code within a plugin, not a macro. >> My best regards, >> Philippe >> >> ----- Mail original ----- >> De: "Michael Schmid" <[hidden email]> >> À: "imagej" <[hidden email]> >> Envoyé: Lundi 2 Décembre 2019 19:26:19 >> Objet: Re: How to put a picture as selected >> >> Hi Philippe, >> >> if you create a non-blocking dialog in a macro, it means that the user >> can do everything else while the dialog is open, but the macro does not >> proceed until the user presses "ok". >> >> So the non-blocking dialog is a bit like "waitForUser(message)", just >> that the "waitForUser" dialog has no possibilities for input and no >> cancel button. >> >> With a macro, I see no way to select the image after creating the >> dialog. But I think this is not desirable anyhow, because the image >> might hide the dialog! >> It often makes sense to select a certain image *before* showing the >> dialog, so that the user has the image he/she needs for whatever should >> be done in the dialog. >> >> >> Michael >> ________________________________________________________________ >> On 02.12.19 14:19, CARL Philippe (LBP) wrote: >>> Dear all, >>> Please consider the following plugin: >>> run("Blobs (25K)"); >>> imageName = getTitle(); >>> print(getInfo("window.title")); >>> Dialog.createNonBlocking("New Image"); >>> Dialog.addString("Title:","Untitled"); >>> Dialog.show(); >>> print(getInfo("window.title")); >>> selectWindow(imageName); >>> print(getInfo("window.title")); >>> Knowing that the dialog is nonBlocking, it is still not possible to get the "Blobs" picture as selected (or in focus). >>> This issue came from a plugin where I have stack which I would like to put as selected in order to the user to be able to browse through the stack without having the user to manually put the stack picture in focus. >>> Thus is what I'm trying to do possible and if yes, how? >>> I thank you very much in advance for your lighting on this. >>> My best regards, >>> Philippe >>> >>> >>> Philippe CARL >>> Laboratoire de Bioimagerie et Pathologies >>> UMR 7021 CNRS - Université de Strasbourg >>> Faculté de Pharmacie >>> 74 route du Rhin >>> 67401 ILLKIRCH >>> Tel : +33(0)3 68 85 41 84 >>> >>> -- >>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >>> >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Philippe,
sorry, I don't understand your code. You have to start the new thread (the one which is expected to bring the image of your choice to the foreground) *before* nbgd.showDialog(); If it is after that, the background thread will be started after the user has *closed* the dialog. Also, I see no reason for having nbgd.showDialog() in a synchronized block. In a context like this, you need synchronized statements only if you use the Objects's notify and wait() methods. [I am not speaking about IJ.wait(millisec)!] My idea was something like the following: Foreground thread - define the NonBlockingGenericDialog nbgd - start the background thread - nbgd.showDialog() - interrupt the background thread (in case it should not have terminated) Background thread, i.e., the run method: - wait for nbgd to be the foreground window, with a short Thread.sleep(millisec) delay - if so, bring the image of your choice to the foreground and terminate (return). - in the catch(InterruptedException) clause required by Thread.sleep(), return (obviously the dialog is over and the thread somehow has missed it, so nothing to do). The advantage of using Thread.sleep(millisec) instead of IJ.wait(millisec) is the fact that you can react on the thread being interrupted. Best, Michael ________________________________________________________________ On 09.12.19 12:09, CARL Philippe (LBP) wrote: > Hi Michael, > In order to look deeper into the issue without "introducing artifacts", I replaced the IJ.log outputing "WindowManager.getActiveWindow();" within the run() void by outputs in a saved file. > And when I look within the outputed ASCII file, the roiManager was selected at first and then the stackWindow gets selected accordingly my wishes. > But still within the GUI, it is the NonBlockingGenericDialog that is in front. > So I even tried pushed things further by adding a run(); within the synchronized(this), i.e. writing this: > synchronized(this) > { > nbgd.showDialog(); > run(); > } > And in this case the window selected by WindowManager.getActiveWindow() was first null and became then as well the stackWindow. > But still within the GUI, it is the NonBlockingGenericDialog that is in front. > So I'm kind of puzzled of what is going on. > Do you have some further ideas? > My best regards, > Philippe > > ----- Mail original ----- > De: "CARL Philippe, LBP" <[hidden email]> > À: "imagej" <[hidden email]> > Envoyé: Vendredi 6 Décembre 2019 18:42:39 > Objet: Re: How to put a picture as selected > > Hi again Michael, > I have only 3 windows open within the plugin: > - stackWindow > - roiManager > - the created NonBlockingGenericDialog > Thus your idea may indeed be right. > Nevertheless by adding a: > WindowManager.setWindow(RoiManager.getInstance()); > prior to the NonBlockingGenericDialog nbgd definition or even just before the > synchronized(this) > { > nbgd.showDialog(); > } > it isn't working as well. > My best regards, > Philippe > > ----- Mail original ----- > De: "Michael Schmid" <[hidden email]> > À: "imagej" <[hidden email]> > Envoyé: Vendredi 6 Décembre 2019 17:30:21 > Objet: Re: How to put a picture as selected > > Hi Philippe, > > could it be that you start with stackWindow being the front window? Then > the background thread will terminate immediately. > > > Michael > ________________________________________________________________ > On 06.12.19 16:28, CARL Philippe (LBP) wrote: >> Dear Michael, >> I may very probably only be missing a little something, but I'm not fully able to follow your recommandations. >> So within my main code, I wrote: >> Thread bgThread = new Thread(this, "Window in front"); >> bgThread.setPriority(Math.max(bgThread.getPriority() - 3, Thread.MIN_PRIORITY)); >> bgThread.start(); >> >> NonBlockingGenericDialog nbgd = new NonBlockingGenericDialog("Action Required"); >> nbgd.addMessage("Message"); >> nbgd.addCheckbox("Choice", choice); >> synchronized(this) >> { >> nbgd.showDialog(); >> } >> if (nbgd.wasCanceled()) >> { >> return; >> } >> bgThread.interrupt(); >> bgThread = null; >> together with the following void: >> public void run() >> { >> while (WindowManager.getActiveWindow() != stackWindow) >> { >> IJ.wait(10); >> WindowManager.setWindow(stackWindow); >> } >> } >> So if I have an IJ.log where ever within the run() void (i.e. within the while loop or before) the code is working as expected. >> But stackWindow isn't anymore put in front if I don't have any IJ.log within the run() void. >> Thus what is my mistake? >> I thank you very much in advance for your (as always!) very bright lighting. >> Have a nice week-end, >> Philippe >> >> Philippe CARL >> Laboratoire de Bioimagerie et Pathologies >> UMR 7021 CNRS - Université de Strasbourg >> Faculté de Pharmacie >> 74 route du Rhin >> 67401 ILLKIRCH >> Tel : +33(0)3 68 85 41 84 >> >> ----- Mail original ----- >> De: "Michael Schmid" <[hidden email]> >> À: "imagej" <[hidden email]> >> Envoyé: Mardi 3 Décembre 2019 21:09:12 >> Objet: Re: How to put a picture as selected >> >> Hi Philippe, >> >> if you need to put something forward immediately after a >> NonBlockingGenericDialog is shown, one option is to use a second thread. >> That thread could wait in a loop until the dialog is in the foreground, >> with repeated calls to WindowManager.getFrontWindow(), then put the >> other window to the front and terminate. >> >> Have a small delay in the loop, e.g. IJ.wait(10), to avoid unnecessary >> CPU load. >> >> It is not 100% bulletproof. With bad luck one could click on another >> window and bring it to the front a microsecond after the dialog gets >> shown, then the other thread never detects the dialog coming to the >> front and runs forever. On could handle this with a timeout. >> >> >> Michael >> ________________________________________________________________ >> On 02.12.19 22:03, CARL Philippe (LBP) wrote: >>> Hi Michael, >>> I agree completely with your comments on the fact that a non-blocking dialog is a waitForUser like dialog. >>> Nevertheless, I would rather like to come back to your following comment: >>>> With a macro, I see no way to select the image after creating the dialog. >>> Does it mean that there is a way to select a picture using a java code within a plugin? >>> I only wrote a macro for illustration but I really want to use such a code within a plugin, not a macro. >>> My best regards, >>> Philippe >>> >>> ----- Mail original ----- >>> De: "Michael Schmid" <[hidden email]> >>> À: "imagej" <[hidden email]> >>> Envoyé: Lundi 2 Décembre 2019 19:26:19 >>> Objet: Re: How to put a picture as selected >>> >>> Hi Philippe, >>> >>> if you create a non-blocking dialog in a macro, it means that the user >>> can do everything else while the dialog is open, but the macro does not >>> proceed until the user presses "ok". >>> >>> So the non-blocking dialog is a bit like "waitForUser(message)", just >>> that the "waitForUser" dialog has no possibilities for input and no >>> cancel button. >>> >>> With a macro, I see no way to select the image after creating the >>> dialog. But I think this is not desirable anyhow, because the image >>> might hide the dialog! >>> It often makes sense to select a certain image *before* showing the >>> dialog, so that the user has the image he/she needs for whatever should >>> be done in the dialog. >>> >>> >>> Michael >>> ________________________________________________________________ >>> On 02.12.19 14:19, CARL Philippe (LBP) wrote: >>>> Dear all, >>>> Please consider the following plugin: >>>> run("Blobs (25K)"); >>>> imageName = getTitle(); >>>> print(getInfo("window.title")); >>>> Dialog.createNonBlocking("New Image"); >>>> Dialog.addString("Title:","Untitled"); >>>> Dialog.show(); >>>> print(getInfo("window.title")); >>>> selectWindow(imageName); >>>> print(getInfo("window.title")); >>>> Knowing that the dialog is nonBlocking, it is still not possible to get the "Blobs" picture as selected (or in focus). >>>> This issue came from a plugin where I have stack which I would like to put as selected in order to the user to be able to browse through the stack without having the user to manually put the stack picture in focus. >>>> Thus is what I'm trying to do possible and if yes, how? >>>> I thank you very much in advance for your lighting on this. >>>> My best regards, >>>> Philippe >>>> >>>> >>>> Philippe CARL >>>> Laboratoire de Bioimagerie et Pathologies >>>> UMR 7021 CNRS - Université de Strasbourg >>>> Faculté de Pharmacie >>>> 74 route du Rhin >>>> 67401 ILLKIRCH >>>> Tel : +33(0)3 68 85 41 84 >>>> >>>> -- >>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >>>> >>> >>> -- >>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >>> >>> -- >>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >>> >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Michael,
The code is indeed working now as wished and this with following (for the community) code: Within the main code: nbgd= new NonBlockingGenericDialog.... if (bgThread == null) { bgThread = new Thread(this, "Window in front"); bgThread.setPriority(Math.max(bgThread.getPriority() - 3, Thread.MIN_PRIORITY)); bgThread.start(); } nbgd.showDialog(); if (nbgd.wasCanceled()) { rm.removeWindowListener(this); return; } if (bgThread != null) bgThread.interrupt(); bgThread = null; And within the run() void: public void run() { try { while (!nbgd.isActive()) { Thread.sleep(100); } stackWindow.toFront(); } catch (InterruptedException ie) { return; } } Thanks a lot for your (as always) very sharp help! Kindest regards, Philippe Philippe CARL Laboratoire de Bioimagerie et Pathologies UMR 7021 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 41 84 ----- Mail original ----- De: "Michael Schmid" <[hidden email]> À: "CARL Philippe, LBP" <[hidden email]> Envoyé: Lundi 16 Décembre 2019 18:32:31 Objet: Re: How to put a picture as selected Hi Philippe, yes, sorry, the WindowManager behaves differently than I thought. I tried a JavaScript Loop (when trying it, note that it will run forever even if you close the text editor window with it) while(true) { IJ.log(""+WindowManager.getActiveWindow()); IJ.log("macro="+IJ.macroRunning()); IJ.wait(1000); } It does not see a NonBlockigGenericDialog, in spite of the WindowManager.addWindow(thisDialog) command in NonBlockigGenericDialog, and the fact that I did not call the process with the NonBlockigGenericDialog (I used Gaussian Blur) from a macro. Looking at the code, it seems that NonBlockingGenericDialogs never become the Windowmanager's active window. You could try with nbgd.isActive() to determine when the dialog comes to the front. Best, Michael ________________________________________________________________ Michael Schmid email: [hidden email] Institut für Angewandte Physik, Technische Universität Wien Wiedner Hauptstr. 8-10/E134, 1040 Wien, Austria Tel. +43 1 58801-13452, Fax +43 1 58801 13499 ________________________________________________________________ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |