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