473,703 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling (C)Python code from Java: Is it JPype?

I've dev'ed a Python prototype of an app, that besides the internals making
it up has a gui. While test-driven dev'ing the app's internals in Python is
fun as usual, dev'ing the GUI is not so funny, at least for me.

I guess dev'ing a GUI in a test-driven way is not possible, or is it? I'm
using wxPython, so if anyone has an idea...

For now most of the time I extend and change the gui things, then run it, do
the clicks to go thru the new things and - bang: Missing attribute bla bla
bla or an error like that. Yes, I use Pychecker, but it isn't of real help
in gui dev'ing (at least in my GUIs ;-)).

So, a compiler could ease things a bit here. While I want the complicated
stuff remaining written in Python, I'd write the GUI things in Java. Java,
because I plan to run the app on Linux too (dev'ing on Windows for now).
Otherwise *.NET could be an option (well, perhaps I should look at Mono).

Now, if I go the Java route, how can I call my Python stuff from Java, if I
do not want to use Jython, which lags behind CPython 3 minor versions (2.1.
vs. 2.4)? Google showed up JPype, but this seems to enable me the other way
round: Call Java code from CPython. Or are there any plans to make this
possible the other way round too?

Any other options here?

Many thanks in advance
Franz GEIGER


Jul 18 '05 #1
9 3764
F. GEIGER wrote:
I've dev'ed a Python prototype of an app, that besides the internals making
it up has a gui. While test-driven dev'ing the app's internals in Python is
fun as usual, dev'ing the GUI is not so funny, at least for me.

I guess dev'ing a GUI in a test-driven way is not possible, or is it? I'm
using wxPython, so if anyone has an idea...

For now most of the time I extend and change the gui things, then run it, do
the clicks to go thru the new things and - bang: Missing attribute bla bla
bla or an error like that. Yes, I use Pychecker, but it isn't of real help
in gui dev'ing (at least in my GUIs ;-)).

So, a compiler could ease things a bit here. While I want the complicated
stuff remaining written in Python, I'd write the GUI things in Java. Java,
because I plan to run the app on Linux too (dev'ing on Windows for now).
Otherwise *.NET could be an option (well, perhaps I should look at Mono).

Now, if I go the Java route, how can I call my Python stuff from Java, if I
do not want to use Jython, which lags behind CPython 3 minor versions (2.1.
vs. 2.4)? Google showed up JPype, but this seems to enable me the other way
round: Call Java code from CPython. Or are there any plans to make this
possible the other way round too?

Any other options here?

Many thanks in advance
Franz GEIGER


Well, lemme see how you can have you cake and eat it too :)

Right now, JPype does not allow you to call Python code "as is".
Besides, adaptic a static language like java to a dynamic language like
python is "easy". Going the other way is ... impossible.

What JPype allows you to do is use Java classes as though they were
regular Python classes. This includes Standard java classes as well as
classes you've written youself.

Somewhere in the back of my head there are plans to make python classes
available to Java. The goal though wil be to be able to make use of the
many frameworks availabel in the Java worlds, be it server technologies
like servlets and EJBs, or client-side stuff like Eclipse.

Aside form that, your problem is exactly one of the problems that
incited me to write JPype. Python GUI toolkits just seem, to my
java-trained mind, too hard to use.

So, what I would do is have Python be the "host", the controller,
calling the JAVA-built GUI and registering listeners. JPype does not
allow subclassing of Java classes in python, but you can crerate JProxy
that "implement" any Java interface. The standard idiom for Java event
and callbacks is based on the use of interfaces anyway. In fact, baring
the very rare cases where Swing requires subclasses, you could crerate
your whole GUI using Swing and not writing a single line of Java.

Hopefully this answers your question. IF you have any, feel free to
contact me through sourceforge.

Steve

Jul 18 '05 #2

"Steve Menard" <fo*@bar.com> schrieb im Newsbeitrag
news:1D******** *********@weber .videotron.net. ..

<snip/>
So, what I would do is have Python be the "host", the controller,
calling the JAVA-built GUI and registering listeners. JPype does not
allow subclassing of Java classes in python, but you can crerate JProxy
that "implement" any Java interface. The standard idiom for Java event
and callbacks is based on the use of interfaces anyway. In fact, baring
the very rare cases where Swing requires subclasses, you could crerate
your whole GUI using Swing and not writing a single line of Java.
Just to be sure that I got you right: I'd write the GUI things in Java and
hook the Python stuff into the GUI by implementing listeners directly or by
implementing interfaces used by the listeners in Python (sorry, yet I'm not
very experienced in Java). For me this sounds like what I want to have: The
GUI in a compiled lang, the gist in Python. If so, I'll give it a try.

Steve


Many thanks, Steve!

Cheers
Franz
Jul 18 '05 #3
>>>>> "f.geiger" == F GEIGER <f.******@vol.a t> writes:
f.geiger> GUI in a compiled lang, the gist in Python. If so, I'll give it a try.

Why GUI in compiled lang? Typically the time in a GUI is spent in a
GUI library, which is native code.

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #4

"Ville Vainio" <vi***@spammers .com> schrieb im Newsbeitrag
news:du******** *****@lehtori.c c.tut.fi...
>> "f.geiger" == F GEIGER <f.******@vol.a t> writes:


f.geiger> GUI in a compiled lang, the gist in Python. If so, I'll give

it a try.
Why GUI in compiled lang? Typically the time in a GUI is spent in a
GUI library, which is native code.
It is not because of the performance. I never had any problems with Python
in this regard. It is because pychecker does not catch all errors *I* make
in *my* GUI programs (YMMV of course). Errors, a compiler typically is able
to catch. It gets really annoying if I aways have to do all the steps again
and again getting to the point the *GUI* part of my app just to see that I
again had missed something. I am willing to give up on flexibilty in the
*GUI* part of my app to receive type safety and in consequence compile time
error checking.

If anyone could show me a way how I can develop the *GUI* part of may apps
in a test driven way, i.e. w/o having to enter data manually all over again,
then I could forget about all this.

Many thanks and kind regards
Franz GEIGER

P.S.: Ville, perhaps you answered to my post because I'd like it to have the
other way round: GUI stuff a compiled lang (but not C++ if possible) and the
gist, which many times is considered time critical by other people, in
Python. But, as I said: I never had performance problems with Python. Python
speeds up dev'ing apps and *app-specific* things because it lets me think
mostly in the problem domain and not in the lang domain. Ever handled
strings, lists etc. in C++ or Java? Forget it! Well, ok, I have to admit:
I'm a Java newbie, yet, and thus I am not allowed yet to rant, actually. But
you got the point: So many things are just easy to do in Python and I don't
want to give up on *that*. OTOH: GUI stuff mostly is a SMOP, nothing special
(possiblities in wx are great, though. I can do things here, I couldn't
dream of doing it in, say, VB). Here a compiler really could make things
easier - for *me* and *my* apps. Again, YMMV.

--
Ville Vainio http://tinyurl.com/2prnb

Jul 18 '05 #5
Ville Vainio wrote:
>>"f.geiger " == F GEIGER <f.******@vol.a t> writes:
>>
>>

f.geiger> GUI in a compiled lang, the gist in Python. If so, I'll give it a try.

Why GUI in compiled lang? Typically the time in a GUI is spent in a
GUI library, which is native code.

Hello,

As I remember, the OP said that he was going to use Java - the
GUI toolkit for that is very nice and extremely portable (no cross
platform niggling little issues 'the window doesn't behave that way on
linux - well it does on windows!!') - the reason for this - Java GUI
(Swing ignore AWT for the point of this - AWT has the same problems as
other native GUI toolkits) is _not_ native. Although I must agree that
using cross language and two separate processes seems like more of a
headache that testing the python code.

Cheers,

Neil

--

Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 47
D-01307
Dresden
Germany

Tel : +49 (0)351 4173 154
e-mail : be**@cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com

Jul 18 '05 #6
In article <ma************ *************** ***********@pyt hon.org>,
Neil Benn <be**@cenix-bioscience.com> wrote:
Jul 18 '05 #7
In article <cj**********@n ewshispeed.ch>, F. GEIGER <f.******@vol.a t> wrote:
Jul 18 '05 #8
>>>>> "geiger" == F GEIGER <f.******@vol.a t> writes:
Why GUI in compiled lang? Typically the time in a GUI is spent in a
GUI library, which is native code.


geiger> It is not because of the performance. I never had any

Ok - just checking. "Compiled language" is so widely abused term,
typically used in the context of performance. You were looking for the
term "statically typed language".

geiger> again had missed something. I am willing to give up on
geiger> flexibilty in the *GUI* part of my app to receive type
geiger> safety and in consequence compile time error checking.

I'm not big on GUI programming, but for me the problem with GUIs, that
a statically typed language would help you catch, is the large amount
of different methods taking a large variety of parameters. You only
need to get them right once, different data sets don't create too many
different situations that would break the GUI. Or at least those parts
that would be helped by static typing.

geiger> If anyone could show me a way how I can develop the *GUI*
geiger> part of may apps in a test driven way, i.e. w/o having to
geiger> enter data manually all over again, then I could forget
geiger> about all this.

Is the UI complex? With simple UIs, the part that needs to interface
with the actual UI library is trivial, and generally not worth unit
testing. TDD the "model"/"document" part of the UI. Or just hack
together some kind of simple UI that you can use to test / demo your
app, and put up the time to create a more sophisticated UI that you
test thoroughly when the rest of the stuff works.

geiger> mostly in the problem domain and not in the lang
geiger> domain. Ever handled strings, lists etc. in C++ or Java?

Have I ever!

HBufC* concat_stringsL (const TDesC& aS1, const TDesC& aS2)
{
HBufR* res = HBufC::NewLC(aS 1.Length() + aS2.Length());
res->Des() = aS1;
res->Des().Append(a S2);
return res;
}

geiger> you got the point: So many things are just easy to do in
geiger> Python and I don't want to give up on *that*. OTOH: GUI
geiger> stuff mostly is a SMOP, nothing special (possiblities in
geiger> wx are great, though. I can do things here, I couldn't
geiger> dream of doing it in, say, VB). Here a compiler really
geiger> could make things easier - for *me* and *my* apps. Again,
geiger> YMMV.

It can make things easier, but the cross-language interface (esp. as
it's a custom one, not a polished one like, say, wxPython is for
wxWindows/C++) can offset the easiness.

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #9
cl****@lairds.u s (Cameron Laird) wrote in message news:<si******* *****@lairds.us >...
In article <ma************ *************** ***********@pyt hon.org>,
Neil Benn <be**@cenix-bioscience.com> wrote:
.
.
.
As I remember, the OP said that he was going to use Java - the
GUI toolkit for that is very nice and extremely portable (no cross
platform niggling little issues 'the window doesn't behave that way on
linux - well it does on windows!!') - the reason for this - Java GUI
(Swing ignore AWT for the point of this - AWT has the same problems as
other native GUI toolkits) is _not_ native. Although I must agree that .
.


Hello,

Comments embedded beneath - BTW please use Neil, Mr Benn is the
name of cartoon in Britain and I get the piss taken out of me for
it!!!!!!
Mr. Benn, you're saying something important here, but something
which merits, at least, qualification. Certainly the Java com-
munity has given considerable attention to the "write once, run
everywhere" goal. My own experience has been that their success
in regard to GUIs is mixed, at best.
<snip>

Err, well with Swing - I experienced very few cross platform issues
when using lightweight components - as soon as I introduce heavyweight
components into the equation - yes these issues start appearing. I
only use AWT when programming Personal Java/Profile (that API doesn;t
include Swing) and it's always a pain moving from one platform to
another. This is just a difference of opinion here and will always be
subjective.

Maybe it would help to clarify a bit--*which* "GUI toolkit" do
you have in mind? I *think* you're talking about Swing--is that
right?
<snip>

Quote from original e-mail - 'Java GUI (Swing ignore AWT for the point
of this'

Yes - swing, although I did embed that bit in brackets
My conclusion: while Java undeniably aspires to be portable in
its GUI, those with a stake in the outcome need to specify clearly
their requirements. Java does *not* currently provide perfect
portability.


I agree there isn't 'perfect portability' (partly because its
difficult to define perfect!!) but it is good - take a look at
something like jedit - it works across all platforms I've tried it on
(OSX, OS9, Windows, Solaris, Linux). For a quick test - get the look
and feel option in most java programs and flick about between the
different models - I think if performs commendably - much better than
the 'wrapper over native' type of GUI toolkits.

As a quick aside - does anyone know of a cross-language non native
GUI toolkit apart from Mozilla?

Cheers,

Neil
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2418
by: Brendan J Simon | last post by:
Hi, I have a Java application from a company. They also provide an API in C++ (MSW platforms only) and Java (for all platforms) for developers that want to create their own front end. I want to use wxPython to create a decent Unix opensource frontend. Is it possible to Interface python to a java application easily ??? Assuming yes to above, would something like Jython or SWIG or some other
0
1299
by: Steve Menard | last post by:
I have a strange problem with Python command-line interactive mode. Problem has been observed on every 2.3 version where it was tested, from 2.3 alpha to 2.3.4 Test is run on windows XP and 2000 I have written a ptyhon extension module called jpype, and run the following code D:\>python
6
22330
by: Dave Kuhlman | last post by:
Is JPE (the Python Java Extension) being used widely/actively? I tried to build it (with Python 2.3.4, j2se 1.4 on Debian GNU/Linux) and had quite a bit of trouble. And, then, the samples did not run. Is there another way to call Java code from Python? The JPE project does not seem too active lately, or is it?
5
3680
by: Maurice Ling | last post by:
Hi, I have read that this had been asked before but there's no satisfactory replies then. I have a module (pA) written in python, which originally is called by another python module (pB), and passes a python object (pO) to pB. Now I require pA to be called in a java class (jC) and pass pO into jC. As pA uses non-python modules, I am not able to use Jython on this.
3
5060
by: Jacques Daussy | last post by:
Hello How can I transfert information between a JAVA application and a python script application. I can't use jython because, I must use python interpreter.I think to socket or semaphore, but can I use it on Windows plateform ? thanks a lot jack
6
3004
by: Chas Emerick | last post by:
This may seem like it's coming out of left field for a minute, but bear with me. There is no doubt that Ruby's success is a concern for anyone who sees it as diminishing Python's status. One of the reasons for Ruby's success is certainly the notion (originally advocated by Bruce Tate, if I'm not mistaken) that it is the "next Java" -- the language and environment that mainstream Java developers are, or will, look to as a...
0
1197
by: datulaida | last post by:
Hi.. How to connect Python with Java. This is my Python program. i use jpype to connect Python with Java. from jpype import * startJVM("d:/Program Files/Java/jdk1.6.0/jre/bin/client/jvm.dll","-ea") jnavClass = JClass("Semantic") jnav = jnavClass() jnavClass.pilih_ayat("i go to school")
1
4341
by: datulaida | last post by:
Hi.. How to connect Python with Java. This is my Python program. i use jpype to connect Python with Java. Code: ( text ) 1. from jpype import * 2. startJVM("d:/Program Files/Java/jdk1.6.0/jre/bin/client/jvm.dll","-ea")
1
5099
by: hofsoc20 | last post by:
Hi, I am trying to call java methods from a python script. Jython is not an option. I have looked at using Jpype. Below is my code thus far: Jpype.py from jpype import * startJVM("C:\Program Files\Java\jdk1.6.0_12\jre\bin\client", "-ea", "-Djava.class.path=%s" % classpath) com =JPackage("CallJavaFromPython")
0
8654
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8983
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8941
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6575
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5910
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4412
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2406
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2037
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.