PyObjCTools: The PyObjC Toolbox

Introduction

The package PyObjCTools contains a number of (basicly unrelated) modules with usefull functionality. These have been placed inside a module to avoid cluttering the global namespace.

The rest of this document provides documentation for these modules, but lets start with a short overview.

Utility functions for use with the AppKit module.

Functions for converting between Cocoa and pure Python data structures.

A python API for working with Key-Value Coding.

Module containing a magic super-class that can read information about the actual super-class and implemented actions and outlets from a NIB file.

Extension of bundlebuilder (XXX: Link) that allows you to build python-based plugin bundles, such as panes for the System Preferences application and screen savers.

Module that tries to print usefull information when the program gets a fatal exception. This module should only be used during development.

PyObjCTools.AppHelper

This module exports two functions that are usefull when working with the AppKit framework.

PyObjCTools.Conversion.py

Functions for converting between Cocoa and pure Python data structures.

PyObjCTools.KeyValueCoding

A module for working with Key-Value Coding in python. Key-Value coding is explained on the apple website

This module provides a python interface to some of that functionality. The interface is modelled on the getattr and setattr functions.

PyObjCTools.NibClassBuilder

Extracting class definitions from nibs

The module maintains a global set of class definitions, extracted from nibs. To add the classes from a nib to this set, use the extractClasses() function. It can be called in two ways:

extractClasses() can be called multiple times for the same bundle: the results are cached so no almost extra overhead is caused.

Using the class definitions

The module contains a "magic" base (super) class called AutoBaseClass. Subclassing AutoBaseClass will invoke some magic that will look up the proper base class in the class definitions extraced from the nib(s). If you use multiple inheritance to use Cocoa's "informal protocols", you must list AutoBaseClass as the first base class. For example:

class PyModel(AutoBaseClass, NSTableSource):
    ...

The NibInfo class

The parsing of nibs and collecting the class definition is done by the NibInfo class. You normally don't use it directly, but it's here if you have special needs.

The command line tool

When run from the command line, this module invokes a simple command line program, which you feed paths to nibs. This will print a Python template for all classes defined in the nib(s). For more doco, see the commandline_doc variable, or simply run the program wothout arguments. It also contains a simple test program.

PyObjCTools.Signals

This module provides two functions that can be usefull while investigating random crashes of a PyObjC program. These crashes are often caused by Objective-C style weak references or incorrectly implemented protocols.

This module is not designed to provide fine grained control over signal handling. Nor is it intended to be terribly robust. It may give usefull information when your program gets unexpected signals, but it might just as easily cause a crash when such a signal gets in.

PyObjCTools.pluginbuilder

This module defines one class to build python based plugin bundles for MacOS X. Examples of plugin bundles include PreferencePanes and InterfaceBuilder palletes.

The PluginBuilder class is instantated with a number of keyword arguments and have a build() method that will do all the work.

XXX: Add documentation about the constructor arguments

The module contains a main program that can be used in two ways:

% python pluginbuilder.py [options] build

% python buildplugin.py [options] build

Where "buildplugin.py" is a user-supplied setup.py-like script following this model:

from PyObjCTools.pluginbuilder import buildplugin

buildplugin(<lots-of-keyword-args>)

The script will tell you about the supported arguments if you run it without any arguments.