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