[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] pygame for OSX



On Tuesday, Feb 11, 2003, at 03:54 America/New_York, Pete Shinners wrote:

Bob Ippolito wrote:
It dawned on me a couple days ago that with PyObjC as far as it is, and using some of the tricks that they used, it'd be possible to make *completely self-contained* pygame applications that run on OS X 10.2+ using the installed python.
i hope this is a step forward to a self contained 'pygame library' as well? andrew straw has been feeding me a couple patches for the SDL_main.m (more this morning) to help get OSX running better. renaming the 'time' module shouldn't be a big problem anymore, since i can 'rename' it on import in the __init__.py for pygame.
Thats more or less what I did, except I did echo "from pygametime import *" > time.py, instead of the sys.modules hack. pydoc tends to work better on C extensions like that for some reason anyhow.

The pygame library can be distributed separately (into site-packages), but the rub is that you can't start pygame programs from the command line without ninja skills (using python 2.2) unless they're in an application bundle. You pretty much have to use Project Builder (Apple's development IDE.. similar in concept to visual studio) and a particular template (a modified version of the Python-Objective C Application template, from PyObjC) in order to *run* the application.. The bonus is that once your application is ready to be distributed, you just drag the dependencies to the right places in the application bundle (pygame, pyobjc, SDL, SDL_ttf, smpeg... etc) and you're ready to go.

The reason for this is that in order to connect to Apple's WindowServer (the GUI) you need to execve a separate python binary that resides in an application bundle (don't ask.. it's rather complicated, but it will also let PyObjC find frameworks that you linked into that bootstrap executable without having to find the files explicitly), and on top of that, as a dependency for pygame, you must have both a NSAutoreleasePool and an NSApplication instantiated before you try and do anything GUI-like.

Something similar to the execve trick can be done with shell script/alias trickery if you have such an application bundle:
#!/bin/sh
exec "/./Applications/MacPython-OSX-2.2/python-additions/Python.app/ Contents/MacOS/Python" "$@"

but that doesn't do the PyObjC trickery that pygame needs to function. It's *possible* that it may be added to pygame/__init__.py, by checking for an NSApplication instance.. and if it's not there, create one. I haven't looked into that yet.


As a quick proof of concept, I've ported Pete's excellent solarwolf 1.1: http://www2.mastersofbranding.com/~bob/solarwolf.dmg.tgz
I also changed the first couple lines of solarwolf so it wouldn't change directories based on argv[0], and to add os.getcwd() to the sys.path.insert call.. but that was it.
rad! i'm eager to get this on the solarwolf website too. any needed install instructions? or is it pretty much click and play?
It's exactly click and play, you don't even need to drag the executable out of the disk image.

-bob

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org