Re: [Pyobjc-dev] Real case for using PyObjC bundles
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-11-07 13:55:53
|
On 7 nov 2003, at 12:52, Dinu Gherman wrote: > Has anybody made some experience using such bundles with PyObjC? The > issues, as I mentioned previously, are basically to load the NIB and > instantiate some instance of a controller/owner class to handle it. > The bundles could be considered documents in a document-based app, > but with additional specific NIB files for their configuration. > > I expect the usual ObjC approach using NSBundle's principleClass me- > thod not to be working in PyObjC directly and wonder what the best > approach would be for doing this? I've sort of tried using the PyObjC > tool PyObjCTools.NibClassBuilder.extractClasses() but maybe not sys- > tematically enough yet to succeed. PyObjCTools.pluginbuilder should be useable here, but would be overkill if both the main program and the plugins are Python-based. You could use the approach used by those plugin modules: - Load the bundle using NSBundle - Look for the main python file (either hardcode a name, or use a key in the Info.plist) - Create a new module object, set __path__ to the resources directory of the bundle, and execute the main python file in that module - Now look for the main class using NSBundle.principleClass Setting the __path__ is important, this way the resources directory is treated like a package which makes it possible to use the same module names in two plugins. Ronald |