$title = "PyObjC Examples"; $cvs_author = '$Author: ronaldoussoren $'; $cvs_date = '$Date: 2003/07/05 14:59:47 $'; include "header.inc"; ?>
The directory Scripts contains a number of simple command-line scripts that make use of Cocoa features.
This script is a daemon that will open the ReadMe file in the root of any (removable) volume that is inserted while this script is running.
The script is part of Introduction to PyObjC, an article at O'Reilly MacDevCenter.com.
This script shows how to use PyObjCTools.Debugging to show tracebacks of all (Cocoa) exceptions (handled and unhandled).
Demonstrate the usage of an NSMutableDictionary object with both Objective-C and Python dictionary syntax.
An example of using the AddressBook framework, this script exports some of the information about people in your addressbook to a CSV file.
Demonstrate the usage of objc.loadBundleFunctions to access functionality from the standard C library on Mac OS X (libSystem, which is also available as the System.framework bundle). This example uses the dyld runtime to determine which dylib the Python runtime came from.
Demonstrates a nib-less Cocoa GUI (purely for informational purposes, you probably shouldn't make a habit of this)
XXX An example script that demonstrates how PyObjC interacts with Key-Value Observing (KVO) at the lowest level. This script was used to debug the PyObjC runtime and should not be used as a guideline for writing new KVO code. It may be interesting to some until we ensure that we have proper unit tests for KVO and remove this example!
Shows how PyObjCTools.Conversion can be used to convert a Python collection into an Objective-C property list. These functions should not typically be necessary as the proxies for Python objects are compatible with Objective-C plists.
Use an NSNetService class to look for servers using rendezvous.
Demonstrates how to get a backtrace when handling a fatal signal using PyObjCTools.Signals.
Demonstrates how to write a console runloop based application that uses NSFileHandle to read stdin asynchronously.
A doctest that demonstrates the subclassing of an Objective-C class from Python. Note that it is typically discouraged to define a __del__ method.
Demonstrates how create a subclass of an Objective-C class that overrides a selector, but calls the super implementation using Python syntax equivalent to [super init].
Another objc.loadBundleFunctions demonstration that shows how to call into a private CoreGraphics SPI and enable full WindowManager access from a process that would not otherwise have it due to a quirk in the implementation of WindowManager (the reason why pythonw should be used instead of python). Use at your own risk!
The directory AppKit contains example applications using the Cocoa Application Framework (aka "AppKit").
Most of the following examples contain a setup.py script that can build an application. See Building applications for details how to invoke these scripts. Some examples contain an Xcode or Project Builder project file; simply double-click it and choose Build and Run, or invoke xcodebuild or pbxbuild from the command line depending on which you have installed.
A simple class browser, demonstrating the use of NSBrowser (a "column view" hierarchical widget) and NSTableView.
A simple NIB based application. Start with this one. Also see the PyObjC tutorial.
A simple one-window demo showing how to custom drawing in a custom NSView. Additionally shows how easy it is to embed a view in an NSScrollView, as well as how to use an NSColorWell.
This shows an simple example of an MVC based application, that also makes use of NSBezierPaths. Contains a Project Builder project, as well as a setup.py script.
The application calculates the field pattern and RMS field of an antenna array with up to three elements.
Demonstrates how to use Carbon global hot keys from a PyObjC application. Also demonstrates how to use a NSApplication subclass.
A more elaborate class browser; demonstrates NSOutlineView and NSTableView.
An implementation of the MacPython PackageManager application using Cocoa.
A full featured embedded Python interpreter. This demonstrates more complicated uses of NSTextView, manual event dispatching, and the new text completion feature of OS X 10.3.
A reimplementation of the Python script launcher helper application in PyObjC.
A reusable Python object browser, demonstrating the use of NSOutlineView as well as how to use an NSWindowController subclass to create a window from a menu action.
Shows how to implement entries for the Services menu.
Basic demo that shows how to use a NSTableView.
A minimal Document-based text editor application.
Another simple service, this one converts URL or strings from the pasteboard to tinyurl.com equivalents.
A more complex NIB based applications. This is a document-based application. The code is a translation into Python of an example project in Learning Cocoa from O'Reilly
Queries an XML-RPC enabled web server for the methods that it implements. Demonstrates a more advanced use of an NSTableView, how to make a toolbar as well as how to use multi-threading. Contains a Project Builder project as well as a setup.py script.
The CocoaBindings directory contains a number of examples that make use of Key-Value Coding and Cocoa Bindings. These scripts require Mac OS X 10.3 or later.
Shows custom array controller that implements table view data source methods to support drag and drop, including copying objects from one window to another, drop of URLs, and re-ordering of the content array.
Originally from Cocoa Bindings Examples and Hints, converted to PyObjC by u.fiedler.
Demonstrates how to use Cocoa Bindings to simplify storing and retrieving user preferences. Also demonstrates how to use an NSValueTransformer to archive/unarchive a non-property-list type automatically (NSColor, in this case).
Originally from Cocoa Bindings Examples and Hints, converted to PyObjC by u.fiedler.
A rewrite of CurrencyConverter using Cocoa Bindings.
Originally from Introduction to Developing Cocoa Applications Using Bindings, converted to PyObjC by u.fiedler.
Demonstrates how to subclass NSArrayController to implement filtering of a NSTableView. Also demonstrates the use of indexed accessors.
Originally from Cocoa Bindings Examples and Hints, converted to PyObjC by u.fiedler.
Shows the use of a custom controller, a value transformer, and two custom bindings-enabled views. One view is a control that allows you to set the angle and offset of a shadow; the other view observes and displays a collection of graphic objects.
Originally from Cocoa Bindings Examples and Hints, converted to PyObjC by u.fiedler.
A simple example that illustrates establishing bindings programmatically, including a number of options such as validation and an array operator, and indexed accessor methods. A custom model object implements custom validation method.
Originally from Cocoa Bindings Examples and Hints, converted to PyObjC by u.fiedler.
Shows how to fill an NSTableView using Key-Value Coding. Contains contains an Xcode project as well as a setup.py script.
A more advanced example of Key-Value Coding. This uses a custom NSArrayController. Contains contains an Xcode project as well as a setup.py script.
An example that uses NSValueTransformer to convert between Celsius and Fahrenheit.
Based on Apple's Value Transformers documentation, converted to PyObjC by u.fiedler.
Shows two array controllers, one to manage the contents of a table view, the other to manage a pop-up menu in a table column. Also shows two value transformers to alter the color of text.
Originally from Cocoa Bindings Examples and Hints, converted to PyObjC by u.fiedler.
The directory CoreData contains a number of examples that use the CoreData framework. This framework is available in MacOS X 10.4 and later.
A python version of the OutlineEdit example that's included with Xcode 2.0.
The directory Foundation contains a number of examples that use only Foundation facilities.
Demonstrates the use of Key-Value Observing from a simple script, without a runloop. Requires Mac OS X 10.3 or later.
The directory Inject contains a number of examples that use the objc.inject facility to inject code into another process. These examples require Mac OS X 10.3 or later.
A proof of concept IDN spoofing defense for Safari (tested with v1.2.4 on Mac OS X 10.3.8). Demonstrates how to write an application that detects the launch of another application by bundle identifier, how to use objc.inject to load code into another application, how to override the implementation of an existing class but still call back into the original implementation, and how to reduce the size of such an application/plugin combination by using symlinks to share object files (the PyObjC extensions in this case).
Shows how to inject an in-process Python interpreter into another process. Based on the AppKit PyInterpreter example.
Shows how to inject an in-process Python class browser into another process. Based on the AppKit ClassBrowser example.
The directory OpenGL contains a number of examples that use OpenGL with a Cocoa UI. These examples also require PyOpenGL.
A simple program that shows how to use OpenGL in a Cocoa program. It is a port of Apple's "CocoaGL" example.
The directory Plugins contains a number of examples that embed a Python plugin into another application. Note that due to an implementation detail of the py2app bundle template, these plugins are only compatible with Mac OS X 10.3 and later.
This NSPreferencePane can be used to edit the default environment for the current user. It also is a simple example of a localized application.
A simple InterfaceBuilder palette written in Python.
A simple screensaver written in Python.
Uses the new WebKit Cocoa plugin API available in Safari 1.3 and later to embed a PyInterpreter in the browser.
The directory Twisted contains a number of examples that use Twisted (2.0 or later) with Cocoa.
This is a refactor of the WebServicesTool example that is made much simpler and faster by using Twisted.
WebServicesTool-ControllerLayer
This is an even simpler refactor of the Twisted WebServicesTool example that uses Cocoa Bindings to remove a lot of the UI related code.
The directory WebKit contains a number of examples that use the WebKit framework, the HTML rendering engine from Safari.
This example implements a subclass of NSURLProtocol that can be used to load the pydoc documentation of a module.
It also includes a simple documentation browser using WebKit and the PyDocURLProtocol class.
The directory NonFunctional may contain a number of examples that are not working for one reason or another. The most likely reason is that example relies on features that have not yet been implemented.