[Jython-users] Re: [Pythonmac-SIG] Cocoa from Jython on MacOSX

Steven D. Majewski sdm7g@virginia.edu
Wed, 28 Feb 2001 11:38:18 -0500 (EST)


On Wed, 28 Feb 2001, Finn Bock wrote:

> >% cd jython-2.0/
> >% setenv CLASSPATH /System/Library/Java/
> 
> I wonder, would other java programs which access Cocoa, also need this
> setenv? 
> 
> It is possible that ordinary java programs don't need it, in which case
> your solution is a good answer to a faq.

Since I didn't see any mention of this setting in Apple's Java/Cocoa
examples, I'm guessing that if you use ProjectBuilder/InterfaceBuilder
(Apple's GUI developer frontend tools -- which the example code does
use) it probably gets magically taken care of for you, but if you use
command-line javac/java tools, it needs to be told where to look. 

( I'll test the assumption when I have a chance )


I changed the jython shell script to add the path:

/System/Library/Frameworks/JavaVM.framework/Versions/1.2/Home/bin/java
-Dpython.home=/Users/sdm7g/jython-2.0 -classpath
"/Users/sdm7g/jython-2.0/jython.jar:/System/Library/Java:$CLASSPATH" org.python.util.jython
"$@"


I don't know anything about how the installer works -- if there is a place
for platform dependent mods, it might be nice to add that. (Also: strictly 
speaking, the initial path OUGHT to be:
	 /System/Library/Frameworks/JavaVM.framework/Home/bin/java
which is symbolically linked to the current version. This script works,
but it won't antomatically track any Java upgrades. If it's not simple
to change, you might just want to keep it in mind as another possible
FAQ -- you may need to reinstall jython if you upgrade Java VM. )   


I was able to get a slightly modified version of one of my PyObjC 
AppKit  test programs to work in Jython. The main difference is 
that the CPython <-> Objective-C bridge does a different name
mangling than the Java bridge does. PyObjC tries to pythonify
the objective-C method names -- for example 

the objective-c statement:

 [ win initWithContentRect:rect styleMask:mask  backing:YES defer:NO ];

actually uses the message selector:

  initWithContentRect:style:Mask:backing:defer: 

which gets name mangled by PyObjC to:

  win.initWithContentRect_styleMask_backing_defer_ (frame, mask, YES, NO )


but Jython gets to use the Java bridge's use of Java overloading of
different polymorphic versions of the same method name (so there are
a couple of different initWithContentRect 's with different numbers
of args. ).

In Jython:

  win.initWithContentRect( frame, mask, YES, NO )


( I don't know yet what happens when there are are two objective-c
  methods with the same number but different args. ) 

I think there was some discussion on the old pyobjc-sig mailing list
on whether or not to attempt this sort of overloading or to keep the
more explicit name transformation. We may wish to revisit this 
decision -- it would be nice to have the same Cocoa bindings for Jython 
and CPython+PyObjC. 


-- Steve Majewski