how to end a jython script ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how to end a jython script ?

Leon Espinosa-3
Hello, I wonder if there is a method to finish a Jython script. What I have in mind is something like :


import sys
from ij.gui import NonBlockingGenericDialog

gd0=NonBlockingGenericDialog("Test")
gd0.showDialog()

if gd0.wasCanceled():
        print "Canceled"
        #sys.exit("end") This works if the script is running in the script editor but it kills Fiji if it is installed in the plugins directory like "Test_exit.py"

if gd0.wasOKed():
        print "OK"
        # do the rest of the script



Of course I could do :

if gd0.wasOKed():
        print "OK"
        # do the rest of the script

else : print "end"


But after some Dilalog windows I will have lot of nested "if... else" blocks.


thank you for any help !

All the best, Leon

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how to end a jython script ?

ctrueden
Hi Leon,

Wrap your script in a function, then call that function at the bottom. You
can then use the "return" keyword to return from the function early as
needed.

An example is below.

Regards,
Curtis

--
# @String name
from ij import IJ
def main():
favorite = "Rumpelstiltskin"
 if name == favorite:
IJ.showMessage(favorite + " is my favorite name!")
return
 IJ.showMessage("Hello, " + name + "!")
main()



On Thu, Aug 28, 2014 at 9:33 AM, Leon Espinosa <[hidden email]>
wrote:

> Hello, I wonder if there is a method to finish a Jython script. What I
> have in mind is something like :
>
>
> import sys
> from ij.gui import NonBlockingGenericDialog
>
> gd0=NonBlockingGenericDialog("Test")
> gd0.showDialog()
>
> if gd0.wasCanceled():
>         print "Canceled"
>         #sys.exit("end") This works if the script is running in the script
> editor but it kills Fiji if it is installed in the plugins directory like
> "Test_exit.py"
>
> if gd0.wasOKed():
>         print "OK"
>         # do the rest of the script
>
>
>
> Of course I could do :
>
> if gd0.wasOKed():
>         print "OK"
>         # do the rest of the script
>
> else : print "end"
>
>
> But after some Dilalog windows I will have lot of nested "if... else"
> blocks.
>
>
> thank you for any help !
>
> All the best, Leon
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how to end a jython script ?

Leon Espinosa-3
Ok thank you Curtis , I get it !

Leon


Le 28 août 2014 à 17:43, Curtis Rueden a écrit :

> Hi Leon,
>
> Wrap your script in a function, then call that function at the bottom. You
> can then use the "return" keyword to return from the function early as
> needed.
>
> An example is below.
>
> Regards,
> Curtis
>
> --
> # @String name
> from ij import IJ
> def main():
> favorite = "Rumpelstiltskin"
> if name == favorite:
> IJ.showMessage(favorite + " is my favorite name!")
> return
> IJ.showMessage("Hello, " + name + "!")
> main()
>
>
>
> On Thu, Aug 28, 2014 at 9:33 AM, Leon Espinosa <[hidden email]>
> wrote:
>
>> Hello, I wonder if there is a method to finish a Jython script. What I
>> have in mind is something like :
>>
>>
>> import sys
>> from ij.gui import NonBlockingGenericDialog
>>
>> gd0=NonBlockingGenericDialog("Test")
>> gd0.showDialog()
>>
>> if gd0.wasCanceled():
>>        print "Canceled"
>>        #sys.exit("end") This works if the script is running in the script
>> editor but it kills Fiji if it is installed in the plugins directory like
>> "Test_exit.py"
>>
>> if gd0.wasOKed():
>>        print "OK"
>>        # do the rest of the script
>>
>>
>>
>> Of course I could do :
>>
>> if gd0.wasOKed():
>>        print "OK"
>>        # do the rest of the script
>>
>> else : print "end"
>>
>>
>> But after some Dilalog windows I will have lot of nested "if... else"
>> blocks.
>>
>>
>> thank you for any help !
>>
>> All the best, Leon
>>
>> --
>> 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