Write plugin in Javascript or Python?!

122 views
Skip to first unread message

Will Ouyang

unread,
Nov 1, 2013, 1:48:01 PM11/1/13
to icy-so...@googlegroups.com
Hi everyone,

Recently, I am thinking about adding script plugin support to Icy. The motivations are:
1. Icy supports Javascript, Python and more in the future, but no script engine interface established.
2. Supporting plugins in script will change the way of developing, it will ease our developing experience and boost the speed. We now have ScriptEditor with autocomplete and highlighting, why should we use eclipse.
3. ScriptEditor can write script easily and why should we run it in the editor? When the develop is done, we only want to click a button and run it just like other plugins in Icy. Native script plugin support will be more elegant for user to run.
4. Script can be used to do some automation like macro, and also can be used to build actionable plugin, like this one [#472] by Timothée Lecomte.
It startup file is in Javascript, when it starts, it build a Python Interpreter to run a simple python plugin with EzPlug by Timothée Lecomte.It runs like this:


Welcome to try it, download from here: https://www.dropbox.com/sh/1zz5dd8eegn80kc/6MG3MuGe4a

Files in this directory demonstrate script plugin in Icy, you can download these files, to test or work with your own plugin write in Python or Javascript.

##Requirement
1.You should install the latest icy software from http://icy.bioimageanalysis.org/. The version should be V1.3.6+ .
2.And in order to run the demonstrate and use plugin write in Python, you should search the online plugin repository to install “Jython for Icy”.

##Usage
In order to work, you should:
1. icy.jar contains the kernel of icy, you should backup your original icy.jar file, and then copy the icy.jar to overwrite the old one.
2. PyPluginTest.zip contains a simple demo plugin write with javascript and python. You should unzip the file to a directory and put it under any sub-directory of “Plugins” in Icy.
3. Open Icy as normal and you will get your plugin installed just like a normal plugin, you can set it in the workspace or open it through “Others” plugin entry.

##Write your own script plugin for Icy

In order to write your own script plugin, you should know:
1.A script plugin should contains at least two files, “__init__.*” file and “*.xml” file. The “__init__.*” is “__init__.js” for javascript and “__init__.py” for python, this file contains the startup code of the plugin will be execute by the script engine when user click the plugin icon. You can write all your plugin code in the startup file and also you can all other module in this file. Another file is a xml file for descript the plugin, this file is just like your other plugin’s xml file. But Additionally, there is a more element named “script_engine_classname” to define which engine will be used to run the script. The sample files will show you what are these files like.

2.A specific scriptEngine is needed running the corresponding script. Currently, I have integrate a JavascriptEngine in icy.jar. So, this means only javascript plugin is supported. But more script Engine can be added by implementing the “PluginScriptEngine” interface.
But, if you have installed “Jython for Icy”, we can run Python plugin through Javascript, this is exactly our demo do. In our demonstration, we write a __init__.js file as the startup script, and it create a Python interpreter and run the plugin code “MyPythonPlugin.py” which is write in Python. 
You can open the file to see more about how to build a EzPlug interfaced plugin.

3. For more detail, you may want to see the source code on Github: https://github.com/oeway/Icy-Kernel or you can contact me by email: oeway007<AT>gmail.com.

Fab

unread,
Nov 3, 2013, 1:43:03 PM11/3/13
to icy-so...@googlegroups.com
Hi Will !

This is very cool !

Are you planning to add some input output to the generated plugins ?

Best,

Fabrice

Will Ouyang

unread,
Nov 4, 2013, 4:12:36 AM11/4/13
to icy-so...@googlegroups.com

Hi Fabrice,

Thanks, I am glad that you like the idea, have you tried the patch? You mentioned that add some input output, actually I don't know what your mean. Writing script plugin is almost the same as writing in Eclipse, except the syntax changed. So, we can write a plugin with EzPlug just like the demo does. I don't think we should add extra input and output to the plugins, unless you want to generate a protocol at the same time. 

The idea is simple, I hope Icy-Kernel masters can support the useful and cool feature. I have a bunch of ideas will based on it, for example, we can build plugin to call other plugins to complete some daily task, we can build a script engine to run Protocols and make protocol based plugin, and maybe ImageJ macro too. Everyone installed Icy could make a plugin in several minutes, and this will surely make Icy a "Battery-Included" program.

Timothée Lecomte

unread,
Nov 5, 2013, 3:37:59 AM11/5/13
to icy-so...@googlegroups.com
Hi Will,

This is very interesting ! I have been working recently on a similar idea too, and I am still trying a couple of techniques to make this (implementing plugins in Python) as smooth as possible. 

I have tried something close to what you have implemented (a small boilerplate code that launches the Python interpreter to create an object deriving from EzPlug), but I have found a couple of drawbacks. First I would prefer a method that doesn't touch the existing PluginLoader if possible, and more importantly this approach does not allow to implement a plugin that implements an interface, such as a Block. I am still testing some ideas to achieve that last point.

If you have some ideas, please do not hesitate to tell me :) We can maybe discuss off-list to avoid flooding the forum.

Best regards,

Timothée

Timothée Lecomte
--
Unité d'analyse d'images quantitative
Institut Pasteur
25 rue du docteur Roux
75015 Paris

Reply all
Reply to author
Forward
0 new messages