[Pythonmac-SIG] Python control/integration of a Cocoa/Quicktime application?

Dethe Elza delza at livingcode.org
Sat Nov 3 08:06:04 CET 2007


On 11/2/07, Darran Edmundson <darran at edmstudio.com> wrote:
>  > The bare minimum you need is:
>  > import objc
>  > objc.loadBundle('MyBundle', globals(),
>  > bundle_path='/my/bundle/path/MyBundle.framework')

One more thing.  While the above is a bare minimum from the command
line or to work with the framework locally, you'll need a skintch more
to get the file paths to work when the framework is packaged into your
application bundle.  Below is an example I use to package Tim
Omernick's CocoaSequenceGrabber framework, and it works both from the
command line and in the app bundle.  I have this saved as
PySight/__init__.py and can then use all the framework objects and
methods by simply importing PySight in my project.

Again, if any of this is not clear, or you're not sure how to
customize this to your project, just let me know.

import objc, AppKit, Foundation, os
if 'site-packages.zip' in __file__:
  base_path = os.path.join(os.path.dirname(os.getcwd()), 'Frameworks')
else:
  base_path = '/Library/Frameworks'
bundle_path = os.path.abspath(os.path.join(base_path, 'CocoaSequenceGrabber.fram
ework'))
objc.loadBundle('CocoaSequenceGrabber', globals(), bundle_path=bundle_path)
del objc, AppKit, Foundation, os, base_path, bundle_path

--Dethe


More information about the Pythonmac-SIG mailing list