blob: 543f8686cff520f7c168d7f1193777d2e2e5481e [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
2:mod:`MacOS` --- Access to Mac OS interpreter features
3======================================================
4
5.. module:: MacOS
6 :platform: Mac
7 :synopsis: Access to Mac OS-specific interpreter features.
8
9
10This module provides access to MacOS specific functionality in the Python
11interpreter, such as how the interpreter eventloop functions and the like. Use
12with care.
13
14Note the capitalization of the module name; this is a historical artifact.
15
16
17.. data:: runtimemodel
18
19 Always ``'macho'``, from Python 2.4 on. In earlier versions of Python the value
20 could also be ``'ppc'`` for the classic Mac OS 8 runtime model or ``'carbon'``
21 for the Mac OS 9 runtime model.
22
23
24.. data:: linkmodel
25
26 The way the interpreter has been linked. As extension modules may be
27 incompatible between linking models, packages could use this information to give
28 more decent error messages. The value is one of ``'static'`` for a statically
29 linked Python, ``'framework'`` for Python in a Mac OS X framework, ``'shared'``
30 for Python in a standard Unix shared library. Older Pythons could also have the
31 value ``'cfm'`` for Mac OS 9-compatible Python.
32
33
34.. exception:: Error
35
36 .. index:: module: macerrors
37
38 This exception is raised on MacOS generated errors, either from functions in
39 this module or from other mac-specific modules like the toolbox interfaces. The
40 arguments are the integer error code (the :cdata:`OSErr` value) and a textual
41 description of the error code. Symbolic names for all known error codes are
42 defined in the standard module :mod:`macerrors`.
43
44
45.. function:: GetErrorString(errno)
46
47 Return the textual description of MacOS error code *errno*.
48
49
50.. function:: DebugStr(message [, object])
51
52 On Mac OS X the string is simply printed to stderr (on older Mac OS systems more
53 elaborate functionality was available), but it provides a convenient location to
54 attach a breakpoint in a low-level debugger like :program:`gdb`.
55
56
57.. function:: SysBeep()
58
59 Ring the bell.
60
61
62.. function:: GetTicks()
63
64 Get the number of clock ticks (1/60th of a second) since system boot.
65
66
67.. function:: GetCreatorAndType(file)
68
69 Return the file creator and file type as two four-character strings. The *file*
70 parameter can be a pathname or an ``FSSpec`` or ``FSRef`` object.
71
72
73.. function:: SetCreatorAndType(file, creator, type)
74
75 Set the file creator and file type. The *file* parameter can be a pathname or an
76 ``FSSpec`` or ``FSRef`` object. *creator* and *type* must be four character
77 strings.
78
79
80.. function:: openrf(name [, mode])
81
82 Open the resource fork of a file. Arguments are the same as for the built-in
83 function :func:`open`. The object returned has file-like semantics, but it is
84 not a Python file object, so there may be subtle differences.
85
86
87.. function:: WMAvailable()
88
89 Checks whether the current process has access to the window manager. The method
90 will return ``False`` if the window manager is not available, for instance when
91 running on Mac OS X Server or when logged in via ssh, or when the current
92 interpreter is not running from a fullblown application bundle. A script runs
93 from an application bundle either when it has been started with
94 :program:`pythonw` instead of :program:`python` or when running as an applet.
95