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