Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module AE ============================ */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 8 | #include "macglue.h" |
Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 9 | #include "pymactoolbox.h" |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 10 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 11 | #include <AppleEvents.h> |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 12 | #include <AEObjects.h> |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 13 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 14 | static pascal OSErr GenericEventHandler(); /* Forward */ |
| 15 | |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 16 | AEEventHandlerUPP upp_GenericEventHandler; |
| 17 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 18 | static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn) |
| 19 | { |
Jack Jansen | 3757523 | 1997-06-20 16:19:14 +0000 | [diff] [blame] | 20 | if ( PyOS_InterruptOccurred() ) |
| 21 | return 1; |
| 22 | if ( PyMac_HandleEvent(theEvent) < 0 ) { |
Jack Jansen | deff89c | 1998-10-12 20:53:15 +0000 | [diff] [blame] | 23 | PySys_WriteStderr("Exception in user event handler during AE processing\n"); |
Jack Jansen | 3757523 | 1997-06-20 16:19:14 +0000 | [diff] [blame] | 24 | PyErr_Clear(); |
| 25 | } |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 26 | return 0; |
| 27 | } |
| 28 | |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 29 | AEIdleUPP upp_AEIdleProc; |
| 30 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 31 | static PyObject *AE_Error; |
| 32 | |
| 33 | /* ----------------------- Object type AEDesc ----------------------- */ |
| 34 | |
Jack Jansen | f69633e | 1997-08-15 14:31:13 +0000 | [diff] [blame] | 35 | PyTypeObject AEDesc_Type; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 36 | |
| 37 | #define AEDesc_Check(x) ((x)->ob_type == &AEDesc_Type) |
| 38 | |
| 39 | typedef struct AEDescObject { |
| 40 | PyObject_HEAD |
| 41 | AEDesc ob_itself; |
| 42 | } AEDescObject; |
| 43 | |
Jack Jansen | f69633e | 1997-08-15 14:31:13 +0000 | [diff] [blame] | 44 | PyObject *AEDesc_New(itself) |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 45 | AEDesc *itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 46 | { |
| 47 | AEDescObject *it; |
| 48 | it = PyObject_NEW(AEDescObject, &AEDesc_Type); |
| 49 | if (it == NULL) return NULL; |
| 50 | it->ob_itself = *itself; |
| 51 | return (PyObject *)it; |
| 52 | } |
Jack Jansen | f69633e | 1997-08-15 14:31:13 +0000 | [diff] [blame] | 53 | AEDesc_Convert(v, p_itself) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 54 | PyObject *v; |
| 55 | AEDesc *p_itself; |
| 56 | { |
| 57 | if (!AEDesc_Check(v)) |
| 58 | { |
| 59 | PyErr_SetString(PyExc_TypeError, "AEDesc required"); |
| 60 | return 0; |
| 61 | } |
| 62 | *p_itself = ((AEDescObject *)v)->ob_itself; |
| 63 | return 1; |
| 64 | } |
| 65 | |
| 66 | static void AEDesc_dealloc(self) |
| 67 | AEDescObject *self; |
| 68 | { |
| 69 | AEDisposeDesc(&self->ob_itself); |
| 70 | PyMem_DEL(self); |
| 71 | } |
| 72 | |
| 73 | static PyObject *AEDesc_AECoerceDesc(_self, _args) |
| 74 | AEDescObject *_self; |
| 75 | PyObject *_args; |
| 76 | { |
| 77 | PyObject *_res = NULL; |
| 78 | OSErr _err; |
| 79 | DescType toType; |
| 80 | AEDesc result; |
| 81 | if (!PyArg_ParseTuple(_args, "O&", |
| 82 | PyMac_GetOSType, &toType)) |
| 83 | return NULL; |
| 84 | _err = AECoerceDesc(&_self->ob_itself, |
| 85 | toType, |
| 86 | &result); |
| 87 | if (_err != noErr) return PyMac_Error(_err); |
| 88 | _res = Py_BuildValue("O&", |
| 89 | AEDesc_New, &result); |
| 90 | return _res; |
| 91 | } |
| 92 | |
| 93 | static PyObject *AEDesc_AEDuplicateDesc(_self, _args) |
| 94 | AEDescObject *_self; |
| 95 | PyObject *_args; |
| 96 | { |
| 97 | PyObject *_res = NULL; |
| 98 | OSErr _err; |
| 99 | AEDesc result; |
| 100 | if (!PyArg_ParseTuple(_args, "")) |
| 101 | return NULL; |
| 102 | _err = AEDuplicateDesc(&_self->ob_itself, |
| 103 | &result); |
| 104 | if (_err != noErr) return PyMac_Error(_err); |
| 105 | _res = Py_BuildValue("O&", |
| 106 | AEDesc_New, &result); |
| 107 | return _res; |
| 108 | } |
| 109 | |
| 110 | static PyObject *AEDesc_AECountItems(_self, _args) |
| 111 | AEDescObject *_self; |
| 112 | PyObject *_args; |
| 113 | { |
| 114 | PyObject *_res = NULL; |
| 115 | OSErr _err; |
| 116 | long theCount; |
| 117 | if (!PyArg_ParseTuple(_args, "")) |
| 118 | return NULL; |
| 119 | _err = AECountItems(&_self->ob_itself, |
| 120 | &theCount); |
| 121 | if (_err != noErr) return PyMac_Error(_err); |
| 122 | _res = Py_BuildValue("l", |
| 123 | theCount); |
| 124 | return _res; |
| 125 | } |
| 126 | |
Jack Jansen | 5ae5fdf | 1995-07-17 11:40:10 +0000 | [diff] [blame] | 127 | static PyObject *AEDesc_AEPutPtr(_self, _args) |
| 128 | AEDescObject *_self; |
| 129 | PyObject *_args; |
| 130 | { |
| 131 | PyObject *_res = NULL; |
| 132 | OSErr _err; |
| 133 | long index; |
| 134 | DescType typeCode; |
| 135 | char *dataPtr__in__; |
| 136 | long dataPtr__len__; |
| 137 | int dataPtr__in_len__; |
| 138 | if (!PyArg_ParseTuple(_args, "lO&s#", |
| 139 | &index, |
| 140 | PyMac_GetOSType, &typeCode, |
| 141 | &dataPtr__in__, &dataPtr__in_len__)) |
| 142 | return NULL; |
| 143 | dataPtr__len__ = dataPtr__in_len__; |
| 144 | _err = AEPutPtr(&_self->ob_itself, |
| 145 | index, |
| 146 | typeCode, |
| 147 | dataPtr__in__, dataPtr__len__); |
| 148 | if (_err != noErr) return PyMac_Error(_err); |
| 149 | Py_INCREF(Py_None); |
| 150 | _res = Py_None; |
| 151 | dataPtr__error__: ; |
| 152 | return _res; |
| 153 | } |
| 154 | |
| 155 | static PyObject *AEDesc_AEPutDesc(_self, _args) |
| 156 | AEDescObject *_self; |
| 157 | PyObject *_args; |
| 158 | { |
| 159 | PyObject *_res = NULL; |
| 160 | OSErr _err; |
| 161 | long index; |
| 162 | AEDesc theAEDesc; |
| 163 | if (!PyArg_ParseTuple(_args, "lO&", |
| 164 | &index, |
| 165 | AEDesc_Convert, &theAEDesc)) |
| 166 | return NULL; |
| 167 | _err = AEPutDesc(&_self->ob_itself, |
| 168 | index, |
| 169 | &theAEDesc); |
| 170 | if (_err != noErr) return PyMac_Error(_err); |
| 171 | Py_INCREF(Py_None); |
| 172 | _res = Py_None; |
| 173 | return _res; |
| 174 | } |
| 175 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 176 | static PyObject *AEDesc_AEGetNthPtr(_self, _args) |
| 177 | AEDescObject *_self; |
| 178 | PyObject *_args; |
| 179 | { |
| 180 | PyObject *_res = NULL; |
| 181 | OSErr _err; |
| 182 | long index; |
| 183 | DescType desiredType; |
| 184 | AEKeyword theAEKeyword; |
| 185 | DescType typeCode; |
| 186 | char *dataPtr__out__; |
| 187 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 188 | int dataPtr__in_len__; |
| 189 | if (!PyArg_ParseTuple(_args, "lO&i", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 190 | &index, |
| 191 | PyMac_GetOSType, &desiredType, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 192 | &dataPtr__in_len__)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 193 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 194 | if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 195 | { |
| 196 | PyErr_NoMemory(); |
| 197 | goto dataPtr__error__; |
| 198 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 199 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 200 | _err = AEGetNthPtr(&_self->ob_itself, |
| 201 | index, |
| 202 | desiredType, |
| 203 | &theAEKeyword, |
| 204 | &typeCode, |
| 205 | dataPtr__out__, dataPtr__len__, &dataPtr__len__); |
| 206 | if (_err != noErr) return PyMac_Error(_err); |
| 207 | _res = Py_BuildValue("O&O&s#", |
| 208 | PyMac_BuildOSType, theAEKeyword, |
| 209 | PyMac_BuildOSType, typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 210 | dataPtr__out__, (int)dataPtr__len__); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 211 | free(dataPtr__out__); |
| 212 | dataPtr__error__: ; |
| 213 | return _res; |
| 214 | } |
| 215 | |
| 216 | static PyObject *AEDesc_AEGetNthDesc(_self, _args) |
| 217 | AEDescObject *_self; |
| 218 | PyObject *_args; |
| 219 | { |
| 220 | PyObject *_res = NULL; |
| 221 | OSErr _err; |
| 222 | long index; |
| 223 | DescType desiredType; |
| 224 | AEKeyword theAEKeyword; |
| 225 | AEDesc result; |
| 226 | if (!PyArg_ParseTuple(_args, "lO&", |
| 227 | &index, |
| 228 | PyMac_GetOSType, &desiredType)) |
| 229 | return NULL; |
| 230 | _err = AEGetNthDesc(&_self->ob_itself, |
| 231 | index, |
| 232 | desiredType, |
| 233 | &theAEKeyword, |
| 234 | &result); |
| 235 | if (_err != noErr) return PyMac_Error(_err); |
| 236 | _res = Py_BuildValue("O&O&", |
| 237 | PyMac_BuildOSType, theAEKeyword, |
| 238 | AEDesc_New, &result); |
| 239 | return _res; |
| 240 | } |
| 241 | |
| 242 | static PyObject *AEDesc_AESizeOfNthItem(_self, _args) |
| 243 | AEDescObject *_self; |
| 244 | PyObject *_args; |
| 245 | { |
| 246 | PyObject *_res = NULL; |
| 247 | OSErr _err; |
| 248 | long index; |
| 249 | DescType typeCode; |
| 250 | Size dataSize; |
| 251 | if (!PyArg_ParseTuple(_args, "l", |
| 252 | &index)) |
| 253 | return NULL; |
| 254 | _err = AESizeOfNthItem(&_self->ob_itself, |
| 255 | index, |
| 256 | &typeCode, |
| 257 | &dataSize); |
| 258 | if (_err != noErr) return PyMac_Error(_err); |
| 259 | _res = Py_BuildValue("O&l", |
| 260 | PyMac_BuildOSType, typeCode, |
| 261 | dataSize); |
| 262 | return _res; |
| 263 | } |
| 264 | |
Jack Jansen | 5ae5fdf | 1995-07-17 11:40:10 +0000 | [diff] [blame] | 265 | static PyObject *AEDesc_AEDeleteItem(_self, _args) |
| 266 | AEDescObject *_self; |
| 267 | PyObject *_args; |
| 268 | { |
| 269 | PyObject *_res = NULL; |
| 270 | OSErr _err; |
| 271 | long index; |
| 272 | if (!PyArg_ParseTuple(_args, "l", |
| 273 | &index)) |
| 274 | return NULL; |
| 275 | _err = AEDeleteItem(&_self->ob_itself, |
| 276 | index); |
| 277 | if (_err != noErr) return PyMac_Error(_err); |
| 278 | Py_INCREF(Py_None); |
| 279 | _res = Py_None; |
| 280 | return _res; |
| 281 | } |
| 282 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 283 | static PyObject *AEDesc_AEPutParamPtr(_self, _args) |
| 284 | AEDescObject *_self; |
| 285 | PyObject *_args; |
| 286 | { |
| 287 | PyObject *_res = NULL; |
| 288 | OSErr _err; |
| 289 | AEKeyword theAEKeyword; |
| 290 | DescType typeCode; |
| 291 | char *dataPtr__in__; |
| 292 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 293 | int dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 294 | if (!PyArg_ParseTuple(_args, "O&O&s#", |
| 295 | PyMac_GetOSType, &theAEKeyword, |
| 296 | PyMac_GetOSType, &typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 297 | &dataPtr__in__, &dataPtr__in_len__)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 298 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 299 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 300 | _err = AEPutParamPtr(&_self->ob_itself, |
| 301 | theAEKeyword, |
| 302 | typeCode, |
| 303 | dataPtr__in__, dataPtr__len__); |
| 304 | if (_err != noErr) return PyMac_Error(_err); |
| 305 | Py_INCREF(Py_None); |
| 306 | _res = Py_None; |
| 307 | dataPtr__error__: ; |
| 308 | return _res; |
| 309 | } |
| 310 | |
| 311 | static PyObject *AEDesc_AEPutParamDesc(_self, _args) |
| 312 | AEDescObject *_self; |
| 313 | PyObject *_args; |
| 314 | { |
| 315 | PyObject *_res = NULL; |
| 316 | OSErr _err; |
| 317 | AEKeyword theAEKeyword; |
| 318 | AEDesc theAEDesc; |
| 319 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 320 | PyMac_GetOSType, &theAEKeyword, |
| 321 | AEDesc_Convert, &theAEDesc)) |
| 322 | return NULL; |
| 323 | _err = AEPutParamDesc(&_self->ob_itself, |
| 324 | theAEKeyword, |
| 325 | &theAEDesc); |
| 326 | if (_err != noErr) return PyMac_Error(_err); |
| 327 | Py_INCREF(Py_None); |
| 328 | _res = Py_None; |
| 329 | return _res; |
| 330 | } |
| 331 | |
| 332 | static PyObject *AEDesc_AEGetParamPtr(_self, _args) |
| 333 | AEDescObject *_self; |
| 334 | PyObject *_args; |
| 335 | { |
| 336 | PyObject *_res = NULL; |
| 337 | OSErr _err; |
| 338 | AEKeyword theAEKeyword; |
| 339 | DescType desiredType; |
| 340 | DescType typeCode; |
| 341 | char *dataPtr__out__; |
| 342 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 343 | int dataPtr__in_len__; |
| 344 | if (!PyArg_ParseTuple(_args, "O&O&i", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 345 | PyMac_GetOSType, &theAEKeyword, |
| 346 | PyMac_GetOSType, &desiredType, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 347 | &dataPtr__in_len__)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 348 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 349 | if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 350 | { |
| 351 | PyErr_NoMemory(); |
| 352 | goto dataPtr__error__; |
| 353 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 354 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 355 | _err = AEGetParamPtr(&_self->ob_itself, |
| 356 | theAEKeyword, |
| 357 | desiredType, |
| 358 | &typeCode, |
| 359 | dataPtr__out__, dataPtr__len__, &dataPtr__len__); |
| 360 | if (_err != noErr) return PyMac_Error(_err); |
| 361 | _res = Py_BuildValue("O&s#", |
| 362 | PyMac_BuildOSType, typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 363 | dataPtr__out__, (int)dataPtr__len__); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 364 | free(dataPtr__out__); |
| 365 | dataPtr__error__: ; |
| 366 | return _res; |
| 367 | } |
| 368 | |
| 369 | static PyObject *AEDesc_AEGetParamDesc(_self, _args) |
| 370 | AEDescObject *_self; |
| 371 | PyObject *_args; |
| 372 | { |
| 373 | PyObject *_res = NULL; |
| 374 | OSErr _err; |
| 375 | AEKeyword theAEKeyword; |
| 376 | DescType desiredType; |
| 377 | AEDesc result; |
| 378 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 379 | PyMac_GetOSType, &theAEKeyword, |
| 380 | PyMac_GetOSType, &desiredType)) |
| 381 | return NULL; |
| 382 | _err = AEGetParamDesc(&_self->ob_itself, |
| 383 | theAEKeyword, |
| 384 | desiredType, |
| 385 | &result); |
| 386 | if (_err != noErr) return PyMac_Error(_err); |
| 387 | _res = Py_BuildValue("O&", |
| 388 | AEDesc_New, &result); |
| 389 | return _res; |
| 390 | } |
| 391 | |
| 392 | static PyObject *AEDesc_AESizeOfParam(_self, _args) |
| 393 | AEDescObject *_self; |
| 394 | PyObject *_args; |
| 395 | { |
| 396 | PyObject *_res = NULL; |
| 397 | OSErr _err; |
| 398 | AEKeyword theAEKeyword; |
| 399 | DescType typeCode; |
| 400 | Size dataSize; |
| 401 | if (!PyArg_ParseTuple(_args, "O&", |
| 402 | PyMac_GetOSType, &theAEKeyword)) |
| 403 | return NULL; |
| 404 | _err = AESizeOfParam(&_self->ob_itself, |
| 405 | theAEKeyword, |
| 406 | &typeCode, |
| 407 | &dataSize); |
| 408 | if (_err != noErr) return PyMac_Error(_err); |
| 409 | _res = Py_BuildValue("O&l", |
| 410 | PyMac_BuildOSType, typeCode, |
| 411 | dataSize); |
| 412 | return _res; |
| 413 | } |
| 414 | |
| 415 | static PyObject *AEDesc_AEDeleteParam(_self, _args) |
| 416 | AEDescObject *_self; |
| 417 | PyObject *_args; |
| 418 | { |
| 419 | PyObject *_res = NULL; |
| 420 | OSErr _err; |
| 421 | AEKeyword theAEKeyword; |
| 422 | if (!PyArg_ParseTuple(_args, "O&", |
| 423 | PyMac_GetOSType, &theAEKeyword)) |
| 424 | return NULL; |
| 425 | _err = AEDeleteParam(&_self->ob_itself, |
| 426 | theAEKeyword); |
| 427 | if (_err != noErr) return PyMac_Error(_err); |
| 428 | Py_INCREF(Py_None); |
| 429 | _res = Py_None; |
| 430 | return _res; |
| 431 | } |
| 432 | |
| 433 | static PyObject *AEDesc_AEGetAttributePtr(_self, _args) |
| 434 | AEDescObject *_self; |
| 435 | PyObject *_args; |
| 436 | { |
| 437 | PyObject *_res = NULL; |
| 438 | OSErr _err; |
| 439 | AEKeyword theAEKeyword; |
| 440 | DescType desiredType; |
| 441 | DescType typeCode; |
| 442 | char *dataPtr__out__; |
| 443 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 444 | int dataPtr__in_len__; |
| 445 | if (!PyArg_ParseTuple(_args, "O&O&i", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 446 | PyMac_GetOSType, &theAEKeyword, |
| 447 | PyMac_GetOSType, &desiredType, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 448 | &dataPtr__in_len__)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 449 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 450 | if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 451 | { |
| 452 | PyErr_NoMemory(); |
| 453 | goto dataPtr__error__; |
| 454 | } |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 455 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 456 | _err = AEGetAttributePtr(&_self->ob_itself, |
| 457 | theAEKeyword, |
| 458 | desiredType, |
| 459 | &typeCode, |
| 460 | dataPtr__out__, dataPtr__len__, &dataPtr__len__); |
| 461 | if (_err != noErr) return PyMac_Error(_err); |
| 462 | _res = Py_BuildValue("O&s#", |
| 463 | PyMac_BuildOSType, typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 464 | dataPtr__out__, (int)dataPtr__len__); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 465 | free(dataPtr__out__); |
| 466 | dataPtr__error__: ; |
| 467 | return _res; |
| 468 | } |
| 469 | |
| 470 | static PyObject *AEDesc_AEGetAttributeDesc(_self, _args) |
| 471 | AEDescObject *_self; |
| 472 | PyObject *_args; |
| 473 | { |
| 474 | PyObject *_res = NULL; |
| 475 | OSErr _err; |
| 476 | AEKeyword theAEKeyword; |
| 477 | DescType desiredType; |
| 478 | AEDesc result; |
| 479 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 480 | PyMac_GetOSType, &theAEKeyword, |
| 481 | PyMac_GetOSType, &desiredType)) |
| 482 | return NULL; |
| 483 | _err = AEGetAttributeDesc(&_self->ob_itself, |
| 484 | theAEKeyword, |
| 485 | desiredType, |
| 486 | &result); |
| 487 | if (_err != noErr) return PyMac_Error(_err); |
| 488 | _res = Py_BuildValue("O&", |
| 489 | AEDesc_New, &result); |
| 490 | return _res; |
| 491 | } |
| 492 | |
| 493 | static PyObject *AEDesc_AESizeOfAttribute(_self, _args) |
| 494 | AEDescObject *_self; |
| 495 | PyObject *_args; |
| 496 | { |
| 497 | PyObject *_res = NULL; |
| 498 | OSErr _err; |
| 499 | AEKeyword theAEKeyword; |
| 500 | DescType typeCode; |
| 501 | Size dataSize; |
| 502 | if (!PyArg_ParseTuple(_args, "O&", |
| 503 | PyMac_GetOSType, &theAEKeyword)) |
| 504 | return NULL; |
| 505 | _err = AESizeOfAttribute(&_self->ob_itself, |
| 506 | theAEKeyword, |
| 507 | &typeCode, |
| 508 | &dataSize); |
| 509 | if (_err != noErr) return PyMac_Error(_err); |
| 510 | _res = Py_BuildValue("O&l", |
| 511 | PyMac_BuildOSType, typeCode, |
| 512 | dataSize); |
| 513 | return _res; |
| 514 | } |
| 515 | |
| 516 | static PyObject *AEDesc_AEPutAttributePtr(_self, _args) |
| 517 | AEDescObject *_self; |
| 518 | PyObject *_args; |
| 519 | { |
| 520 | PyObject *_res = NULL; |
| 521 | OSErr _err; |
| 522 | AEKeyword theAEKeyword; |
| 523 | DescType typeCode; |
| 524 | char *dataPtr__in__; |
| 525 | long dataPtr__len__; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 526 | int dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 527 | if (!PyArg_ParseTuple(_args, "O&O&s#", |
| 528 | PyMac_GetOSType, &theAEKeyword, |
| 529 | PyMac_GetOSType, &typeCode, |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 530 | &dataPtr__in__, &dataPtr__in_len__)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 531 | return NULL; |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 532 | dataPtr__len__ = dataPtr__in_len__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 533 | _err = AEPutAttributePtr(&_self->ob_itself, |
| 534 | theAEKeyword, |
| 535 | typeCode, |
| 536 | dataPtr__in__, dataPtr__len__); |
| 537 | if (_err != noErr) return PyMac_Error(_err); |
| 538 | Py_INCREF(Py_None); |
| 539 | _res = Py_None; |
| 540 | dataPtr__error__: ; |
| 541 | return _res; |
| 542 | } |
| 543 | |
| 544 | static PyObject *AEDesc_AEPutAttributeDesc(_self, _args) |
| 545 | AEDescObject *_self; |
| 546 | PyObject *_args; |
| 547 | { |
| 548 | PyObject *_res = NULL; |
| 549 | OSErr _err; |
| 550 | AEKeyword theAEKeyword; |
| 551 | AEDesc theAEDesc; |
| 552 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 553 | PyMac_GetOSType, &theAEKeyword, |
| 554 | AEDesc_Convert, &theAEDesc)) |
| 555 | return NULL; |
| 556 | _err = AEPutAttributeDesc(&_self->ob_itself, |
| 557 | theAEKeyword, |
| 558 | &theAEDesc); |
| 559 | if (_err != noErr) return PyMac_Error(_err); |
| 560 | Py_INCREF(Py_None); |
| 561 | _res = Py_None; |
| 562 | return _res; |
| 563 | } |
| 564 | |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 565 | #if TARGET_API_MAC_CARBON |
| 566 | |
| 567 | static PyObject *AEDesc_AEGetDescDataSize(_self, _args) |
| 568 | AEDescObject *_self; |
| 569 | PyObject *_args; |
| 570 | { |
| 571 | PyObject *_res = NULL; |
| 572 | Size _rv; |
| 573 | if (!PyArg_ParseTuple(_args, "")) |
| 574 | return NULL; |
| 575 | _rv = AEGetDescDataSize(&_self->ob_itself); |
| 576 | _res = Py_BuildValue("l", |
| 577 | _rv); |
| 578 | return _res; |
| 579 | } |
| 580 | #endif |
| 581 | |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 582 | static PyObject *AEDesc_AESend(_self, _args) |
| 583 | AEDescObject *_self; |
| 584 | PyObject *_args; |
| 585 | { |
| 586 | PyObject *_res = NULL; |
| 587 | OSErr _err; |
| 588 | AppleEvent reply; |
| 589 | AESendMode sendMode; |
| 590 | AESendPriority sendPriority; |
| 591 | long timeOutInTicks; |
| 592 | if (!PyArg_ParseTuple(_args, "lhl", |
| 593 | &sendMode, |
| 594 | &sendPriority, |
| 595 | &timeOutInTicks)) |
| 596 | return NULL; |
| 597 | _err = AESend(&_self->ob_itself, |
| 598 | &reply, |
| 599 | sendMode, |
| 600 | sendPriority, |
| 601 | timeOutInTicks, |
| 602 | upp_AEIdleProc, |
| 603 | (AEFilterUPP)0); |
| 604 | if (_err != noErr) return PyMac_Error(_err); |
| 605 | _res = Py_BuildValue("O&", |
| 606 | AEDesc_New, &reply); |
| 607 | return _res; |
| 608 | } |
| 609 | |
| 610 | static PyObject *AEDesc_AEResetTimer(_self, _args) |
| 611 | AEDescObject *_self; |
| 612 | PyObject *_args; |
| 613 | { |
| 614 | PyObject *_res = NULL; |
| 615 | OSErr _err; |
| 616 | if (!PyArg_ParseTuple(_args, "")) |
| 617 | return NULL; |
| 618 | _err = AEResetTimer(&_self->ob_itself); |
| 619 | if (_err != noErr) return PyMac_Error(_err); |
| 620 | Py_INCREF(Py_None); |
| 621 | _res = Py_None; |
| 622 | return _res; |
| 623 | } |
| 624 | |
| 625 | static PyObject *AEDesc_AESuspendTheCurrentEvent(_self, _args) |
| 626 | AEDescObject *_self; |
| 627 | PyObject *_args; |
| 628 | { |
| 629 | PyObject *_res = NULL; |
| 630 | OSErr _err; |
| 631 | if (!PyArg_ParseTuple(_args, "")) |
| 632 | return NULL; |
| 633 | _err = AESuspendTheCurrentEvent(&_self->ob_itself); |
| 634 | if (_err != noErr) return PyMac_Error(_err); |
| 635 | Py_INCREF(Py_None); |
| 636 | _res = Py_None; |
| 637 | return _res; |
| 638 | } |
| 639 | |
| 640 | static PyObject *AEDesc_AEResumeTheCurrentEvent(_self, _args) |
| 641 | AEDescObject *_self; |
| 642 | PyObject *_args; |
| 643 | { |
| 644 | PyObject *_res = NULL; |
| 645 | OSErr _err; |
| 646 | AppleEvent reply; |
| 647 | AEEventHandlerUPP dispatcher__proc__ = upp_GenericEventHandler; |
| 648 | PyObject *dispatcher; |
| 649 | if (!PyArg_ParseTuple(_args, "O&O", |
| 650 | AEDesc_Convert, &reply, |
| 651 | &dispatcher)) |
| 652 | return NULL; |
| 653 | _err = AEResumeTheCurrentEvent(&_self->ob_itself, |
| 654 | &reply, |
| 655 | dispatcher__proc__, (long)dispatcher); |
| 656 | if (_err != noErr) return PyMac_Error(_err); |
| 657 | Py_INCREF(Py_None); |
| 658 | _res = Py_None; |
| 659 | Py_INCREF(dispatcher); /* XXX leak, but needed */ |
| 660 | return _res; |
| 661 | } |
| 662 | |
| 663 | static PyObject *AEDesc_AEGetTheCurrentEvent(_self, _args) |
| 664 | AEDescObject *_self; |
| 665 | PyObject *_args; |
| 666 | { |
| 667 | PyObject *_res = NULL; |
| 668 | OSErr _err; |
| 669 | if (!PyArg_ParseTuple(_args, "")) |
| 670 | return NULL; |
| 671 | _err = AEGetTheCurrentEvent(&_self->ob_itself); |
| 672 | if (_err != noErr) return PyMac_Error(_err); |
| 673 | Py_INCREF(Py_None); |
| 674 | _res = Py_None; |
| 675 | return _res; |
| 676 | } |
| 677 | |
| 678 | static PyObject *AEDesc_AESetTheCurrentEvent(_self, _args) |
| 679 | AEDescObject *_self; |
| 680 | PyObject *_args; |
| 681 | { |
| 682 | PyObject *_res = NULL; |
| 683 | OSErr _err; |
| 684 | if (!PyArg_ParseTuple(_args, "")) |
| 685 | return NULL; |
| 686 | _err = AESetTheCurrentEvent(&_self->ob_itself); |
| 687 | if (_err != noErr) return PyMac_Error(_err); |
| 688 | Py_INCREF(Py_None); |
| 689 | _res = Py_None; |
| 690 | return _res; |
| 691 | } |
| 692 | |
| 693 | static PyObject *AEDesc_AEResolve(_self, _args) |
| 694 | AEDescObject *_self; |
| 695 | PyObject *_args; |
| 696 | { |
| 697 | PyObject *_res = NULL; |
| 698 | OSErr _err; |
| 699 | short callbackFlags; |
| 700 | AEDesc theToken; |
| 701 | if (!PyArg_ParseTuple(_args, "h", |
| 702 | &callbackFlags)) |
| 703 | return NULL; |
| 704 | _err = AEResolve(&_self->ob_itself, |
| 705 | callbackFlags, |
| 706 | &theToken); |
| 707 | if (_err != noErr) return PyMac_Error(_err); |
| 708 | _res = Py_BuildValue("O&", |
| 709 | AEDesc_New, &theToken); |
| 710 | return _res; |
| 711 | } |
| 712 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 713 | static PyMethodDef AEDesc_methods[] = { |
| 714 | {"AECoerceDesc", (PyCFunction)AEDesc_AECoerceDesc, 1, |
| 715 | "(DescType toType) -> (AEDesc result)"}, |
| 716 | {"AEDuplicateDesc", (PyCFunction)AEDesc_AEDuplicateDesc, 1, |
| 717 | "() -> (AEDesc result)"}, |
| 718 | {"AECountItems", (PyCFunction)AEDesc_AECountItems, 1, |
| 719 | "() -> (long theCount)"}, |
Jack Jansen | 5ae5fdf | 1995-07-17 11:40:10 +0000 | [diff] [blame] | 720 | {"AEPutPtr", (PyCFunction)AEDesc_AEPutPtr, 1, |
| 721 | "(long index, DescType typeCode, Buffer dataPtr) -> None"}, |
| 722 | {"AEPutDesc", (PyCFunction)AEDesc_AEPutDesc, 1, |
| 723 | "(long index, AEDesc theAEDesc) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 724 | {"AEGetNthPtr", (PyCFunction)AEDesc_AEGetNthPtr, 1, |
| 725 | "(long index, DescType desiredType, Buffer dataPtr) -> (AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr)"}, |
| 726 | {"AEGetNthDesc", (PyCFunction)AEDesc_AEGetNthDesc, 1, |
| 727 | "(long index, DescType desiredType) -> (AEKeyword theAEKeyword, AEDesc result)"}, |
| 728 | {"AESizeOfNthItem", (PyCFunction)AEDesc_AESizeOfNthItem, 1, |
| 729 | "(long index) -> (DescType typeCode, Size dataSize)"}, |
Jack Jansen | 5ae5fdf | 1995-07-17 11:40:10 +0000 | [diff] [blame] | 730 | {"AEDeleteItem", (PyCFunction)AEDesc_AEDeleteItem, 1, |
| 731 | "(long index) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 732 | {"AEPutParamPtr", (PyCFunction)AEDesc_AEPutParamPtr, 1, |
| 733 | "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"}, |
| 734 | {"AEPutParamDesc", (PyCFunction)AEDesc_AEPutParamDesc, 1, |
| 735 | "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"}, |
| 736 | {"AEGetParamPtr", (PyCFunction)AEDesc_AEGetParamPtr, 1, |
| 737 | "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"}, |
| 738 | {"AEGetParamDesc", (PyCFunction)AEDesc_AEGetParamDesc, 1, |
| 739 | "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"}, |
| 740 | {"AESizeOfParam", (PyCFunction)AEDesc_AESizeOfParam, 1, |
| 741 | "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"}, |
| 742 | {"AEDeleteParam", (PyCFunction)AEDesc_AEDeleteParam, 1, |
| 743 | "(AEKeyword theAEKeyword) -> None"}, |
| 744 | {"AEGetAttributePtr", (PyCFunction)AEDesc_AEGetAttributePtr, 1, |
| 745 | "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"}, |
| 746 | {"AEGetAttributeDesc", (PyCFunction)AEDesc_AEGetAttributeDesc, 1, |
| 747 | "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"}, |
| 748 | {"AESizeOfAttribute", (PyCFunction)AEDesc_AESizeOfAttribute, 1, |
| 749 | "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"}, |
| 750 | {"AEPutAttributePtr", (PyCFunction)AEDesc_AEPutAttributePtr, 1, |
| 751 | "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"}, |
| 752 | {"AEPutAttributeDesc", (PyCFunction)AEDesc_AEPutAttributeDesc, 1, |
| 753 | "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"}, |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 754 | |
| 755 | #if TARGET_API_MAC_CARBON |
| 756 | {"AEGetDescDataSize", (PyCFunction)AEDesc_AEGetDescDataSize, 1, |
| 757 | "() -> (Size _rv)"}, |
| 758 | #endif |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 759 | {"AESend", (PyCFunction)AEDesc_AESend, 1, |
| 760 | "(AESendMode sendMode, AESendPriority sendPriority, long timeOutInTicks) -> (AppleEvent reply)"}, |
| 761 | {"AEResetTimer", (PyCFunction)AEDesc_AEResetTimer, 1, |
| 762 | "() -> None"}, |
| 763 | {"AESuspendTheCurrentEvent", (PyCFunction)AEDesc_AESuspendTheCurrentEvent, 1, |
| 764 | "() -> None"}, |
| 765 | {"AEResumeTheCurrentEvent", (PyCFunction)AEDesc_AEResumeTheCurrentEvent, 1, |
| 766 | "(AppleEvent reply, EventHandler dispatcher) -> None"}, |
| 767 | {"AEGetTheCurrentEvent", (PyCFunction)AEDesc_AEGetTheCurrentEvent, 1, |
| 768 | "() -> None"}, |
| 769 | {"AESetTheCurrentEvent", (PyCFunction)AEDesc_AESetTheCurrentEvent, 1, |
| 770 | "() -> None"}, |
| 771 | {"AEResolve", (PyCFunction)AEDesc_AEResolve, 1, |
| 772 | "(short callbackFlags) -> (AEDesc theToken)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 773 | {NULL, NULL, 0} |
| 774 | }; |
| 775 | |
Jack Jansen | f69633e | 1997-08-15 14:31:13 +0000 | [diff] [blame] | 776 | PyMethodChain AEDesc_chain = { AEDesc_methods, NULL }; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 777 | |
| 778 | static PyObject *AEDesc_getattr(self, name) |
| 779 | AEDescObject *self; |
| 780 | char *name; |
| 781 | { |
| 782 | |
| 783 | if (strcmp(name, "type") == 0) |
| 784 | return PyMac_BuildOSType(self->ob_itself.descriptorType); |
| 785 | if (strcmp(name, "data") == 0) { |
| 786 | PyObject *res; |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 787 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 788 | char state; |
| 789 | state = HGetState(self->ob_itself.dataHandle); |
| 790 | HLock(self->ob_itself.dataHandle); |
| 791 | res = PyString_FromStringAndSize( |
| 792 | *self->ob_itself.dataHandle, |
| 793 | GetHandleSize(self->ob_itself.dataHandle)); |
| 794 | HUnlock(self->ob_itself.dataHandle); |
| 795 | HSetState(self->ob_itself.dataHandle, state); |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 796 | #else |
| 797 | Size size; |
| 798 | char *ptr; |
| 799 | OSErr err; |
| 800 | |
| 801 | size = AEGetDescDataSize(&self->ob_itself); |
| 802 | if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL ) |
| 803 | return NULL; |
| 804 | if ( (ptr = PyString_AsString(res)) == NULL ) |
| 805 | return NULL; |
| 806 | if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 ) |
| 807 | return PyMac_Error(err); |
| 808 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 809 | return res; |
| 810 | } |
| 811 | if (strcmp(name, "__members__") == 0) |
| 812 | return Py_BuildValue("[ss]", "data", "type"); |
| 813 | |
| 814 | return Py_FindMethodInChain(&AEDesc_chain, (PyObject *)self, name); |
| 815 | } |
| 816 | |
| 817 | #define AEDesc_setattr NULL |
| 818 | |
Jack Jansen | b1b78d8 | 1999-12-14 15:47:01 +0000 | [diff] [blame] | 819 | #define AEDesc_compare NULL |
| 820 | |
| 821 | #define AEDesc_repr NULL |
| 822 | |
| 823 | #define AEDesc_hash NULL |
| 824 | |
Jack Jansen | f69633e | 1997-08-15 14:31:13 +0000 | [diff] [blame] | 825 | PyTypeObject AEDesc_Type = { |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 826 | PyObject_HEAD_INIT(&PyType_Type) |
| 827 | 0, /*ob_size*/ |
| 828 | "AEDesc", /*tp_name*/ |
| 829 | sizeof(AEDescObject), /*tp_basicsize*/ |
| 830 | 0, /*tp_itemsize*/ |
| 831 | /* methods */ |
| 832 | (destructor) AEDesc_dealloc, /*tp_dealloc*/ |
| 833 | 0, /*tp_print*/ |
| 834 | (getattrfunc) AEDesc_getattr, /*tp_getattr*/ |
| 835 | (setattrfunc) AEDesc_setattr, /*tp_setattr*/ |
Jack Jansen | b1b78d8 | 1999-12-14 15:47:01 +0000 | [diff] [blame] | 836 | (cmpfunc) AEDesc_compare, /*tp_compare*/ |
| 837 | (reprfunc) AEDesc_repr, /*tp_repr*/ |
| 838 | (PyNumberMethods *)0, /* tp_as_number */ |
| 839 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 840 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 841 | (hashfunc) AEDesc_hash, /*tp_hash*/ |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 842 | }; |
| 843 | |
| 844 | /* --------------------- End object type AEDesc --------------------- */ |
| 845 | |
| 846 | |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 847 | static PyObject *AE_AECoercePtr(_self, _args) |
| 848 | PyObject *_self; |
| 849 | PyObject *_args; |
| 850 | { |
| 851 | PyObject *_res = NULL; |
| 852 | OSErr _err; |
| 853 | DescType typeCode; |
| 854 | char *dataPtr__in__; |
| 855 | long dataPtr__len__; |
| 856 | int dataPtr__in_len__; |
| 857 | DescType toType; |
| 858 | AEDesc result; |
| 859 | if (!PyArg_ParseTuple(_args, "O&s#O&", |
| 860 | PyMac_GetOSType, &typeCode, |
| 861 | &dataPtr__in__, &dataPtr__in_len__, |
| 862 | PyMac_GetOSType, &toType)) |
| 863 | return NULL; |
| 864 | dataPtr__len__ = dataPtr__in_len__; |
| 865 | _err = AECoercePtr(typeCode, |
| 866 | dataPtr__in__, dataPtr__len__, |
| 867 | toType, |
| 868 | &result); |
| 869 | if (_err != noErr) return PyMac_Error(_err); |
| 870 | _res = Py_BuildValue("O&", |
| 871 | AEDesc_New, &result); |
| 872 | dataPtr__error__: ; |
| 873 | return _res; |
| 874 | } |
| 875 | |
| 876 | static PyObject *AE_AECreateDesc(_self, _args) |
| 877 | PyObject *_self; |
| 878 | PyObject *_args; |
| 879 | { |
| 880 | PyObject *_res = NULL; |
| 881 | OSErr _err; |
| 882 | DescType typeCode; |
| 883 | char *dataPtr__in__; |
| 884 | long dataPtr__len__; |
| 885 | int dataPtr__in_len__; |
| 886 | AEDesc result; |
| 887 | if (!PyArg_ParseTuple(_args, "O&s#", |
| 888 | PyMac_GetOSType, &typeCode, |
| 889 | &dataPtr__in__, &dataPtr__in_len__)) |
| 890 | return NULL; |
| 891 | dataPtr__len__ = dataPtr__in_len__; |
| 892 | _err = AECreateDesc(typeCode, |
| 893 | dataPtr__in__, dataPtr__len__, |
| 894 | &result); |
| 895 | if (_err != noErr) return PyMac_Error(_err); |
| 896 | _res = Py_BuildValue("O&", |
| 897 | AEDesc_New, &result); |
| 898 | dataPtr__error__: ; |
| 899 | return _res; |
| 900 | } |
| 901 | |
| 902 | static PyObject *AE_AECreateList(_self, _args) |
| 903 | PyObject *_self; |
| 904 | PyObject *_args; |
| 905 | { |
| 906 | PyObject *_res = NULL; |
| 907 | OSErr _err; |
| 908 | char *factoringPtr__in__; |
| 909 | long factoringPtr__len__; |
| 910 | int factoringPtr__in_len__; |
| 911 | Boolean isRecord; |
| 912 | AEDescList resultList; |
| 913 | if (!PyArg_ParseTuple(_args, "s#b", |
| 914 | &factoringPtr__in__, &factoringPtr__in_len__, |
| 915 | &isRecord)) |
| 916 | return NULL; |
| 917 | factoringPtr__len__ = factoringPtr__in_len__; |
| 918 | _err = AECreateList(factoringPtr__in__, factoringPtr__len__, |
| 919 | isRecord, |
| 920 | &resultList); |
| 921 | if (_err != noErr) return PyMac_Error(_err); |
| 922 | _res = Py_BuildValue("O&", |
| 923 | AEDesc_New, &resultList); |
| 924 | factoringPtr__error__: ; |
| 925 | return _res; |
| 926 | } |
| 927 | |
| 928 | static PyObject *AE_AECreateAppleEvent(_self, _args) |
| 929 | PyObject *_self; |
| 930 | PyObject *_args; |
| 931 | { |
| 932 | PyObject *_res = NULL; |
| 933 | OSErr _err; |
| 934 | AEEventClass theAEEventClass; |
| 935 | AEEventID theAEEventID; |
| 936 | AEAddressDesc target; |
| 937 | AEReturnID returnID; |
| 938 | AETransactionID transactionID; |
| 939 | AppleEvent result; |
| 940 | if (!PyArg_ParseTuple(_args, "O&O&O&hl", |
| 941 | PyMac_GetOSType, &theAEEventClass, |
| 942 | PyMac_GetOSType, &theAEEventID, |
| 943 | AEDesc_Convert, &target, |
| 944 | &returnID, |
| 945 | &transactionID)) |
| 946 | return NULL; |
| 947 | _err = AECreateAppleEvent(theAEEventClass, |
| 948 | theAEEventID, |
| 949 | &target, |
| 950 | returnID, |
| 951 | transactionID, |
| 952 | &result); |
| 953 | if (_err != noErr) return PyMac_Error(_err); |
| 954 | _res = Py_BuildValue("O&", |
| 955 | AEDesc_New, &result); |
| 956 | return _res; |
| 957 | } |
| 958 | |
| 959 | #if TARGET_API_MAC_CARBON |
| 960 | |
| 961 | static PyObject *AE_AEReplaceDescData(_self, _args) |
| 962 | PyObject *_self; |
| 963 | PyObject *_args; |
| 964 | { |
| 965 | PyObject *_res = NULL; |
| 966 | OSErr _err; |
| 967 | DescType typeCode; |
| 968 | char *dataPtr__in__; |
| 969 | long dataPtr__len__; |
| 970 | int dataPtr__in_len__; |
| 971 | AEDesc theAEDesc; |
| 972 | if (!PyArg_ParseTuple(_args, "O&s#", |
| 973 | PyMac_GetOSType, &typeCode, |
| 974 | &dataPtr__in__, &dataPtr__in_len__)) |
| 975 | return NULL; |
| 976 | dataPtr__len__ = dataPtr__in_len__; |
| 977 | _err = AEReplaceDescData(typeCode, |
| 978 | dataPtr__in__, dataPtr__len__, |
| 979 | &theAEDesc); |
| 980 | if (_err != noErr) return PyMac_Error(_err); |
| 981 | _res = Py_BuildValue("O&", |
| 982 | AEDesc_New, &theAEDesc); |
| 983 | dataPtr__error__: ; |
| 984 | return _res; |
| 985 | } |
| 986 | #endif |
| 987 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 988 | static PyObject *AE_AEProcessAppleEvent(_self, _args) |
| 989 | PyObject *_self; |
| 990 | PyObject *_args; |
| 991 | { |
| 992 | PyObject *_res = NULL; |
| 993 | OSErr _err; |
| 994 | EventRecord theEventRecord; |
| 995 | if (!PyArg_ParseTuple(_args, "O&", |
| 996 | PyMac_GetEventRecord, &theEventRecord)) |
| 997 | return NULL; |
| 998 | _err = AEProcessAppleEvent(&theEventRecord); |
| 999 | if (_err != noErr) return PyMac_Error(_err); |
| 1000 | Py_INCREF(Py_None); |
| 1001 | _res = Py_None; |
| 1002 | return _res; |
| 1003 | } |
| 1004 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1005 | static PyObject *AE_AEGetInteractionAllowed(_self, _args) |
| 1006 | PyObject *_self; |
| 1007 | PyObject *_args; |
| 1008 | { |
| 1009 | PyObject *_res = NULL; |
| 1010 | OSErr _err; |
| 1011 | AEInteractAllowed level; |
| 1012 | if (!PyArg_ParseTuple(_args, "")) |
| 1013 | return NULL; |
| 1014 | _err = AEGetInteractionAllowed(&level); |
| 1015 | if (_err != noErr) return PyMac_Error(_err); |
| 1016 | _res = Py_BuildValue("b", |
| 1017 | level); |
| 1018 | return _res; |
| 1019 | } |
| 1020 | |
| 1021 | static PyObject *AE_AESetInteractionAllowed(_self, _args) |
| 1022 | PyObject *_self; |
| 1023 | PyObject *_args; |
| 1024 | { |
| 1025 | PyObject *_res = NULL; |
| 1026 | OSErr _err; |
| 1027 | AEInteractAllowed level; |
| 1028 | if (!PyArg_ParseTuple(_args, "b", |
| 1029 | &level)) |
| 1030 | return NULL; |
| 1031 | _err = AESetInteractionAllowed(level); |
| 1032 | if (_err != noErr) return PyMac_Error(_err); |
| 1033 | Py_INCREF(Py_None); |
| 1034 | _res = Py_None; |
| 1035 | return _res; |
| 1036 | } |
| 1037 | |
| 1038 | static PyObject *AE_AEInteractWithUser(_self, _args) |
| 1039 | PyObject *_self; |
| 1040 | PyObject *_args; |
| 1041 | { |
| 1042 | PyObject *_res = NULL; |
| 1043 | OSErr _err; |
| 1044 | long timeOutInTicks; |
| 1045 | if (!PyArg_ParseTuple(_args, "l", |
| 1046 | &timeOutInTicks)) |
| 1047 | return NULL; |
| 1048 | _err = AEInteractWithUser(timeOutInTicks, |
| 1049 | (NMRecPtr)0, |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 1050 | upp_AEIdleProc); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1051 | if (_err != noErr) return PyMac_Error(_err); |
| 1052 | Py_INCREF(Py_None); |
| 1053 | _res = Py_None; |
| 1054 | return _res; |
| 1055 | } |
| 1056 | |
| 1057 | static PyObject *AE_AEInstallEventHandler(_self, _args) |
| 1058 | PyObject *_self; |
| 1059 | PyObject *_args; |
| 1060 | { |
| 1061 | PyObject *_res = NULL; |
| 1062 | OSErr _err; |
| 1063 | AEEventClass theAEEventClass; |
| 1064 | AEEventID theAEEventID; |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1065 | AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler; |
| 1066 | PyObject *handler; |
| 1067 | if (!PyArg_ParseTuple(_args, "O&O&O", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1068 | PyMac_GetOSType, &theAEEventClass, |
| 1069 | PyMac_GetOSType, &theAEEventID, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1070 | &handler)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1071 | return NULL; |
| 1072 | _err = AEInstallEventHandler(theAEEventClass, |
| 1073 | theAEEventID, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1074 | handler__proc__, (long)handler, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1075 | 0); |
| 1076 | if (_err != noErr) return PyMac_Error(_err); |
| 1077 | Py_INCREF(Py_None); |
| 1078 | _res = Py_None; |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1079 | Py_INCREF(handler); /* XXX leak, but needed */ |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1080 | return _res; |
| 1081 | } |
| 1082 | |
| 1083 | static PyObject *AE_AERemoveEventHandler(_self, _args) |
| 1084 | PyObject *_self; |
| 1085 | PyObject *_args; |
| 1086 | { |
| 1087 | PyObject *_res = NULL; |
| 1088 | OSErr _err; |
| 1089 | AEEventClass theAEEventClass; |
| 1090 | AEEventID theAEEventID; |
| 1091 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1092 | PyMac_GetOSType, &theAEEventClass, |
| 1093 | PyMac_GetOSType, &theAEEventID)) |
| 1094 | return NULL; |
| 1095 | _err = AERemoveEventHandler(theAEEventClass, |
| 1096 | theAEEventID, |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 1097 | upp_GenericEventHandler, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1098 | 0); |
| 1099 | if (_err != noErr) return PyMac_Error(_err); |
| 1100 | Py_INCREF(Py_None); |
| 1101 | _res = Py_None; |
| 1102 | return _res; |
| 1103 | } |
| 1104 | |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1105 | static PyObject *AE_AEGetEventHandler(_self, _args) |
| 1106 | PyObject *_self; |
| 1107 | PyObject *_args; |
| 1108 | { |
| 1109 | PyObject *_res = NULL; |
| 1110 | OSErr _err; |
| 1111 | AEEventClass theAEEventClass; |
| 1112 | AEEventID theAEEventID; |
Jack Jansen | 8ce4d51 | 1995-08-17 14:24:35 +0000 | [diff] [blame] | 1113 | AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler; |
| 1114 | PyObject *handler; |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1115 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1116 | PyMac_GetOSType, &theAEEventClass, |
| 1117 | PyMac_GetOSType, &theAEEventID)) |
| 1118 | return NULL; |
| 1119 | _err = AEGetEventHandler(theAEEventClass, |
| 1120 | theAEEventID, |
Jack Jansen | 8ce4d51 | 1995-08-17 14:24:35 +0000 | [diff] [blame] | 1121 | &handler__proc__, (long *)&handler, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1122 | 0); |
| 1123 | if (_err != noErr) return PyMac_Error(_err); |
Jack Jansen | 8ce4d51 | 1995-08-17 14:24:35 +0000 | [diff] [blame] | 1124 | _res = Py_BuildValue("O", |
| 1125 | handler); |
| 1126 | Py_INCREF(handler); /* XXX leak, but needed */ |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1127 | return _res; |
| 1128 | } |
| 1129 | |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 1130 | static PyObject *AE_AEInstallSpecialHandler(_self, _args) |
| 1131 | PyObject *_self; |
| 1132 | PyObject *_args; |
| 1133 | { |
| 1134 | PyObject *_res = NULL; |
| 1135 | OSErr _err; |
| 1136 | AEKeyword functionClass; |
| 1137 | if (!PyArg_ParseTuple(_args, "O&", |
| 1138 | PyMac_GetOSType, &functionClass)) |
| 1139 | return NULL; |
| 1140 | _err = AEInstallSpecialHandler(functionClass, |
| 1141 | upp_GenericEventHandler, |
| 1142 | 0); |
| 1143 | if (_err != noErr) return PyMac_Error(_err); |
| 1144 | Py_INCREF(Py_None); |
| 1145 | _res = Py_None; |
| 1146 | return _res; |
| 1147 | } |
| 1148 | |
| 1149 | static PyObject *AE_AERemoveSpecialHandler(_self, _args) |
| 1150 | PyObject *_self; |
| 1151 | PyObject *_args; |
| 1152 | { |
| 1153 | PyObject *_res = NULL; |
| 1154 | OSErr _err; |
| 1155 | AEKeyword functionClass; |
| 1156 | if (!PyArg_ParseTuple(_args, "O&", |
| 1157 | PyMac_GetOSType, &functionClass)) |
| 1158 | return NULL; |
| 1159 | _err = AERemoveSpecialHandler(functionClass, |
| 1160 | upp_GenericEventHandler, |
| 1161 | 0); |
| 1162 | if (_err != noErr) return PyMac_Error(_err); |
| 1163 | Py_INCREF(Py_None); |
| 1164 | _res = Py_None; |
| 1165 | return _res; |
| 1166 | } |
| 1167 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1168 | static PyObject *AE_AEManagerInfo(_self, _args) |
| 1169 | PyObject *_self; |
| 1170 | PyObject *_args; |
| 1171 | { |
| 1172 | PyObject *_res = NULL; |
| 1173 | OSErr _err; |
| 1174 | AEKeyword keyWord; |
| 1175 | long result; |
| 1176 | if (!PyArg_ParseTuple(_args, "O&", |
| 1177 | PyMac_GetOSType, &keyWord)) |
| 1178 | return NULL; |
| 1179 | _err = AEManagerInfo(keyWord, |
| 1180 | &result); |
| 1181 | if (_err != noErr) return PyMac_Error(_err); |
| 1182 | _res = Py_BuildValue("l", |
| 1183 | result); |
| 1184 | return _res; |
| 1185 | } |
| 1186 | |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1187 | static PyObject *AE_AEObjectInit(_self, _args) |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1188 | PyObject *_self; |
| 1189 | PyObject *_args; |
| 1190 | { |
| 1191 | PyObject *_res = NULL; |
| 1192 | OSErr _err; |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1193 | if (!PyArg_ParseTuple(_args, "")) |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1194 | return NULL; |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1195 | _err = AEObjectInit(); |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1196 | if (_err != noErr) return PyMac_Error(_err); |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1197 | Py_INCREF(Py_None); |
| 1198 | _res = Py_None; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1199 | return _res; |
| 1200 | } |
| 1201 | |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1202 | static PyObject *AE_AEDisposeToken(_self, _args) |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1203 | PyObject *_self; |
| 1204 | PyObject *_args; |
| 1205 | { |
| 1206 | PyObject *_res = NULL; |
| 1207 | OSErr _err; |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1208 | AEDesc theToken; |
| 1209 | if (!PyArg_ParseTuple(_args, "")) |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1210 | return NULL; |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1211 | _err = AEDisposeToken(&theToken); |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1212 | if (_err != noErr) return PyMac_Error(_err); |
| 1213 | _res = Py_BuildValue("O&", |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1214 | AEDesc_New, &theToken); |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1215 | return _res; |
| 1216 | } |
| 1217 | |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1218 | static PyObject *AE_AECallObjectAccessor(_self, _args) |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1219 | PyObject *_self; |
| 1220 | PyObject *_args; |
| 1221 | { |
| 1222 | PyObject *_res = NULL; |
| 1223 | OSErr _err; |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1224 | DescType desiredClass; |
| 1225 | AEDesc containerToken; |
| 1226 | DescType containerClass; |
| 1227 | DescType keyForm; |
| 1228 | AEDesc keyData; |
| 1229 | AEDesc token; |
| 1230 | if (!PyArg_ParseTuple(_args, "O&O&O&O&O&", |
| 1231 | PyMac_GetOSType, &desiredClass, |
| 1232 | AEDesc_Convert, &containerToken, |
| 1233 | PyMac_GetOSType, &containerClass, |
| 1234 | PyMac_GetOSType, &keyForm, |
| 1235 | AEDesc_Convert, &keyData)) |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1236 | return NULL; |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1237 | _err = AECallObjectAccessor(desiredClass, |
| 1238 | &containerToken, |
| 1239 | containerClass, |
| 1240 | keyForm, |
| 1241 | &keyData, |
| 1242 | &token); |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1243 | if (_err != noErr) return PyMac_Error(_err); |
| 1244 | _res = Py_BuildValue("O&", |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1245 | AEDesc_New, &token); |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1246 | return _res; |
| 1247 | } |
| 1248 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1249 | static PyMethodDef AE_methods[] = { |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1250 | {"AECoercePtr", (PyCFunction)AE_AECoercePtr, 1, |
| 1251 | "(DescType typeCode, Buffer dataPtr, DescType toType) -> (AEDesc result)"}, |
| 1252 | {"AECreateDesc", (PyCFunction)AE_AECreateDesc, 1, |
| 1253 | "(DescType typeCode, Buffer dataPtr) -> (AEDesc result)"}, |
| 1254 | {"AECreateList", (PyCFunction)AE_AECreateList, 1, |
| 1255 | "(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)"}, |
| 1256 | {"AECreateAppleEvent", (PyCFunction)AE_AECreateAppleEvent, 1, |
| 1257 | "(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, AEReturnID returnID, AETransactionID transactionID) -> (AppleEvent result)"}, |
| 1258 | |
| 1259 | #if TARGET_API_MAC_CARBON |
| 1260 | {"AEReplaceDescData", (PyCFunction)AE_AEReplaceDescData, 1, |
| 1261 | "(DescType typeCode, Buffer dataPtr) -> (AEDesc theAEDesc)"}, |
| 1262 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1263 | {"AEProcessAppleEvent", (PyCFunction)AE_AEProcessAppleEvent, 1, |
| 1264 | "(EventRecord theEventRecord) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1265 | {"AEGetInteractionAllowed", (PyCFunction)AE_AEGetInteractionAllowed, 1, |
| 1266 | "() -> (AEInteractAllowed level)"}, |
| 1267 | {"AESetInteractionAllowed", (PyCFunction)AE_AESetInteractionAllowed, 1, |
| 1268 | "(AEInteractAllowed level) -> None"}, |
| 1269 | {"AEInteractWithUser", (PyCFunction)AE_AEInteractWithUser, 1, |
| 1270 | "(long timeOutInTicks) -> None"}, |
| 1271 | {"AEInstallEventHandler", (PyCFunction)AE_AEInstallEventHandler, 1, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1272 | "(AEEventClass theAEEventClass, AEEventID theAEEventID, EventHandler handler) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1273 | {"AERemoveEventHandler", (PyCFunction)AE_AERemoveEventHandler, 1, |
| 1274 | "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None"}, |
Jack Jansen | 5050199 | 1995-07-29 13:58:41 +0000 | [diff] [blame] | 1275 | {"AEGetEventHandler", (PyCFunction)AE_AEGetEventHandler, 1, |
| 1276 | "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> (EventHandler handler)"}, |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 1277 | {"AEInstallSpecialHandler", (PyCFunction)AE_AEInstallSpecialHandler, 1, |
| 1278 | "(AEKeyword functionClass) -> None"}, |
| 1279 | {"AERemoveSpecialHandler", (PyCFunction)AE_AERemoveSpecialHandler, 1, |
| 1280 | "(AEKeyword functionClass) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1281 | {"AEManagerInfo", (PyCFunction)AE_AEManagerInfo, 1, |
| 1282 | "(AEKeyword keyWord) -> (long result)"}, |
Jack Jansen | 8ed8130 | 2000-12-12 22:09:11 +0000 | [diff] [blame] | 1283 | {"AEObjectInit", (PyCFunction)AE_AEObjectInit, 1, |
| 1284 | "() -> None"}, |
| 1285 | {"AEDisposeToken", (PyCFunction)AE_AEDisposeToken, 1, |
| 1286 | "() -> (AEDesc theToken)"}, |
| 1287 | {"AECallObjectAccessor", (PyCFunction)AE_AECallObjectAccessor, 1, |
| 1288 | "(DescType desiredClass, AEDesc containerToken, DescType containerClass, DescType keyForm, AEDesc keyData) -> (AEDesc token)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1289 | {NULL, NULL, 0} |
| 1290 | }; |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | static pascal OSErr |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1295 | GenericEventHandler(const AppleEvent *request, AppleEvent *reply, unsigned long refcon) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1296 | { |
| 1297 | PyObject *handler = (PyObject *)refcon; |
| 1298 | AEDescObject *requestObject, *replyObject; |
| 1299 | PyObject *args, *res; |
Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 1300 | if ((requestObject = (AEDescObject *)AEDesc_New((AppleEvent *)request)) == NULL) { |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1301 | return -1; |
| 1302 | } |
| 1303 | if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) { |
| 1304 | Py_DECREF(requestObject); |
| 1305 | return -1; |
| 1306 | } |
| 1307 | if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) { |
| 1308 | Py_DECREF(requestObject); |
| 1309 | Py_DECREF(replyObject); |
| 1310 | return -1; |
| 1311 | } |
| 1312 | res = PyEval_CallObject(handler, args); |
| 1313 | requestObject->ob_itself.descriptorType = 'null'; |
| 1314 | requestObject->ob_itself.dataHandle = NULL; |
| 1315 | replyObject->ob_itself.descriptorType = 'null'; |
| 1316 | replyObject->ob_itself.dataHandle = NULL; |
| 1317 | Py_DECREF(args); |
| 1318 | if (res == NULL) |
| 1319 | return -1; |
| 1320 | Py_DECREF(res); |
| 1321 | return noErr; |
| 1322 | } |
| 1323 | |
| 1324 | |
| 1325 | void initAE() |
| 1326 | { |
| 1327 | PyObject *m; |
| 1328 | PyObject *d; |
| 1329 | |
| 1330 | |
| 1331 | |
Guido van Rossum | b19a645 | 1995-02-05 16:58:33 +0000 | [diff] [blame] | 1332 | upp_AEIdleProc = NewAEIdleProc(AEIdleProc); |
| 1333 | upp_GenericEventHandler = NewAEEventHandlerProc(GenericEventHandler); |
| 1334 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1335 | |
| 1336 | m = Py_InitModule("AE", AE_methods); |
| 1337 | d = PyModule_GetDict(m); |
| 1338 | AE_Error = PyMac_GetOSErrException(); |
| 1339 | if (AE_Error == NULL || |
| 1340 | PyDict_SetItemString(d, "Error", AE_Error) != 0) |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 1341 | return; |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 1342 | AEDesc_Type.ob_type = &PyType_Type; |
| 1343 | Py_INCREF(&AEDesc_Type); |
| 1344 | if (PyDict_SetItemString(d, "AEDescType", (PyObject *)&AEDesc_Type) != 0) |
| 1345 | Py_FatalError("can't initialize AEDescType"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | /* ========================= End module AE ========================== */ |
| 1349 | |