[Pythonmac-SIG] Python, Jython, Cocoa and Charleroi

Dinu Gherman gherman@darwin.in-berlin.de
Mon, 03 Jun 2002 19:43:52 +0200 (CEST)


Quoting Ronald Oussoren <oussoren@cistron.nl>:

> I'm definitely interested in Python and Cocoa, but not going to 
> Chareroi. How are Jython and Cocoa working out?
>
> We (Frans Schippers, Jack Jansen and myself) are working on calling 
> Cocoa from CPython, using the pyobjc module as a starting point. 
> Loading NIB files works just fine, connecting the NIB to python will 
> require some work.

Jython and Cocoa could work very nicely together! Apple has an 
equivalent Java API for its frameworks and I find it to be more
natural to use than anything pyobjc-like that I've seen so far,
one reason being that it doesn't result in plenty of underscores
and parantheses that seem to be needed for simulating Objective-
C's method signatures in Python.

Also, pyobjc development seems to be more or less stalled (?), so 
I've never been sure what to expect from that side in the not so
distant future.

I've added below some of the most simple test functions from my 
growing test suite just to give you an idea...

Regards,

Dinu


from com.apple.cocoa.foundation import *
from com.apple.cocoa.application import *
from java.net import URL

    def play(self):
        sound = NSSound("bong.wav", 0)
        result = sound.play()
        assert result == 1

    def openURL(self):
        url = "http://www.reportlab.com"
        res = NSWorkspace.sharedWorkspace().openURL(URL(url))
        assert 1

    def launchApplication(self):
        name = "Acrobat Reader 5.0"
        res = NSWorkspace.sharedWorkspace().launchApplication(name)
        assert res

    def beep(self):
        NSApplication.beep()

    def localizedStringForKey(self):
        import os
        myBundle = NSBundle.bundleWithPath(os.getcwd())
        locString = myBundle.localizedStringForKey("Cut", None, None)
        expected = "Ausschneiden"
        assert locString == expected

    def mutableArray(self):
        myPool = NSAutoreleasePool.push()
        a = NSMutableArray((1, 2, 3))
        assert a.objectAtIndex(0) == 1
        assert a.objectAtIndex(1) == 2
        assert a.objectAtIndex(2) == 3
        NSAutoreleasePool.pop(myPool)

    def currentUserName(self):
        currentUserName = NSSystem.currentUserName()
        assert currentUserName == 'dinu'