On Jan 9, 2004, at 9:06 PM, Pete Shinners wrote:
J. Michael McGarrah wrote:
Adding the default TTF file fixed it. It has to be in the same
location as the EXE like you both said.
Excellent! Now I need to make the error in this case a little more
reasonable.
Pete, what do you think about coming up with a smarter scheme for
resource acquisition?
In the case of Mac OS X (with bundlebuilder), I'd like to be able to
override where pygame looks for the ttf file. By default
bundlebuilder uses the zip import hook, so __file__ of the module
isn't going to be a good place to try and open a ttf file at :) I'd
like to shorten the bundlebuilder command line for pygame based
applications significantly. I've written (unreleased) tools and a
revised version of bundlebuilder that walks all of the extensions for
non-system shared libraries and frameworks, then relocates their
mach-o headers so it can stuff them into the app bundle. All that I
have left is this pesky "--package=pygame" command line argument due
to these necessary data files. Other than that "bundlebuilder2
--standalone mypygameapp.py" does all the necessary magic to make a
standalone application!
In any case, I'm thinking that such a resource acquisition module
should expose a simple API along the lines of:
import resfinder
myfilename = resfinder.fileInPackage('pygame', 'something.ttf')
and perhaps even
myfilelikeobj = resfinder.fileobjInPackage('pygame', 'somedatafile')
if an actual on-disk file is not necessary. This would be useful in
the case of py2exe, where the data would have to go in the exe
somewhere (perhaps zipped or some such).. a file-like object could be
created that accesses 'somedatafile' directly without decompressing
the whole thing to a temp folder. At worst case it would do the copy,
but on __del__ or close it could clean up.
When using this theoretical resfinder module, you should have some
kind of manifest that sits in your package somewhere that lists the
non-python-code files that are necessary for correct operation.
Future versions of "freeze" applications would know about resfinder
and its manifest files and make provisions to (a) put the required
data files somewhere (b) throw a manifest file or bootstrap code
somewhere such that resfinder is aware of where and how it should
acquire these data files. A distutils extension could be developed to
generate resfinder manifest files at setup.py time.
I have not done any research to see if a module like this already exists.
-bob