开发者

How to pass data from Java applet to client side python script?

I have a python script which does various number-crunching jobs and now need to put a graphical front-end on it (a molecular editor in which a user draws a compound to pass to the script) to allow others in the lab to use it more easily. The available editors are Java applets, standalone Java or written in JavaScript.

I would greatly appreciate any advice on the best strategy to put the editor and script together. I really don't want to get into client/server arrangement and envisage a self-contained install on each machine i.e. "client only". Is it better to start off in javascript and pass the output in some way to python and then run the python script from within js. Or (preferably) is there some way to run applets (or standalone java) within python e.g. in Tkinter or some other GUI and "on-click" take the output from the edit开发者_如何转开发or into the python script for the crunching bit.

Thanks for any pointers - book chapters, useful projects/libraries and links to examples would be great.


If you go for JavaScript I'm assuming it would run in a browser and therefore to communicate with anything else it would make HTTP requests (e.g. POST or GET URLs), so the client/server arrangement is unavoidable.

Therefore you would need to turn your Python code into a web application, using something like CherryPy to map URLs to your methods. You could then pass data around using JSON notation.


The best solution for this problem is surely Jython (http://www.jython.org/). With this you can call your python code from Java and even use the Java API in python (i.e. create a java object and return it).

The only downside is that it only supports Python 2 (and that you get a bit longer startup times). So if you wrote your script in Python3 you would need to port it (depending on what exactly you're doing that may be a bit of work).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜