Starting with version 2.4 PyObjC provides a more efficient, lazy loading metadata system. This can greatly reduce the memory use and startup time for PyObjC based applications while still providing full access to Cocoa APIs.
A framework wrapper with the new metadata system is always a python package. The package contains an “__init__.py” file that creates the lazy loader, a “_metadata.py” file with the compiled metadata and optionally other modules and extensions.
The general structure of the “__init__.py” file is:
import sys, objc
import Foundation
from . import _metadata
sys.modules['FrameworkName'] = objc.ObjCLazyModule('FrameworkName',
"com.apple.FrameworkName',
objc.pathForFramework("/System/Library/Frameworks/FrameworkName.framework"),
_metadata.__dict__, None, {
'__doc__': __doc__,
'objc': objc,
'__path__': __path__,
}, (Foundation,))
The framework name, identifier and path should be replaced by the correct values for the wrapped framework. The import of “Foundation” can be replaced by imports of other framework this framework relies on (also add those to the last argument of objc.ObjCLazyModule).
The exact contents of the “_metadata” module will be described later.
The “objective-metadata” project contains a tool for collecting information about frameworks and compiling that information and manual additions into a “_metadata” module.
That project currently is not a stable as I’d like, this documentation will be updated with more information when that changes.
A subclass of the built-in module type that adds lazy-loading of values defined in PyObjC metadata.
Parameters: |
|
---|
Note
This is the primary entry point for the framework wrappers shipped with PyObjC.