Re: how to end a jython script ?

Posted by ctrueden on
URL: http://imagej.273.s1.nabble.com/how-to-end-a-jython-script-tp5009398p5009400.html

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