blob: 69753802241cbb5bc98103e88ef93c970401f8fc [file] [log] [blame]
Jack Jansenebed45f1995-08-14 13:40:05 +00001\section{Built-in Module \sectcode{MacOS}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-MacOS}
Jack Jansenebed45f1995-08-14 13:40:05 +00003\bimodindex{MacOS}
4
5\renewcommand{\indexsubitem}{(in module MacOS)}
6
7This module provides access to MacOS specific functionality in the
8python interpreter, such as how the interpreter eventloop functions
9and the like. Use with care.
10
11Note the capitalisation of the module name, this is a historical
12artefact.
13
14\begin{excdesc}{Error}
15This exception is raised on MacOS generated errors, either from
16functions in this module or from other mac-specific modules like the
17toolbox interfaces. The arguments are the integer error code (the
18\var{OSErr} value) and a textual description of the error code.
Guido van Rossum7e42cab1996-10-15 14:37:31 +000019Symbolic names for all known error codes are defined in the standard
20module \var{macerrors}.
Jack Jansenebed45f1995-08-14 13:40:05 +000021\end{excdesc}
22
23\begin{funcdesc}{SetHighLevelEventHandler}{handler}
24Pass a python function that will be called upon reception of a
25high-level event. The previous handler is returned. The handler
26function is called with the event as argument.
27
28Note that your event handler is currently only called dependably if
29your main event loop is in \var{stdwin}.
30\end{funcdesc}
31
32\begin{funcdesc}{AcceptHighLevelEvent}{}
33Read a high-level event. The return value is a tuple \code{(sender,
34refcon, data)}.
35\end{funcdesc}
36
37\begin{funcdesc}{SetScheduleTimes}{fgi\, fgy \optional{\, bgi\, bgy}}
38Controls how often the interpreter checks the event queue and how
39long it will yield the processor to other processes. \var{fgi}
40specifies after how many clicks (one click is one 60th of a second)
41the interpreter should check the event queue, and \var{fgy} specifies
42for how many clicks the CPU should be yielded when in the
43foreground. The optional \var{bgi} and \var{bgy} allow you to specify
44different values to use when python runs in the background, otherwise
45the background values will be set the the same as the foreground
46values. The function returns nothing.
47
Guido van Rossum7e42cab1996-10-15 14:37:31 +000048The default values, which are based on minimal empirical testing, are 12, 1, 6
49and 2 respectively.
Jack Jansenebed45f1995-08-14 13:40:05 +000050\end{funcdesc}
51
52\begin{funcdesc}{EnableAppswitch}{onoff}
53Enable or disable the python event loop, based on the value of
54\var{onoff}. The old value is returned. If the event loop is disabled
55no time is granted to other applications, checking for command-period
56is not performed and it is impossible to switch applications. This
57should only be used by programs providing their own complete event
58loop.
59
60Note that based on the compiler used to build python it is still
61possible to loose events even with the python event loop disabled. If
62you have a \code{sys.stdout} window its handler will often also look
63in the event queue. Making sure nothing is ever printed works around
64this.
65\end{funcdesc}
66
67\begin{funcdesc}{HandleEvent}{ev}
68Pass the event record \code{ev} back to the python event loop, or
69possibly to the handler for the \code{sys.stdout} window (based on the
70compiler used to build python). This allows python programs that do
71their own event handling to still have some command-period and
72window-switching capability.
73\end{funcdesc}
74
75\begin{funcdesc}{GetErrorString}{errno}
76Return the textual description of MacOS error code \var{errno}.
77\end{funcdesc}
Guido van Rossum66774a91996-07-21 02:20:58 +000078
79\begin{funcdesc}{splash}{resid}
80This function will put a splash window
81on-screen, with the contents of the DLOG resource specified by
82\code{resid}. Calling with a zero argument will remove the splash
Guido van Rossum7e42cab1996-10-15 14:37:31 +000083screen. This function is useful if you want an applet to post a splash screen
Guido van Rossum66774a91996-07-21 02:20:58 +000084early in initialization without first having to load numerous
85extension modules.
86\end{funcdesc}
87
Guido van Rossum7e42cab1996-10-15 14:37:31 +000088\begin{funcdesc}{DebugStr}{message \optional{\, object}}
89Drop to the low-level debugger with message \var{message}. The
90optional \var{object} argument is not used, but can easily be
91inspected from the debugger.
92
93Note that you should use this function with extreme care: if no
94low-level debugger like MacsBug is installed this call will crash your
95system. It is intended mainly for developers of Python extension
96modules.
97\end{funcdesc}
98
Guido van Rossum66774a91996-07-21 02:20:58 +000099\begin{funcdesc}{openrf}{name \optional{\, mode}}
100Open the resource fork of a file. Arguments are the same as for the
101builtin function \code{open}. The object returned has file-like
102semantics, but it is not a python file object, so there may be subtle
103differences.
104\end{funcdesc}