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