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