Skip to content, Skip to search


Jython Scripting

1,990 bytes added, 16:23, 25 September 2009
Tips and Tricks
== Jython for plugins ==
=== Using a jython script as a plugin ===
The simplest way is to place the jython script file into fiji/plugins/ folder or a subfolder, and it will appear in the menus on restarting fiji.
=== Distributing jython scripts in a .jar file ===
PLEASE NOTE: there is no need to do the following. See entry above.
We create two jython scripts that we want to distribute in a .jar file as plugins:
The script:
<source lang="python">
IJ.log("Print this to the log window")
The script:
<source lang="python">
ip = ByteProcessor(400, 400)
imp = ImagePlus("New", ip)
ip.setRoi(OvalRoi(100, 100, 200, 200))
Place both scripts under a folder named <i>scripts</i>.
You will need a tiny .java file specifying a launcher PlugIn, such as:
<source lang="java">
package my;
import ij.plugin.PlugIn;
import Jython.Refresh_Jython_Scripts;
public class Jython_Launcher implements PlugIn {
public void run(String arg) {
new Refresh_Jython_Scripts.runScript(getClass().getResourceAsStream(arg);
Notice we place the above file under directory <i>my/</i>, packaged.
To compile it:
$ java -cp .:ij.jar my/
Then we define the plugins.config file:
Plugins>My Scripts, "Print to log window", my.Jython_Launcher("/scripts/")
Plugins>My Scripts, "Create image with a white circle", my.Jython_Launcher("/scripts/")
Finally, we put all files in a .jar file:
$ jar my_jython_scripts.jar plugins.config my/Jython_Launcher.class scripts/*py
Then, drop the jar file into fiji/plugins/ folder and run "Help - Update Menus", or restart fiji. Your scripts will appear under Plugins - My Scripts.
Notice, though, that <b>you don't need to do the .jar packaging at all</b>. Just place the python scripts directly under fiji/plugins/My Scripts/ and they will appear in the menus as regular plugins.
Emailconfirmed, uploaders