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