[Pythonmac-SIG] Python, Jython, Cocoa and Charleroi
Dinu Gherman
gherman@darwin.in-berlin.de
Mon, 17 Jun 2002 09:46:53 +0200
Jack Jansen wrote:
>
> What's the convention used by Apple's Java<->ObjC bridge? I don't
> like all the underscores either, and if Apple decided not to do
> any underscores I think pyobjc should follow suit. It could always
> have a compile-time option to give the old _ names, for backward
> compatibility.
I'm not sure there is a formal convention. Obj-C signatures
are "richer" in a sense that you can say:
[obj doItWithFoo:arg1 andBar:arg2 andQuit];
which in Java would probably become:
obj.doItWithFooAndBarAndQuit(arg1, arg2);
The Java Cocoa-API tries hard to come as close as possible
to the "original meaning" of Obj-C signatures, but in some
cases this might be difficult to achieve.
> Well, as mentioned here before there's now three of us happily
> hacking at it. Unfortunately the folks over at the pyobjc mailing
> list are in deep slumber: two of my mails are still waiting in
> their mail queue (and have been for almost 2 weeks now) and a
> message directly to Steven Majevski has also remained unanswered,
> so I think he's off on holidays or otherwise occupied.
Yes, I meant the pyobjc mailing list which looked, uhm, coma-
tose. If you have something to play with I might want to give
it a try, perhaps.
> Do you have an example of a Jython program with a NIB? That's what
> we're currently working on for pyobjc, and we're getting some posi-
> tive results (we have a Python applet with a .nib and it fills an
> on-screen table with data from a Python table source object (just
> before crashing hard:-)), but it would be nice to see how things
> are done in Jython.
Well I have some trivial code, but it doesn't work! ;-) Most
likely, that's because of some problem in establishing a re-
cognized owner relationship and providing the callable methods
in the owner (omitted in the next snippet):
result = NSApplication.loadNibNamed("AlertPanel", owner)
OTOH, some other trivial code *does* work (well, "most of the
time", as there seem to be some Jython issues left to meditate
over as well...). See below.
Regards,
Dinu
# watchLuxoJr.py
import sys
sys.path.append("/System/Library/Java")
from java.net import URL
from com.apple.cocoa.foundation import *
from com.apple.cocoa.application import *
from com.apple.cocoa.application.NSWindow \
import TitledWindowMask, ClosableWindowMask, Buffered
class Cinema:
def fetch(self, url):
self.movie = NSMovie(URL(url), 0)
def show(self, format):
width, height = format
winRect = NSRect(100, 200, width, height)
myView = NSMovieView()
myView.setMovie(self.movie)
myStyle = TitledWindowMask | ClosableWindowMask
myWindow = NSWindow(winRect, myStyle, Buffered, 0)
myWindow.setContentView(myView)
myWindow.makeKeyAndOrderFront(None)
myView.gotoBeginning(self)
myView.start(self)
def main():
url =
'http://www.pixar.com/theater/shorts/ljr/quicktime/ljr_180.mov'
format = (180, 116)
c = Cinema()
c.fetch(url)
c.show(format)
myPool = NSAutoreleasePool.push()
app = NSApplication.sharedApplication()
main()
app.run()
NSAutoreleasePool.pop(myPool)
sys.exit(0)