2 /* =========================== Module _AE =========================== */
9 #include "pywintoolbox.h"
12 #include "pymactoolbox.h"
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
24 #define PyDoc_STR(x) (x)
26 #ifdef WITHOUT_FRAMEWORKS
27 #include <AppleEvents.h>
28 #include <AEObjects.h>
30 #include <Carbon/Carbon.h>
33 #ifdef USE_TOOLBOX_OBJECT_GLUE
34 extern PyObject
*_AEDesc_New(AEDesc
*);
35 extern int _AEDesc_Convert(PyObject
*, AEDesc
*);
37 #define AEDesc_New _AEDesc_New
38 #define AEDesc_Convert _AEDesc_Convert
41 typedef long refcontype
;
43 static pascal OSErr
GenericEventHandler(const AppleEvent
*request
, AppleEvent
*reply
, refcontype refcon
); /* Forward */
45 AEEventHandlerUPP upp_GenericEventHandler
;
47 static pascal Boolean
AEIdleProc(EventRecord
*theEvent
, long *sleepTime
, RgnHandle
*mouseRgn
)
49 if ( PyOS_InterruptOccurred() )
51 #if !TARGET_API_MAC_OSX
52 if ( PyMac_HandleEvent(theEvent
) < 0 ) {
53 PySys_WriteStderr("Exception in user event handler during AE processing\n");
60 AEIdleUPP upp_AEIdleProc
;
62 static PyObject
*AE_Error
;
64 /* ----------------------- Object type AEDesc ----------------------- */
66 PyTypeObject AEDesc_Type
;
68 #define AEDesc_Check(x) ((x)->ob_type == &AEDesc_Type || PyObject_TypeCheck((x), &AEDesc_Type))
70 typedef struct AEDescObject
{
75 PyObject
*AEDesc_New(AEDesc
*itself
)
78 it
= PyObject_NEW(AEDescObject
, &AEDesc_Type
);
79 if (it
== NULL
) return NULL
;
80 it
->ob_itself
= *itself
;
81 return (PyObject
*)it
;
83 int AEDesc_Convert(PyObject
*v
, AEDesc
*p_itself
)
87 PyErr_SetString(PyExc_TypeError
, "AEDesc required");
90 *p_itself
= ((AEDescObject
*)v
)->ob_itself
;
94 static void AEDesc_dealloc(AEDescObject
*self
)
96 AEDisposeDesc(&self
->ob_itself
);
97 self
->ob_type
->tp_free((PyObject
*)self
);
100 static PyObject
*AEDesc_AECoerceDesc(AEDescObject
*_self
, PyObject
*_args
)
102 PyObject
*_res
= NULL
;
107 PyMac_PRECHECK(AECoerceDesc
);
109 if (!PyArg_ParseTuple(_args
, "O&",
110 PyMac_GetOSType
, &toType
))
112 _err
= AECoerceDesc(&_self
->ob_itself
,
115 if (_err
!= noErr
) return PyMac_Error(_err
);
116 _res
= Py_BuildValue("O&",
117 AEDesc_New
, &result
);
121 static PyObject
*AEDesc_AEDuplicateDesc(AEDescObject
*_self
, PyObject
*_args
)
123 PyObject
*_res
= NULL
;
126 #ifndef AEDuplicateDesc
127 PyMac_PRECHECK(AEDuplicateDesc
);
129 if (!PyArg_ParseTuple(_args
, ""))
131 _err
= AEDuplicateDesc(&_self
->ob_itself
,
133 if (_err
!= noErr
) return PyMac_Error(_err
);
134 _res
= Py_BuildValue("O&",
135 AEDesc_New
, &result
);
139 static PyObject
*AEDesc_AECountItems(AEDescObject
*_self
, PyObject
*_args
)
141 PyObject
*_res
= NULL
;
145 PyMac_PRECHECK(AECountItems
);
147 if (!PyArg_ParseTuple(_args
, ""))
149 _err
= AECountItems(&_self
->ob_itself
,
151 if (_err
!= noErr
) return PyMac_Error(_err
);
152 _res
= Py_BuildValue("l",
157 static PyObject
*AEDesc_AEPutPtr(AEDescObject
*_self
, PyObject
*_args
)
159 PyObject
*_res
= NULL
;
165 int dataPtr__in_len__
;
167 PyMac_PRECHECK(AEPutPtr
);
169 if (!PyArg_ParseTuple(_args
, "lO&s#",
171 PyMac_GetOSType
, &typeCode
,
172 &dataPtr__in__
, &dataPtr__in_len__
))
174 dataPtr__len__
= dataPtr__in_len__
;
175 _err
= AEPutPtr(&_self
->ob_itself
,
178 dataPtr__in__
, dataPtr__len__
);
179 if (_err
!= noErr
) return PyMac_Error(_err
);
185 static PyObject
*AEDesc_AEPutDesc(AEDescObject
*_self
, PyObject
*_args
)
187 PyObject
*_res
= NULL
;
192 PyMac_PRECHECK(AEPutDesc
);
194 if (!PyArg_ParseTuple(_args
, "lO&",
196 AEDesc_Convert
, &theAEDesc
))
198 _err
= AEPutDesc(&_self
->ob_itself
,
201 if (_err
!= noErr
) return PyMac_Error(_err
);
207 static PyObject
*AEDesc_AEGetNthPtr(AEDescObject
*_self
, PyObject
*_args
)
209 PyObject
*_res
= NULL
;
212 DescType desiredType
;
213 AEKeyword theAEKeyword
;
215 char *dataPtr__out__
;
217 int dataPtr__in_len__
;
219 PyMac_PRECHECK(AEGetNthPtr
);
221 if (!PyArg_ParseTuple(_args
, "lO&i",
223 PyMac_GetOSType
, &desiredType
,
226 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
229 goto dataPtr__error__
;
231 dataPtr__len__
= dataPtr__in_len__
;
232 _err
= AEGetNthPtr(&_self
->ob_itself
,
237 dataPtr__out__
, dataPtr__len__
, &dataPtr__len__
);
238 if (_err
!= noErr
) return PyMac_Error(_err
);
239 _res
= Py_BuildValue("O&O&s#",
240 PyMac_BuildOSType
, theAEKeyword
,
241 PyMac_BuildOSType
, typeCode
,
242 dataPtr__out__
, (int)dataPtr__len__
);
243 free(dataPtr__out__
);
248 static PyObject
*AEDesc_AEGetNthDesc(AEDescObject
*_self
, PyObject
*_args
)
250 PyObject
*_res
= NULL
;
253 DescType desiredType
;
254 AEKeyword theAEKeyword
;
257 PyMac_PRECHECK(AEGetNthDesc
);
259 if (!PyArg_ParseTuple(_args
, "lO&",
261 PyMac_GetOSType
, &desiredType
))
263 _err
= AEGetNthDesc(&_self
->ob_itself
,
268 if (_err
!= noErr
) return PyMac_Error(_err
);
269 _res
= Py_BuildValue("O&O&",
270 PyMac_BuildOSType
, theAEKeyword
,
271 AEDesc_New
, &result
);
275 static PyObject
*AEDesc_AESizeOfNthItem(AEDescObject
*_self
, PyObject
*_args
)
277 PyObject
*_res
= NULL
;
282 #ifndef AESizeOfNthItem
283 PyMac_PRECHECK(AESizeOfNthItem
);
285 if (!PyArg_ParseTuple(_args
, "l",
288 _err
= AESizeOfNthItem(&_self
->ob_itself
,
292 if (_err
!= noErr
) return PyMac_Error(_err
);
293 _res
= Py_BuildValue("O&l",
294 PyMac_BuildOSType
, typeCode
,
299 static PyObject
*AEDesc_AEDeleteItem(AEDescObject
*_self
, PyObject
*_args
)
301 PyObject
*_res
= NULL
;
305 PyMac_PRECHECK(AEDeleteItem
);
307 if (!PyArg_ParseTuple(_args
, "l",
310 _err
= AEDeleteItem(&_self
->ob_itself
,
312 if (_err
!= noErr
) return PyMac_Error(_err
);
318 static PyObject
*AEDesc_AEPutParamPtr(AEDescObject
*_self
, PyObject
*_args
)
320 PyObject
*_res
= NULL
;
322 AEKeyword theAEKeyword
;
326 int dataPtr__in_len__
;
327 #ifndef AEPutParamPtr
328 PyMac_PRECHECK(AEPutParamPtr
);
330 if (!PyArg_ParseTuple(_args
, "O&O&s#",
331 PyMac_GetOSType
, &theAEKeyword
,
332 PyMac_GetOSType
, &typeCode
,
333 &dataPtr__in__
, &dataPtr__in_len__
))
335 dataPtr__len__
= dataPtr__in_len__
;
336 _err
= AEPutParamPtr(&_self
->ob_itself
,
339 dataPtr__in__
, dataPtr__len__
);
340 if (_err
!= noErr
) return PyMac_Error(_err
);
346 static PyObject
*AEDesc_AEPutParamDesc(AEDescObject
*_self
, PyObject
*_args
)
348 PyObject
*_res
= NULL
;
350 AEKeyword theAEKeyword
;
352 #ifndef AEPutParamDesc
353 PyMac_PRECHECK(AEPutParamDesc
);
355 if (!PyArg_ParseTuple(_args
, "O&O&",
356 PyMac_GetOSType
, &theAEKeyword
,
357 AEDesc_Convert
, &theAEDesc
))
359 _err
= AEPutParamDesc(&_self
->ob_itself
,
362 if (_err
!= noErr
) return PyMac_Error(_err
);
368 static PyObject
*AEDesc_AEGetParamPtr(AEDescObject
*_self
, PyObject
*_args
)
370 PyObject
*_res
= NULL
;
372 AEKeyword theAEKeyword
;
373 DescType desiredType
;
375 char *dataPtr__out__
;
377 int dataPtr__in_len__
;
378 #ifndef AEGetParamPtr
379 PyMac_PRECHECK(AEGetParamPtr
);
381 if (!PyArg_ParseTuple(_args
, "O&O&i",
382 PyMac_GetOSType
, &theAEKeyword
,
383 PyMac_GetOSType
, &desiredType
,
386 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
389 goto dataPtr__error__
;
391 dataPtr__len__
= dataPtr__in_len__
;
392 _err
= AEGetParamPtr(&_self
->ob_itself
,
396 dataPtr__out__
, dataPtr__len__
, &dataPtr__len__
);
397 if (_err
!= noErr
) return PyMac_Error(_err
);
398 _res
= Py_BuildValue("O&s#",
399 PyMac_BuildOSType
, typeCode
,
400 dataPtr__out__
, (int)dataPtr__len__
);
401 free(dataPtr__out__
);
406 static PyObject
*AEDesc_AEGetParamDesc(AEDescObject
*_self
, PyObject
*_args
)
408 PyObject
*_res
= NULL
;
410 AEKeyword theAEKeyword
;
411 DescType desiredType
;
413 #ifndef AEGetParamDesc
414 PyMac_PRECHECK(AEGetParamDesc
);
416 if (!PyArg_ParseTuple(_args
, "O&O&",
417 PyMac_GetOSType
, &theAEKeyword
,
418 PyMac_GetOSType
, &desiredType
))
420 _err
= AEGetParamDesc(&_self
->ob_itself
,
424 if (_err
!= noErr
) return PyMac_Error(_err
);
425 _res
= Py_BuildValue("O&",
426 AEDesc_New
, &result
);
430 static PyObject
*AEDesc_AESizeOfParam(AEDescObject
*_self
, PyObject
*_args
)
432 PyObject
*_res
= NULL
;
434 AEKeyword theAEKeyword
;
437 #ifndef AESizeOfParam
438 PyMac_PRECHECK(AESizeOfParam
);
440 if (!PyArg_ParseTuple(_args
, "O&",
441 PyMac_GetOSType
, &theAEKeyword
))
443 _err
= AESizeOfParam(&_self
->ob_itself
,
447 if (_err
!= noErr
) return PyMac_Error(_err
);
448 _res
= Py_BuildValue("O&l",
449 PyMac_BuildOSType
, typeCode
,
454 static PyObject
*AEDesc_AEDeleteParam(AEDescObject
*_self
, PyObject
*_args
)
456 PyObject
*_res
= NULL
;
458 AEKeyword theAEKeyword
;
459 #ifndef AEDeleteParam
460 PyMac_PRECHECK(AEDeleteParam
);
462 if (!PyArg_ParseTuple(_args
, "O&",
463 PyMac_GetOSType
, &theAEKeyword
))
465 _err
= AEDeleteParam(&_self
->ob_itself
,
467 if (_err
!= noErr
) return PyMac_Error(_err
);
473 static PyObject
*AEDesc_AEGetAttributePtr(AEDescObject
*_self
, PyObject
*_args
)
475 PyObject
*_res
= NULL
;
477 AEKeyword theAEKeyword
;
478 DescType desiredType
;
480 char *dataPtr__out__
;
482 int dataPtr__in_len__
;
483 #ifndef AEGetAttributePtr
484 PyMac_PRECHECK(AEGetAttributePtr
);
486 if (!PyArg_ParseTuple(_args
, "O&O&i",
487 PyMac_GetOSType
, &theAEKeyword
,
488 PyMac_GetOSType
, &desiredType
,
491 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
494 goto dataPtr__error__
;
496 dataPtr__len__
= dataPtr__in_len__
;
497 _err
= AEGetAttributePtr(&_self
->ob_itself
,
501 dataPtr__out__
, dataPtr__len__
, &dataPtr__len__
);
502 if (_err
!= noErr
) return PyMac_Error(_err
);
503 _res
= Py_BuildValue("O&s#",
504 PyMac_BuildOSType
, typeCode
,
505 dataPtr__out__
, (int)dataPtr__len__
);
506 free(dataPtr__out__
);
511 static PyObject
*AEDesc_AEGetAttributeDesc(AEDescObject
*_self
, PyObject
*_args
)
513 PyObject
*_res
= NULL
;
515 AEKeyword theAEKeyword
;
516 DescType desiredType
;
518 #ifndef AEGetAttributeDesc
519 PyMac_PRECHECK(AEGetAttributeDesc
);
521 if (!PyArg_ParseTuple(_args
, "O&O&",
522 PyMac_GetOSType
, &theAEKeyword
,
523 PyMac_GetOSType
, &desiredType
))
525 _err
= AEGetAttributeDesc(&_self
->ob_itself
,
529 if (_err
!= noErr
) return PyMac_Error(_err
);
530 _res
= Py_BuildValue("O&",
531 AEDesc_New
, &result
);
535 static PyObject
*AEDesc_AESizeOfAttribute(AEDescObject
*_self
, PyObject
*_args
)
537 PyObject
*_res
= NULL
;
539 AEKeyword theAEKeyword
;
542 #ifndef AESizeOfAttribute
543 PyMac_PRECHECK(AESizeOfAttribute
);
545 if (!PyArg_ParseTuple(_args
, "O&",
546 PyMac_GetOSType
, &theAEKeyword
))
548 _err
= AESizeOfAttribute(&_self
->ob_itself
,
552 if (_err
!= noErr
) return PyMac_Error(_err
);
553 _res
= Py_BuildValue("O&l",
554 PyMac_BuildOSType
, typeCode
,
559 static PyObject
*AEDesc_AEPutAttributePtr(AEDescObject
*_self
, PyObject
*_args
)
561 PyObject
*_res
= NULL
;
563 AEKeyword theAEKeyword
;
567 int dataPtr__in_len__
;
568 #ifndef AEPutAttributePtr
569 PyMac_PRECHECK(AEPutAttributePtr
);
571 if (!PyArg_ParseTuple(_args
, "O&O&s#",
572 PyMac_GetOSType
, &theAEKeyword
,
573 PyMac_GetOSType
, &typeCode
,
574 &dataPtr__in__
, &dataPtr__in_len__
))
576 dataPtr__len__
= dataPtr__in_len__
;
577 _err
= AEPutAttributePtr(&_self
->ob_itself
,
580 dataPtr__in__
, dataPtr__len__
);
581 if (_err
!= noErr
) return PyMac_Error(_err
);
587 static PyObject
*AEDesc_AEPutAttributeDesc(AEDescObject
*_self
, PyObject
*_args
)
589 PyObject
*_res
= NULL
;
591 AEKeyword theAEKeyword
;
593 #ifndef AEPutAttributeDesc
594 PyMac_PRECHECK(AEPutAttributeDesc
);
596 if (!PyArg_ParseTuple(_args
, "O&O&",
597 PyMac_GetOSType
, &theAEKeyword
,
598 AEDesc_Convert
, &theAEDesc
))
600 _err
= AEPutAttributeDesc(&_self
->ob_itself
,
603 if (_err
!= noErr
) return PyMac_Error(_err
);
609 static PyObject
*AEDesc_AEGetDescDataSize(AEDescObject
*_self
, PyObject
*_args
)
611 PyObject
*_res
= NULL
;
613 #ifndef AEGetDescDataSize
614 PyMac_PRECHECK(AEGetDescDataSize
);
616 if (!PyArg_ParseTuple(_args
, ""))
618 _rv
= AEGetDescDataSize(&_self
->ob_itself
);
619 _res
= Py_BuildValue("l",
624 static PyObject
*AEDesc_AESend(AEDescObject
*_self
, PyObject
*_args
)
626 PyObject
*_res
= NULL
;
630 AESendPriority sendPriority
;
633 PyMac_PRECHECK(AESend
);
635 if (!PyArg_ParseTuple(_args
, "lhl",
640 _err
= AESend(&_self
->ob_itself
,
647 if (_err
!= noErr
) return PyMac_Error(_err
);
648 _res
= Py_BuildValue("O&",
653 static PyObject
*AEDesc_AEResetTimer(AEDescObject
*_self
, PyObject
*_args
)
655 PyObject
*_res
= NULL
;
658 PyMac_PRECHECK(AEResetTimer
);
660 if (!PyArg_ParseTuple(_args
, ""))
662 _err
= AEResetTimer(&_self
->ob_itself
);
663 if (_err
!= noErr
) return PyMac_Error(_err
);
669 static PyObject
*AEDesc_AESuspendTheCurrentEvent(AEDescObject
*_self
, PyObject
*_args
)
671 PyObject
*_res
= NULL
;
673 #ifndef AESuspendTheCurrentEvent
674 PyMac_PRECHECK(AESuspendTheCurrentEvent
);
676 if (!PyArg_ParseTuple(_args
, ""))
678 _err
= AESuspendTheCurrentEvent(&_self
->ob_itself
);
679 if (_err
!= noErr
) return PyMac_Error(_err
);
685 static PyObject
*AEDesc_AEResumeTheCurrentEvent(AEDescObject
*_self
, PyObject
*_args
)
687 PyObject
*_res
= NULL
;
690 AEEventHandlerUPP dispatcher__proc__
= upp_GenericEventHandler
;
691 PyObject
*dispatcher
;
692 #ifndef AEResumeTheCurrentEvent
693 PyMac_PRECHECK(AEResumeTheCurrentEvent
);
695 if (!PyArg_ParseTuple(_args
, "O&O",
696 AEDesc_Convert
, &reply
,
699 _err
= AEResumeTheCurrentEvent(&_self
->ob_itself
,
701 dispatcher__proc__
, (long)dispatcher
);
702 if (_err
!= noErr
) return PyMac_Error(_err
);
705 Py_INCREF(dispatcher
); /* XXX leak, but needed */
709 static PyObject
*AEDesc_AEGetTheCurrentEvent(AEDescObject
*_self
, PyObject
*_args
)
711 PyObject
*_res
= NULL
;
713 #ifndef AEGetTheCurrentEvent
714 PyMac_PRECHECK(AEGetTheCurrentEvent
);
716 if (!PyArg_ParseTuple(_args
, ""))
718 _err
= AEGetTheCurrentEvent(&_self
->ob_itself
);
719 if (_err
!= noErr
) return PyMac_Error(_err
);
725 static PyObject
*AEDesc_AESetTheCurrentEvent(AEDescObject
*_self
, PyObject
*_args
)
727 PyObject
*_res
= NULL
;
729 #ifndef AESetTheCurrentEvent
730 PyMac_PRECHECK(AESetTheCurrentEvent
);
732 if (!PyArg_ParseTuple(_args
, ""))
734 _err
= AESetTheCurrentEvent(&_self
->ob_itself
);
735 if (_err
!= noErr
) return PyMac_Error(_err
);
741 static PyObject
*AEDesc_AEResolve(AEDescObject
*_self
, PyObject
*_args
)
743 PyObject
*_res
= NULL
;
748 PyMac_PRECHECK(AEResolve
);
750 if (!PyArg_ParseTuple(_args
, "h",
753 _err
= AEResolve(&_self
->ob_itself
,
756 if (_err
!= noErr
) return PyMac_Error(_err
);
757 _res
= Py_BuildValue("O&",
758 AEDesc_New
, &theToken
);
762 static PyMethodDef AEDesc_methods
[] = {
763 {"AECoerceDesc", (PyCFunction
)AEDesc_AECoerceDesc
, 1,
764 PyDoc_STR("(DescType toType) -> (AEDesc result)")},
765 {"AEDuplicateDesc", (PyCFunction
)AEDesc_AEDuplicateDesc
, 1,
766 PyDoc_STR("() -> (AEDesc result)")},
767 {"AECountItems", (PyCFunction
)AEDesc_AECountItems
, 1,
768 PyDoc_STR("() -> (long theCount)")},
769 {"AEPutPtr", (PyCFunction
)AEDesc_AEPutPtr
, 1,
770 PyDoc_STR("(long index, DescType typeCode, Buffer dataPtr) -> None")},
771 {"AEPutDesc", (PyCFunction
)AEDesc_AEPutDesc
, 1,
772 PyDoc_STR("(long index, AEDesc theAEDesc) -> None")},
773 {"AEGetNthPtr", (PyCFunction
)AEDesc_AEGetNthPtr
, 1,
774 PyDoc_STR("(long index, DescType desiredType, Buffer dataPtr) -> (AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr)")},
775 {"AEGetNthDesc", (PyCFunction
)AEDesc_AEGetNthDesc
, 1,
776 PyDoc_STR("(long index, DescType desiredType) -> (AEKeyword theAEKeyword, AEDesc result)")},
777 {"AESizeOfNthItem", (PyCFunction
)AEDesc_AESizeOfNthItem
, 1,
778 PyDoc_STR("(long index) -> (DescType typeCode, Size dataSize)")},
779 {"AEDeleteItem", (PyCFunction
)AEDesc_AEDeleteItem
, 1,
780 PyDoc_STR("(long index) -> None")},
781 {"AEPutParamPtr", (PyCFunction
)AEDesc_AEPutParamPtr
, 1,
782 PyDoc_STR("(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None")},
783 {"AEPutParamDesc", (PyCFunction
)AEDesc_AEPutParamDesc
, 1,
784 PyDoc_STR("(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None")},
785 {"AEGetParamPtr", (PyCFunction
)AEDesc_AEGetParamPtr
, 1,
786 PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)")},
787 {"AEGetParamDesc", (PyCFunction
)AEDesc_AEGetParamDesc
, 1,
788 PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)")},
789 {"AESizeOfParam", (PyCFunction
)AEDesc_AESizeOfParam
, 1,
790 PyDoc_STR("(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)")},
791 {"AEDeleteParam", (PyCFunction
)AEDesc_AEDeleteParam
, 1,
792 PyDoc_STR("(AEKeyword theAEKeyword) -> None")},
793 {"AEGetAttributePtr", (PyCFunction
)AEDesc_AEGetAttributePtr
, 1,
794 PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)")},
795 {"AEGetAttributeDesc", (PyCFunction
)AEDesc_AEGetAttributeDesc
, 1,
796 PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)")},
797 {"AESizeOfAttribute", (PyCFunction
)AEDesc_AESizeOfAttribute
, 1,
798 PyDoc_STR("(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)")},
799 {"AEPutAttributePtr", (PyCFunction
)AEDesc_AEPutAttributePtr
, 1,
800 PyDoc_STR("(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None")},
801 {"AEPutAttributeDesc", (PyCFunction
)AEDesc_AEPutAttributeDesc
, 1,
802 PyDoc_STR("(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None")},
803 {"AEGetDescDataSize", (PyCFunction
)AEDesc_AEGetDescDataSize
, 1,
804 PyDoc_STR("() -> (Size _rv)")},
805 {"AESend", (PyCFunction
)AEDesc_AESend
, 1,
806 PyDoc_STR("(AESendMode sendMode, AESendPriority sendPriority, long timeOutInTicks) -> (AppleEvent reply)")},
807 {"AEResetTimer", (PyCFunction
)AEDesc_AEResetTimer
, 1,
808 PyDoc_STR("() -> None")},
809 {"AESuspendTheCurrentEvent", (PyCFunction
)AEDesc_AESuspendTheCurrentEvent
, 1,
810 PyDoc_STR("() -> None")},
811 {"AEResumeTheCurrentEvent", (PyCFunction
)AEDesc_AEResumeTheCurrentEvent
, 1,
812 PyDoc_STR("(AppleEvent reply, EventHandler dispatcher) -> None")},
813 {"AEGetTheCurrentEvent", (PyCFunction
)AEDesc_AEGetTheCurrentEvent
, 1,
814 PyDoc_STR("() -> None")},
815 {"AESetTheCurrentEvent", (PyCFunction
)AEDesc_AESetTheCurrentEvent
, 1,
816 PyDoc_STR("() -> None")},
817 {"AEResolve", (PyCFunction
)AEDesc_AEResolve
, 1,
818 PyDoc_STR("(short callbackFlags) -> (AEDesc theToken)")},
822 static PyObject
*AEDesc_get_type(AEDescObject
*self
, void *closure
)
824 return PyMac_BuildOSType(self
->ob_itself
.descriptorType
);
827 #define AEDesc_set_type NULL
829 static PyObject
*AEDesc_get_data(AEDescObject
*self
, void *closure
)
837 size
= AEGetDescDataSize(&self
->ob_itself
);
838 if ( (res
= PyString_FromStringAndSize(NULL
, size
)) == NULL
)
840 if ( (ptr
= PyString_AsString(res
)) == NULL
)
842 if ( (err
=AEGetDescData(&self
->ob_itself
, ptr
, size
)) < 0 )
843 return PyMac_Error(err
);
848 #define AEDesc_set_data NULL
850 static PyGetSetDef AEDesc_getsetlist
[] = {
851 {"type", (getter
)AEDesc_get_type
, (setter
)AEDesc_set_type
, "Type of this AEDesc"},
852 {"data", (getter
)AEDesc_get_data
, (setter
)AEDesc_set_data
, "The raw data in this AEDesc"},
853 {NULL
, NULL
, NULL
, NULL
},
857 #define AEDesc_compare NULL
859 #define AEDesc_repr NULL
861 #define AEDesc_hash NULL
862 #define AEDesc_tp_init 0
864 #define AEDesc_tp_alloc PyType_GenericAlloc
866 static PyObject
*AEDesc_tp_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
)
870 char *kw
[] = {"itself", 0};
872 if (!PyArg_ParseTupleAndKeywords(args
, kwds
, "O&", kw
, AEDesc_Convert
, &itself
)) return NULL
;
873 if ((self
= type
->tp_alloc(type
, 0)) == NULL
) return NULL
;
874 ((AEDescObject
*)self
)->ob_itself
= itself
;
878 #define AEDesc_tp_free PyObject_Del
881 PyTypeObject AEDesc_Type
= {
882 PyObject_HEAD_INIT(NULL
)
884 "_AE.AEDesc", /*tp_name*/
885 sizeof(AEDescObject
), /*tp_basicsize*/
888 (destructor
) AEDesc_dealloc
, /*tp_dealloc*/
890 (getattrfunc
)0, /*tp_getattr*/
891 (setattrfunc
)0, /*tp_setattr*/
892 (cmpfunc
) AEDesc_compare
, /*tp_compare*/
893 (reprfunc
) AEDesc_repr
, /*tp_repr*/
894 (PyNumberMethods
*)0, /* tp_as_number */
895 (PySequenceMethods
*)0, /* tp_as_sequence */
896 (PyMappingMethods
*)0, /* tp_as_mapping */
897 (hashfunc
) AEDesc_hash
, /*tp_hash*/
900 PyObject_GenericGetAttr
, /*tp_getattro*/
901 PyObject_GenericSetAttr
, /*tp_setattro */
903 Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
, /* tp_flags */
907 0, /*tp_richcompare*/
908 0, /*tp_weaklistoffset*/
911 AEDesc_methods
, /* tp_methods */
913 AEDesc_getsetlist
, /*tp_getset*/
919 AEDesc_tp_init
, /* tp_init */
920 AEDesc_tp_alloc
, /* tp_alloc */
921 AEDesc_tp_new
, /* tp_new */
922 AEDesc_tp_free
, /* tp_free */
925 /* --------------------- End object type AEDesc --------------------- */
928 static PyObject
*AE_AECoercePtr(PyObject
*_self
, PyObject
*_args
)
930 PyObject
*_res
= NULL
;
935 int dataPtr__in_len__
;
939 PyMac_PRECHECK(AECoercePtr
);
941 if (!PyArg_ParseTuple(_args
, "O&s#O&",
942 PyMac_GetOSType
, &typeCode
,
943 &dataPtr__in__
, &dataPtr__in_len__
,
944 PyMac_GetOSType
, &toType
))
946 dataPtr__len__
= dataPtr__in_len__
;
947 _err
= AECoercePtr(typeCode
,
948 dataPtr__in__
, dataPtr__len__
,
951 if (_err
!= noErr
) return PyMac_Error(_err
);
952 _res
= Py_BuildValue("O&",
953 AEDesc_New
, &result
);
957 static PyObject
*AE_AECreateDesc(PyObject
*_self
, PyObject
*_args
)
959 PyObject
*_res
= NULL
;
964 int dataPtr__in_len__
;
967 PyMac_PRECHECK(AECreateDesc
);
969 if (!PyArg_ParseTuple(_args
, "O&s#",
970 PyMac_GetOSType
, &typeCode
,
971 &dataPtr__in__
, &dataPtr__in_len__
))
973 dataPtr__len__
= dataPtr__in_len__
;
974 _err
= AECreateDesc(typeCode
,
975 dataPtr__in__
, dataPtr__len__
,
977 if (_err
!= noErr
) return PyMac_Error(_err
);
978 _res
= Py_BuildValue("O&",
979 AEDesc_New
, &result
);
983 static PyObject
*AE_AECreateList(PyObject
*_self
, PyObject
*_args
)
985 PyObject
*_res
= NULL
;
987 char *factoringPtr__in__
;
988 long factoringPtr__len__
;
989 int factoringPtr__in_len__
;
991 AEDescList resultList
;
993 PyMac_PRECHECK(AECreateList
);
995 if (!PyArg_ParseTuple(_args
, "s#b",
996 &factoringPtr__in__
, &factoringPtr__in_len__
,
999 factoringPtr__len__
= factoringPtr__in_len__
;
1000 _err
= AECreateList(factoringPtr__in__
, factoringPtr__len__
,
1003 if (_err
!= noErr
) return PyMac_Error(_err
);
1004 _res
= Py_BuildValue("O&",
1005 AEDesc_New
, &resultList
);
1009 static PyObject
*AE_AECreateAppleEvent(PyObject
*_self
, PyObject
*_args
)
1011 PyObject
*_res
= NULL
;
1013 AEEventClass theAEEventClass
;
1014 AEEventID theAEEventID
;
1015 AEAddressDesc target
;
1016 AEReturnID returnID
;
1017 AETransactionID transactionID
;
1019 #ifndef AECreateAppleEvent
1020 PyMac_PRECHECK(AECreateAppleEvent
);
1022 if (!PyArg_ParseTuple(_args
, "O&O&O&hl",
1023 PyMac_GetOSType
, &theAEEventClass
,
1024 PyMac_GetOSType
, &theAEEventID
,
1025 AEDesc_Convert
, &target
,
1029 _err
= AECreateAppleEvent(theAEEventClass
,
1035 if (_err
!= noErr
) return PyMac_Error(_err
);
1036 _res
= Py_BuildValue("O&",
1037 AEDesc_New
, &result
);
1041 static PyObject
*AE_AEReplaceDescData(PyObject
*_self
, PyObject
*_args
)
1043 PyObject
*_res
= NULL
;
1046 char *dataPtr__in__
;
1047 long dataPtr__len__
;
1048 int dataPtr__in_len__
;
1050 #ifndef AEReplaceDescData
1051 PyMac_PRECHECK(AEReplaceDescData
);
1053 if (!PyArg_ParseTuple(_args
, "O&s#",
1054 PyMac_GetOSType
, &typeCode
,
1055 &dataPtr__in__
, &dataPtr__in_len__
))
1057 dataPtr__len__
= dataPtr__in_len__
;
1058 _err
= AEReplaceDescData(typeCode
,
1059 dataPtr__in__
, dataPtr__len__
,
1061 if (_err
!= noErr
) return PyMac_Error(_err
);
1062 _res
= Py_BuildValue("O&",
1063 AEDesc_New
, &theAEDesc
);
1067 static PyObject
*AE_AEProcessAppleEvent(PyObject
*_self
, PyObject
*_args
)
1069 PyObject
*_res
= NULL
;
1071 EventRecord theEventRecord
;
1072 #ifndef AEProcessAppleEvent
1073 PyMac_PRECHECK(AEProcessAppleEvent
);
1075 if (!PyArg_ParseTuple(_args
, "O&",
1076 PyMac_GetEventRecord
, &theEventRecord
))
1078 _err
= AEProcessAppleEvent(&theEventRecord
);
1079 if (_err
!= noErr
) return PyMac_Error(_err
);
1085 static PyObject
*AE_AEGetInteractionAllowed(PyObject
*_self
, PyObject
*_args
)
1087 PyObject
*_res
= NULL
;
1089 AEInteractAllowed level
;
1090 #ifndef AEGetInteractionAllowed
1091 PyMac_PRECHECK(AEGetInteractionAllowed
);
1093 if (!PyArg_ParseTuple(_args
, ""))
1095 _err
= AEGetInteractionAllowed(&level
);
1096 if (_err
!= noErr
) return PyMac_Error(_err
);
1097 _res
= Py_BuildValue("b",
1102 static PyObject
*AE_AESetInteractionAllowed(PyObject
*_self
, PyObject
*_args
)
1104 PyObject
*_res
= NULL
;
1106 AEInteractAllowed level
;
1107 #ifndef AESetInteractionAllowed
1108 PyMac_PRECHECK(AESetInteractionAllowed
);
1110 if (!PyArg_ParseTuple(_args
, "b",
1113 _err
= AESetInteractionAllowed(level
);
1114 if (_err
!= noErr
) return PyMac_Error(_err
);
1120 static PyObject
*AE_AEInteractWithUser(PyObject
*_self
, PyObject
*_args
)
1122 PyObject
*_res
= NULL
;
1124 long timeOutInTicks
;
1125 #ifndef AEInteractWithUser
1126 PyMac_PRECHECK(AEInteractWithUser
);
1128 if (!PyArg_ParseTuple(_args
, "l",
1131 _err
= AEInteractWithUser(timeOutInTicks
,
1134 if (_err
!= noErr
) return PyMac_Error(_err
);
1140 static PyObject
*AE_AEInstallEventHandler(PyObject
*_self
, PyObject
*_args
)
1142 PyObject
*_res
= NULL
;
1144 AEEventClass theAEEventClass
;
1145 AEEventID theAEEventID
;
1146 AEEventHandlerUPP handler__proc__
= upp_GenericEventHandler
;
1148 #ifndef AEInstallEventHandler
1149 PyMac_PRECHECK(AEInstallEventHandler
);
1151 if (!PyArg_ParseTuple(_args
, "O&O&O",
1152 PyMac_GetOSType
, &theAEEventClass
,
1153 PyMac_GetOSType
, &theAEEventID
,
1156 _err
= AEInstallEventHandler(theAEEventClass
,
1158 handler__proc__
, (long)handler
,
1160 if (_err
!= noErr
) return PyMac_Error(_err
);
1163 Py_INCREF(handler
); /* XXX leak, but needed */
1167 static PyObject
*AE_AERemoveEventHandler(PyObject
*_self
, PyObject
*_args
)
1169 PyObject
*_res
= NULL
;
1171 AEEventClass theAEEventClass
;
1172 AEEventID theAEEventID
;
1173 #ifndef AERemoveEventHandler
1174 PyMac_PRECHECK(AERemoveEventHandler
);
1176 if (!PyArg_ParseTuple(_args
, "O&O&",
1177 PyMac_GetOSType
, &theAEEventClass
,
1178 PyMac_GetOSType
, &theAEEventID
))
1180 _err
= AERemoveEventHandler(theAEEventClass
,
1182 upp_GenericEventHandler
,
1184 if (_err
!= noErr
) return PyMac_Error(_err
);
1190 static PyObject
*AE_AEGetEventHandler(PyObject
*_self
, PyObject
*_args
)
1192 PyObject
*_res
= NULL
;
1194 AEEventClass theAEEventClass
;
1195 AEEventID theAEEventID
;
1196 AEEventHandlerUPP handler__proc__
= upp_GenericEventHandler
;
1198 #ifndef AEGetEventHandler
1199 PyMac_PRECHECK(AEGetEventHandler
);
1201 if (!PyArg_ParseTuple(_args
, "O&O&",
1202 PyMac_GetOSType
, &theAEEventClass
,
1203 PyMac_GetOSType
, &theAEEventID
))
1205 _err
= AEGetEventHandler(theAEEventClass
,
1207 &handler__proc__
, (long *)&handler
,
1209 if (_err
!= noErr
) return PyMac_Error(_err
);
1210 _res
= Py_BuildValue("O",
1212 Py_INCREF(handler
); /* XXX leak, but needed */
1216 static PyObject
*AE_AEInstallSpecialHandler(PyObject
*_self
, PyObject
*_args
)
1218 PyObject
*_res
= NULL
;
1220 AEKeyword functionClass
;
1221 #ifndef AEInstallSpecialHandler
1222 PyMac_PRECHECK(AEInstallSpecialHandler
);
1224 if (!PyArg_ParseTuple(_args
, "O&",
1225 PyMac_GetOSType
, &functionClass
))
1227 _err
= AEInstallSpecialHandler(functionClass
,
1228 upp_GenericEventHandler
,
1230 if (_err
!= noErr
) return PyMac_Error(_err
);
1236 static PyObject
*AE_AERemoveSpecialHandler(PyObject
*_self
, PyObject
*_args
)
1238 PyObject
*_res
= NULL
;
1240 AEKeyword functionClass
;
1241 #ifndef AERemoveSpecialHandler
1242 PyMac_PRECHECK(AERemoveSpecialHandler
);
1244 if (!PyArg_ParseTuple(_args
, "O&",
1245 PyMac_GetOSType
, &functionClass
))
1247 _err
= AERemoveSpecialHandler(functionClass
,
1248 upp_GenericEventHandler
,
1250 if (_err
!= noErr
) return PyMac_Error(_err
);
1256 static PyObject
*AE_AEManagerInfo(PyObject
*_self
, PyObject
*_args
)
1258 PyObject
*_res
= NULL
;
1262 #ifndef AEManagerInfo
1263 PyMac_PRECHECK(AEManagerInfo
);
1265 if (!PyArg_ParseTuple(_args
, "O&",
1266 PyMac_GetOSType
, &keyWord
))
1268 _err
= AEManagerInfo(keyWord
,
1270 if (_err
!= noErr
) return PyMac_Error(_err
);
1271 _res
= Py_BuildValue("l",
1276 static PyObject
*AE_AEObjectInit(PyObject
*_self
, PyObject
*_args
)
1278 PyObject
*_res
= NULL
;
1280 #ifndef AEObjectInit
1281 PyMac_PRECHECK(AEObjectInit
);
1283 if (!PyArg_ParseTuple(_args
, ""))
1285 _err
= AEObjectInit();
1286 if (_err
!= noErr
) return PyMac_Error(_err
);
1292 static PyObject
*AE_AEDisposeToken(PyObject
*_self
, PyObject
*_args
)
1294 PyObject
*_res
= NULL
;
1297 #ifndef AEDisposeToken
1298 PyMac_PRECHECK(AEDisposeToken
);
1300 if (!PyArg_ParseTuple(_args
, ""))
1302 _err
= AEDisposeToken(&theToken
);
1303 if (_err
!= noErr
) return PyMac_Error(_err
);
1304 _res
= Py_BuildValue("O&",
1305 AEDesc_New
, &theToken
);
1309 static PyObject
*AE_AECallObjectAccessor(PyObject
*_self
, PyObject
*_args
)
1311 PyObject
*_res
= NULL
;
1313 DescType desiredClass
;
1314 AEDesc containerToken
;
1315 DescType containerClass
;
1319 #ifndef AECallObjectAccessor
1320 PyMac_PRECHECK(AECallObjectAccessor
);
1322 if (!PyArg_ParseTuple(_args
, "O&O&O&O&O&",
1323 PyMac_GetOSType
, &desiredClass
,
1324 AEDesc_Convert
, &containerToken
,
1325 PyMac_GetOSType
, &containerClass
,
1326 PyMac_GetOSType
, &keyForm
,
1327 AEDesc_Convert
, &keyData
))
1329 _err
= AECallObjectAccessor(desiredClass
,
1335 if (_err
!= noErr
) return PyMac_Error(_err
);
1336 _res
= Py_BuildValue("O&",
1337 AEDesc_New
, &token
);
1341 static PyMethodDef AE_methods
[] = {
1342 {"AECoercePtr", (PyCFunction
)AE_AECoercePtr
, 1,
1343 PyDoc_STR("(DescType typeCode, Buffer dataPtr, DescType toType) -> (AEDesc result)")},
1344 {"AECreateDesc", (PyCFunction
)AE_AECreateDesc
, 1,
1345 PyDoc_STR("(DescType typeCode, Buffer dataPtr) -> (AEDesc result)")},
1346 {"AECreateList", (PyCFunction
)AE_AECreateList
, 1,
1347 PyDoc_STR("(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)")},
1348 {"AECreateAppleEvent", (PyCFunction
)AE_AECreateAppleEvent
, 1,
1349 PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, AEReturnID returnID, AETransactionID transactionID) -> (AppleEvent result)")},
1350 {"AEReplaceDescData", (PyCFunction
)AE_AEReplaceDescData
, 1,
1351 PyDoc_STR("(DescType typeCode, Buffer dataPtr) -> (AEDesc theAEDesc)")},
1352 {"AEProcessAppleEvent", (PyCFunction
)AE_AEProcessAppleEvent
, 1,
1353 PyDoc_STR("(EventRecord theEventRecord) -> None")},
1354 {"AEGetInteractionAllowed", (PyCFunction
)AE_AEGetInteractionAllowed
, 1,
1355 PyDoc_STR("() -> (AEInteractAllowed level)")},
1356 {"AESetInteractionAllowed", (PyCFunction
)AE_AESetInteractionAllowed
, 1,
1357 PyDoc_STR("(AEInteractAllowed level) -> None")},
1358 {"AEInteractWithUser", (PyCFunction
)AE_AEInteractWithUser
, 1,
1359 PyDoc_STR("(long timeOutInTicks) -> None")},
1360 {"AEInstallEventHandler", (PyCFunction
)AE_AEInstallEventHandler
, 1,
1361 PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID, EventHandler handler) -> None")},
1362 {"AERemoveEventHandler", (PyCFunction
)AE_AERemoveEventHandler
, 1,
1363 PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None")},
1364 {"AEGetEventHandler", (PyCFunction
)AE_AEGetEventHandler
, 1,
1365 PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID) -> (EventHandler handler)")},
1366 {"AEInstallSpecialHandler", (PyCFunction
)AE_AEInstallSpecialHandler
, 1,
1367 PyDoc_STR("(AEKeyword functionClass) -> None")},
1368 {"AERemoveSpecialHandler", (PyCFunction
)AE_AERemoveSpecialHandler
, 1,
1369 PyDoc_STR("(AEKeyword functionClass) -> None")},
1370 {"AEManagerInfo", (PyCFunction
)AE_AEManagerInfo
, 1,
1371 PyDoc_STR("(AEKeyword keyWord) -> (long result)")},
1372 {"AEObjectInit", (PyCFunction
)AE_AEObjectInit
, 1,
1373 PyDoc_STR("() -> None")},
1374 {"AEDisposeToken", (PyCFunction
)AE_AEDisposeToken
, 1,
1375 PyDoc_STR("() -> (AEDesc theToken)")},
1376 {"AECallObjectAccessor", (PyCFunction
)AE_AECallObjectAccessor
, 1,
1377 PyDoc_STR("(DescType desiredClass, AEDesc containerToken, DescType containerClass, DescType keyForm, AEDesc keyData) -> (AEDesc token)")},
1384 GenericEventHandler(const AppleEvent
*request
, AppleEvent
*reply
, refcontype refcon
)
1386 PyObject
*handler
= (PyObject
*)refcon
;
1387 AEDescObject
*requestObject
, *replyObject
;
1388 PyObject
*args
, *res
;
1389 if ((requestObject
= (AEDescObject
*)AEDesc_New((AppleEvent
*)request
)) == NULL
) {
1392 if ((replyObject
= (AEDescObject
*)AEDesc_New(reply
)) == NULL
) {
1393 Py_DECREF(requestObject
);
1396 if ((args
= Py_BuildValue("OO", requestObject
, replyObject
)) == NULL
) {
1397 Py_DECREF(requestObject
);
1398 Py_DECREF(replyObject
);
1401 res
= PyEval_CallObject(handler
, args
);
1402 requestObject
->ob_itself
.descriptorType
= 'null';
1403 requestObject
->ob_itself
.dataHandle
= NULL
;
1404 replyObject
->ob_itself
.descriptorType
= 'null';
1405 replyObject
->ob_itself
.dataHandle
= NULL
;
1408 PySys_WriteStderr("Exception in AE event handler function\n");
1424 upp_AEIdleProc
= NewAEIdleUPP(AEIdleProc
);
1425 upp_GenericEventHandler
= NewAEEventHandlerUPP(GenericEventHandler
);
1426 PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc
*, AEDesc_New
);
1427 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc
, AEDesc_Convert
);
1430 m
= Py_InitModule("_AE", AE_methods
);
1431 d
= PyModule_GetDict(m
);
1432 AE_Error
= PyMac_GetOSErrException();
1433 if (AE_Error
== NULL
||
1434 PyDict_SetItemString(d
, "Error", AE_Error
) != 0)
1436 AEDesc_Type
.ob_type
= &PyType_Type
;
1437 if (PyType_Ready(&AEDesc_Type
) < 0) return;
1438 Py_INCREF(&AEDesc_Type
);
1439 PyModule_AddObject(m
, "AEDesc", (PyObject
*)&AEDesc_Type
);
1440 /* Backward-compatible name */
1441 Py_INCREF(&AEDesc_Type
);
1442 PyModule_AddObject(m
, "AEDescType", (PyObject
*)&AEDesc_Type
);
1445 /* ========================= End module _AE ========================= */