views:

88

answers:

5

I am about to begin a project where I will likely use PyQt or Pyside.

I will need to interface with a buggy 3rd party piece of server software that provides C++ and Java APIs. The Java APIs are a lot easier to use because you get Exceptions where with the C++ libraries you get segfaults. Also, the Python bindings to the Java APIs are automatic with Jython whereas the Python bindings for the C++ APIs don't exist.

So, how would a CPython PyQt client application be able to communicate with these Java APIs? How would you go about it?

Would you have another separate Java process on the client that serializes / pickles objects and communicates with the PyQt process over a socket?

I don't want to re-invent the wheel... is there some sort of standard interface for these types of things? Some technology I should look into? RPC, Corba, etc?

Thanks, ~Eric

A: 

If you want to maintain complete isolation and increase your robustness (the 3rd party library going down and not taking your client, and if it's buggy I would recommend that) then perhaps something like CORBA is the way forwards. Don't forget that Java comes with a CORBA implementation as standard, so you just need to generate your C proxy from the IDL.

Swig may be of interest if you want to run stuff in-process. It simplifies the binding of components in different languages. Note in particular that it generates bindings for Python and Java.

Brian Agnew
A: 

If the criteria is not reinventing the wheel, there is the SimpleXMLRPCServer and xmlrpclib modules available in the standard library. They should work in Jython too.

Wai Yip Tung
A: 

There appear to be Java bindings for Qt. ( Google: "Java Qt bindings" )

Maybe it would be simpler just to use them from Jython.

Qt Jambi : http://en.wikipedia.org/wiki/Qt_Jambi

or

Qt Java : http://sourceforge.net/projects/qtjava/

( haven't tried them myself, so no idea how well they'll work. )

And here is a relevant SO thread.

Steven D. Majewski
+1  A: 

You can call Java from C-Python via JPype

http://jpype.sourceforge.net/

Blauohr
A: 

Please see a related question, where I recommended execnet. It seems to be the right solution to these sorts of problems if you want to write the integration in Python (like me).

Jim Baker
Unfortunately I cannot use it as it is GPL. At first glance it looks nice but why GPL when Python itself is more free? Oh well.
eric.frederich
Your comment is valid. It's clear from an email (http://www.mail-archive.com/[email protected]/msg00566.html) by execnet's principal author that the GPL license is intended for your class of problem. I do like the simplicity of execnet, and it would seem that the piece most likely to cause IP problems - combining Pythons in a parent-child process relationship (popen) - is also the easiest to replace. See this simple code example, http://codespeak.net/execnet/example/hybridpython.html#work-with-java-objects-from-cpython]. Maybe someone should write this subset :)
Jim Baker