[Pythonmac-SIG] [OSX/Jython] reanimating Cocoa Nibs from Python (fwd)

Steven D. Majewski sdm7g@minsky.med.virginia.edu
Tue, 6 Mar 2001 12:28:45 -0500 (EST)


FYI: Obviously, this doesn't completely work, or I wouldn't
have been asking for help, but I'm forwarding a copy to
pythonmac-sig, just in case any of you want to try this at home!
( You obviously have to have build one of the Cocoa tutorials:
   TempConverter or CurrencyConverter, before you try this in
    jython. And if you try it from a file rather than interactively,
    you should wrap the NSAutorelease.push() in a try:except:
    block -- if you get the exception, then "print NSBundle.allFrameworks()"
    and call the push method again. I'm mystified as to why this
    happens. )


-- Steve.

---------- Forwarded message ----------
Date: Tue, 6 Mar 2001 12:16:22 -0500 (EST)
From: Steven D. Majewski <sdm7g@minsky.med.virginia.edu>
To: macosx-dev@omnigroup.com
Subject: reanimating Cocoa Nibs from Python


Since creating windows and menu's programatically seems rather
pointless and tedious in Cocoa, I've been trying to figure out
how to get Python to load nibs from InterfaceBuilder.

(I've been experimenting with both the C based Python 2.1b1
 (which now builds out of the box on OSX -- unfortunately that's
 probably broken the Darwin build. ) <http://www.python.org/>
 plus  PyObjC  <http://sourceforge.net/projects/pyobjc/>, and
 the JVM based Jython <http://www.jython.org/>. I've made a
 bit more progress with Jython, so that's what's used in the
 examples below. BTW: you have to add /System/Library/Java to
 classpath for Jython to be able to load cocoa classes. )


Since IB doesn't yet support other languages like Python, I started
trying to load the Nibs from the CurrencyConverter and Java TempConverter
examples from the tutorials.


The following code snippet works (as far as it goes) for both
converter examples (depending on the path used):

--- Jython example:

from com.apple.cocoa.foundation import *
from com.apple.cocoa.application import *

tpath = '../TempConverter/build/TempConverter.app'
cpath = '../CurrencyConverter/build/CurrencyConverter.app'

pool = NSAutoreleasePool.push()
MyApp = NSApplication.sharedApplication()
bndl = NSBundle.bundleWithPath( cpath )
nib = NSApplication.loadNibFromBundle( bndl, 'MainMenu', MyApp )
MyApp.run()


---


loading the nibs generates the following error message, which is, I
guess, to be expected, since I'm loading the nibs from a different
program not containing the appropriate classes. However, all of the
default actions of the window work properly: it can be selected and
moved around, minimized, and the tab item selection works as it
should.


Mar 06 11:27:51 java[344] Unknown class `Converter' in nib file, using
`NSObjec\
t' instead.
Mar 06 11:27:52 java[344] Unknown class `ConverterController' in nib file,
usin\
g `NSObject' instead.
Mar 06 11:27:52 java[344] Could not connect the action convert: to target
of cl\
ass NSObject



The question is how to connect the actions to new targets (Python
methods) ?

NSNibConnector sounds like it may be what I want, but:
 The docs just say: "Description forthcoming", and
 I don't see a Java version -- only objective-c bindings.


-- Steve Majewski <sdm7g@Virginia.EDU>



( PS: Sometimes, but not always, and not initially, I get the following
  error from the NSAutorelease.push() call. Since it's a java.lang
  error, it's likely not a jython bug, but a JVM problem bubbling up.
  If I execute a statement like:  "print NSBundle.allFrameworks()",
  for example, I can retry the operation and it will succeed with
  no exceptions.   Any clues as to the cause ?

java.lang.UnsatisfiedLinkError: push
        at com.apple.cocoa.foundation.NSAutoreleasePool.push(Native Method)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java
:158)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java
:166)
        at org.python.core.PyObject.__call__(PyObject.java:260)
        at org.python.core.PyObject.invoke(PyObject.java:2092)

)

_______________________________________________
MacOSX-dev mailing list
MacOSX-dev@omnigroup.com
http://www.omnigroup.com/mailman/listinfo/macosx-dev