Macintosh Python crash course
This set of documents provides an introduction to various aspects of
Python programming on the Mac. It is assumed that the reader is
already familiar with Python and, to some extent, with MacOS Toolbox
programming. Other readers may find something interesting here too,
your mileage may vary.
There is a companion document Using Python on the Mac
which you should read before starting here: it explains the basics of using
python on the Macintosh.
Another set of Macintosh-savvy examples, more aimed at beginners, is
maintained by Joseph Strout, at
http://www-acs.ucsd.edu/~jstrout/python/.
The Python Library
Reference contains a section on Macintosh-specific
modules that you should also read. Documentation is also available
in PostScript and other forms, see the documentation section on the
webserver.
Some of these documents were actually written a long time ago and have seen
little maintainance, so use with care.
Table of contents
-
Using python to create Macintosh applications,
part zero whets your appetite by showing you how to ask the user
for a filename, and how to display a message. It explains about end-of-line
confusion while doing so.
-
Using python to create Macintosh applications,
part one explains how to create a simple modal-dialog application
in Python. It also takes a glance at using the toolbox modules Res and
Dlg, and EasyDialogs for simple question-dialogs.
-
Using python to create Macintosh applications,
part two turns the previous example program into a more complete
mac application, using a modeless dialog, menus, etc. It also explains
how to create applets, standalone applications written in Python.
-
Using FrameWork and TextEdit shows you
how to use
FrameWork
application framework and the
TextEdit
toolbox to build a text editor.
-
Using WASTE expands on this editor by using
WASTE, an extended TextEdit replacement.
-
Creating a C extension module on the Macintosh
is meant for the hardcore programmer, and shows how to create an
extension module in C. It also handles using Modulator to create the
boilerplate for your module, and creating dynamically-loadable modules
on PowerPC Macs.
-
Using Open Scripting Architecture from Python explains
how to create a Python module interfacing to a scriptable application,
and how to use that module in your python program.
-
Using python to create CGI scripts is a preliminary
introduction to writing CGI scripts in Python and to writing scriptable applications
in Python.
-
Building Mac Python from source explains
how to build a PPC or 68K interpreter from a source distribution.
-
Embedding Python on the Mac is a minimal example of
how to embed Python in other Mac applications.
-
Building Standalone applications in Python
explains how you can create real standalone applications in Python. You do
need source (and a C development environment) for this at the moment.
The Python distribution contains a few more examples, all unexplained:
-
PICTbrowse is an application that locates PICT
resources and displays them, it demonstrates some quickdraw and the
resource and list managers.
-
Imgbrowse displays image files in
many different formats (gif, tiff, pbm, etc). It shows how to use the
img modules on the mac.
-
Quicktime has the standard
MovieInWindow
and
VerySimplePlayer
examples, re-coded in Python.
-
Resources, Sound and Speech have some examples
on using the respective managers. In the Mac:Lib folder you
will also find modules that do useful things with the Communications
Toolbox, the Finder interface, etc.
-
Printing has an example on using the Printing module to, you guessed
it, print from Python. The code is somewhat self-documenting. Donated
by Just van Rossum, who also donated the Printing module itself.
At some point in the (possibly distant) future, I will add chapters on
how to use bgen to create modules completely automatic and how to make
your Python program scriptable, but that will have to wait.
Please let me know if you miss critical information in this
document. I am quite sure that I will never find the time to turn it
into a complete MacPython programmers guide (which would probably be a
400-page book instead of 10 lousy html-files), but it should contain
at least the information that is neither in the standard Python
documentation nor in Inside Mac or other Mac programmers
documentation.
Jack Jansen,
jack@cwi.nl, 27-Apr-98.