blob: 26a672e808e48a5fcdb949e18d0e40e18bec3114 [file] [log] [blame]
Fred Drake1bd905e2000-10-14 05:06:24 +00001\section{\module{aepack} ---
2 Conversion between Python variables and AppleEvent data containers}
3
4\declaremodule{standard}{aepack}
5 \platform{Mac}
6%\moduleauthor{Jack Jansen?}{email}
7\modulesynopsis{Conversion between Python variables and AppleEvent
8 data containers.}
9\sectionauthor{Vincent Marchetti}{vincem@en.com}
10
11
12The \module{aepack} module defines functions for converting (packing)
13Python variables to AppleEvent descriptors and back (unpacking).
14Within Python the AppleEvent descriptor is handled by Python objects
Fred Drakebb18f622003-08-07 14:31:08 +000015of built-in type \class{AEDesc}, defined in module \refmodule{Carbon.AE}.
Fred Drake1bd905e2000-10-14 05:06:24 +000016
17The \module{aepack} module defines the following functions:
18
19
20\begin{funcdesc}{pack}{x\optional{, forcetype}}
21Returns an \class{AEDesc} object containing a conversion of Python
22value x. If \var{forcetype} is provided it specifies the descriptor
23type of the result. Otherwise, a default mapping of Python types to
24Apple Event descriptor types is used, as follows:
25
26\begin{tableii}{l|l}{textrm}{Python type}{descriptor type}
27 \lineii{\class{FSSpec}}{typeFSS}
Jack Jansen7aeba452003-02-12 09:58:33 +000028 \lineii{\class{FSRef}}{typeFSRef}
Fred Drake1bd905e2000-10-14 05:06:24 +000029 \lineii{\class{Alias}}{typeAlias}
30 \lineii{integer}{typeLong (32 bit integer)}
31 \lineii{float}{typeFloat (64 bit floating point)}
32 \lineii{string}{typeText}
Jack Jansen7aeba452003-02-12 09:58:33 +000033 \lineii{unicode}{typeUnicodeText}
Fred Drake1bd905e2000-10-14 05:06:24 +000034 \lineii{list}{typeAEList}
35 \lineii{dictionary}{typeAERecord}
36 \lineii{instance}{\emph{see below}}
37\end{tableii}
38
Fred Drake1bd905e2000-10-14 05:06:24 +000039If \var{x} is a Python instance then this function attempts to call an
40\method{__aepack__()} method. This method should return an
Fred Drakebb18f622003-08-07 14:31:08 +000041\class{AEDesc} object.
Fred Drake1bd905e2000-10-14 05:06:24 +000042
43If the conversion \var{x} is not defined above, this function returns
44the Python string representation of a value (the repr() function)
45encoded as a text descriptor.
46\end{funcdesc}
47
Jack Jansenbae5c962003-04-11 15:35:28 +000048\begin{funcdesc}{unpack}{x\optional{, formodulename}}
Fred Drake1bd905e2000-10-14 05:06:24 +000049 \var{x} must be an object of type \class{AEDesc}. This function
50 returns a Python object representation of the data in the Apple
51 Event descriptor \var{x}. Simple AppleEvent data types (integer,
52 text, float) are returned as their obvious Python counterparts.
53 Apple Event lists are returned as Python lists, and the list
54 elements are recursively unpacked. Object references
55 (ex. \code{line 3 of document 1}) are returned as instances of
Jack Jansenbae5c962003-04-11 15:35:28 +000056 \class{aetypes.ObjectSpecifier}, unless \code{formodulename}
57 is specified. AppleEvent descriptors with
Fred Drake1bd905e2000-10-14 05:06:24 +000058 descriptor type typeFSS are returned as \class{FSSpec}
59 objects. AppleEvent record descriptors are returned as Python
Jack Jansenbae5c962003-04-11 15:35:28 +000060 dictionaries, with 4-character string keys and elements recursively
Fred Drake1bd905e2000-10-14 05:06:24 +000061 unpacked.
Jack Jansenbae5c962003-04-11 15:35:28 +000062
63 The optional \code{formodulename} argument is used by the stub packages
64 generated by \module{gensuitemodule}, and ensures that the OSA classes
65 for object specifiers are looked up in the correct module. This ensures
66 that if, say, the Finder returns an object specifier for a window
67 you get an instance of \code{Finder.Window} and not a generic
68 \code{aetypes.Window}. The former knows about all the properties
69 and elements a window has in the Finder, while the latter knows
70 no such things.
Fred Drake1bd905e2000-10-14 05:06:24 +000071\end{funcdesc}
72
73
74\begin{seealso}
Jack Jansenbae5c962003-04-11 15:35:28 +000075 \seemodule{Carbon.AE}{Built-in access to Apple Event Manager routines.}
Fred Drake1bd905e2000-10-14 05:06:24 +000076 \seemodule{aetypes}{Python definitions of codes for Apple Event
77 descriptor types.}
78 \seetitle[http://developer.apple.com/techpubs/mac/IAC/IAC-2.html]{
79 Inside Macintosh: Interapplication
80 Communication}{Information about inter-process
81 communications on the Macintosh.}
82\end{seealso}