A program is a process, not a thing. This also applies to life, the universe, and everything.


A New Renaissance

Yesterday I laid out the issues I have with using Interface Builder to create Cocoa applications (whether in Objective-C or Python), and my requirements for a replacement. To sum up, here are the requirements again

As I hinted at previously, I think I've found the tool I was looking forin GNUstep Renaissance, and as an added bonus, it can be used to create applications for Linux, unix, and Windows using the GNUstep framework. So although I'm interested mainly in building applications for OS X, there is still a chance for cross-platform compatibility.

So what does Renaissance look like? It's and XML format, similar to HTML and Mozilla XUL (but simpler than XUL). Today I will cover how to install Renaissance and set it up to use from PyObjC.

Prerequisites (this is my setup, others may work, but I haven't tested them).

  1. A Mac

  2. OS X (10.3)

  3. PyObjC (1.1), available from http://pyobjc.sourceforge.net/

  4. py2app (0.1.4), available from http://pythonmac.org/wiki/py2app (we'll use this to build our double-clickable applications)

  5. Renaissance framework (0.8), available from http://www.gnustep.it/Renaissance/Download.html (this is the secret sauce)

Once you have the prerequisites installed, you need to make Renaissance available from Python. In your site-packages directory (on my machine this is /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages) add a Renaissance directory containing the following file:


import objc, AppKit, Foundation
objc.loadBundle('Renaissance', globals(),
del objc, AppKit, Foundation

Well, that was easy enough. Next up, a Hello World application.

Wow. This is interesting.

Do you know if there is an easy way to run the hello.py script without having to turn it into an application?
One of the things about Cocoa, and thus PyObjC, is that it expects applications to be run inside of a bundle (a specific set of folders). Building hello.py as an application creates those folders. So when you try to run, for instance:

pythonw hello.py

It will complain that it can't find MainMenu.gsmarkup or MainWindow.gsmarkup, because it is looking for them in a bundle, and the bundle it's finding is the pythonw bundle, not the hello.py bundle.

You could make it load by changing the paths for the gsmarkup files to be explicit, but I'm not sure if that would work, and it would almost certainly break things down the road, which would be harder to figure out.

If you're developing an application, it can be annoying to have to keep building it each time you touch a file (that loses a lot of the benefit of Python, after all). So what you can do is build it with

python setup.py py2app --alias

which will not copy the files, but just make aliases to them. It's very fast and you only have to do it again during development if you add new files to your project. Then you can work on your files (both Python and Renaissance) at will without having to rebuild. Of course, before you distribute your app you should rebuild it without the alias flag.

I hope this helps.
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?