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"); \
23 #ifdef WITHOUT_FRAMEWORKS
24 #include <AppleEvents.h>
25 #include <AEObjects.h>
27 #include <Carbon/Carbon.h>
30 #ifdef USE_TOOLBOX_OBJECT_GLUE
31 extern PyObject
*_AEDesc_New(AEDesc
*);
32 extern int _AEDesc_Convert(PyObject
*, AEDesc
*);
34 #define AEDesc_New _AEDesc_New
35 #define AEDesc_Convert _AEDesc_Convert
38 static pascal OSErr
GenericEventHandler(); /* Forward */
40 AEEventHandlerUPP upp_GenericEventHandler
;
42 static pascal Boolean
AEIdleProc(EventRecord
*theEvent
, long *sleepTime
, RgnHandle
*mouseRgn
)
44 if ( PyOS_InterruptOccurred() )
46 #if !TARGET_API_MAC_OSX
47 if ( PyMac_HandleEvent(theEvent
) < 0 ) {
48 PySys_WriteStderr("Exception in user event handler during AE processing\n");
55 AEIdleUPP upp_AEIdleProc
;
57 static PyObject
*AE_Error
;
59 /* ----------------------- Object type AEDesc ----------------------- */
61 PyTypeObject AEDesc_Type
;
63 #define AEDesc_Check(x) ((x)->ob_type == &AEDesc_Type)
65 typedef struct AEDescObject
{
70 PyObject
*AEDesc_New(AEDesc
*itself
)
73 it
= PyObject_NEW(AEDescObject
, &AEDesc_Type
);
74 if (it
== NULL
) return NULL
;
75 it
->ob_itself
= *itself
;
76 return (PyObject
*)it
;
78 int AEDesc_Convert(PyObject
*v
, AEDesc
*p_itself
)
82 PyErr_SetString(PyExc_TypeError
, "AEDesc required");
85 *p_itself
= ((AEDescObject
*)v
)->ob_itself
;
89 static void AEDesc_dealloc(AEDescObject
*self
)
91 AEDisposeDesc(&self
->ob_itself
);
95 static PyObject
*AEDesc_AECoerceDesc(AEDescObject
*_self
, PyObject
*_args
)
97 PyObject
*_res
= NULL
;
102 PyMac_PRECHECK(AECoerceDesc
);
104 if (!PyArg_ParseTuple(_args
, "O&",
105 PyMac_GetOSType
, &toType
))
107 _err
= AECoerceDesc(&_self
->ob_itself
,
110 if (_err
!= noErr
) return PyMac_Error(_err
);
111 _res
= Py_BuildValue("O&",
112 AEDesc_New
, &result
);
116 static PyObject
*AEDesc_AEDuplicateDesc(AEDescObject
*_self
, PyObject
*_args
)
118 PyObject
*_res
= NULL
;
121 #ifndef AEDuplicateDesc
122 PyMac_PRECHECK(AEDuplicateDesc
);
124 if (!PyArg_ParseTuple(_args
, ""))
126 _err
= AEDuplicateDesc(&_self
->ob_itself
,
128 if (_err
!= noErr
) return PyMac_Error(_err
);
129 _res
= Py_BuildValue("O&",
130 AEDesc_New
, &result
);
134 static PyObject
*AEDesc_AECountItems(AEDescObject
*_self
, PyObject
*_args
)
136 PyObject
*_res
= NULL
;
140 PyMac_PRECHECK(AECountItems
);
142 if (!PyArg_ParseTuple(_args
, ""))
144 _err
= AECountItems(&_self
->ob_itself
,
146 if (_err
!= noErr
) return PyMac_Error(_err
);
147 _res
= Py_BuildValue("l",
152 static PyObject
*AEDesc_AEPutPtr(AEDescObject
*_self
, PyObject
*_args
)
154 PyObject
*_res
= NULL
;
160 int dataPtr__in_len__
;
162 PyMac_PRECHECK(AEPutPtr
);
164 if (!PyArg_ParseTuple(_args
, "lO&s#",
166 PyMac_GetOSType
, &typeCode
,
167 &dataPtr__in__
, &dataPtr__in_len__
))
169 dataPtr__len__
= dataPtr__in_len__
;
170 _err
= AEPutPtr(&_self
->ob_itself
,
173 dataPtr__in__
, dataPtr__len__
);
174 if (_err
!= noErr
) return PyMac_Error(_err
);
180 static PyObject
*AEDesc_AEPutDesc(AEDescObject
*_self
, PyObject
*_args
)
182 PyObject
*_res
= NULL
;
187 PyMac_PRECHECK(AEPutDesc
);
189 if (!PyArg_ParseTuple(_args
, "lO&",
191 AEDesc_Convert
, &theAEDesc
))
193 _err
= AEPutDesc(&_self
->ob_itself
,
196 if (_err
!= noErr
) return PyMac_Error(_err
);
202 static PyObject
*AEDesc_AEGetNthPtr(AEDescObject
*_self
, PyObject
*_args
)
204 PyObject
*_res
= NULL
;
207 DescType desiredType
;
208 AEKeyword theAEKeyword
;
210 char *dataPtr__out__
;
212 int dataPtr__in_len__
;
214 PyMac_PRECHECK(AEGetNthPtr
);
216 if (!PyArg_ParseTuple(_args
, "lO&i",
218 PyMac_GetOSType
, &desiredType
,
221 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
224 goto dataPtr__error__
;
226 dataPtr__len__
= dataPtr__in_len__
;
227 _err
= AEGetNthPtr(&_self
->ob_itself
,
232 dataPtr__out__
, dataPtr__len__
, &dataPtr__len__
);
233 if (_err
!= noErr
) return PyMac_Error(_err
);
234 _res
= Py_BuildValue("O&O&s#",
235 PyMac_BuildOSType
, theAEKeyword
,
236 PyMac_BuildOSType
, typeCode
,
237 dataPtr__out__
, (int)dataPtr__len__
);
238 free(dataPtr__out__
);
243 static PyObject
*AEDesc_AEGetNthDesc(AEDescObject
*_self
, PyObject
*_args
)
245 PyObject
*_res
= NULL
;
248 DescType desiredType
;
249 AEKeyword theAEKeyword
;
252 PyMac_PRECHECK(AEGetNthDesc
);
254 if (!PyArg_ParseTuple(_args
, "lO&",
256 PyMac_GetOSType
, &desiredType
))
258 _err
= AEGetNthDesc(&_self
->ob_itself
,
263 if (_err
!= noErr
) return PyMac_Error(_err
);
264 _res
= Py_BuildValue("O&O&",
265 PyMac_BuildOSType
, theAEKeyword
,
266 AEDesc_New
, &result
);
270 static PyObject
*AEDesc_AESizeOfNthItem(AEDescObject
*_self
, PyObject
*_args
)
272 PyObject
*_res
= NULL
;
277 #ifndef AESizeOfNthItem
278 PyMac_PRECHECK(AESizeOfNthItem
);
280 if (!PyArg_ParseTuple(_args
, "l",
283 _err
= AESizeOfNthItem(&_self
->ob_itself
,
287 if (_err
!= noErr
) return PyMac_Error(_err
);
288 _res
= Py_BuildValue("O&l",
289 PyMac_BuildOSType
, typeCode
,
294 static PyObject
*AEDesc_AEDeleteItem(AEDescObject
*_self
, PyObject
*_args
)
296 PyObject
*_res
= NULL
;
300 PyMac_PRECHECK(AEDeleteItem
);
302 if (!PyArg_ParseTuple(_args
, "l",
305 _err
= AEDeleteItem(&_self
->ob_itself
,
307 if (_err
!= noErr
) return PyMac_Error(_err
);
313 static PyObject
*AEDesc_AEPutParamPtr(AEDescObject
*_self
, PyObject
*_args
)
315 PyObject
*_res
= NULL
;
317 AEKeyword theAEKeyword
;
321 int dataPtr__in_len__
;
322 #ifndef AEPutParamPtr
323 PyMac_PRECHECK(AEPutParamPtr
);
325 if (!PyArg_ParseTuple(_args
, "O&O&s#",
326 PyMac_GetOSType
, &theAEKeyword
,
327 PyMac_GetOSType
, &typeCode
,
328 &dataPtr__in__
, &dataPtr__in_len__
))
330 dataPtr__len__
= dataPtr__in_len__
;
331 _err
= AEPutParamPtr(&_self
->ob_itself
,
334 dataPtr__in__
, dataPtr__len__
);
335 if (_err
!= noErr
) return PyMac_Error(_err
);
341 static PyObject
*AEDesc_AEPutParamDesc(AEDescObject
*_self
, PyObject
*_args
)
343 PyObject
*_res
= NULL
;
345 AEKeyword theAEKeyword
;
347 #ifndef AEPutParamDesc
348 PyMac_PRECHECK(AEPutParamDesc
);
350 if (!PyArg_ParseTuple(_args
, "O&O&",
351 PyMac_GetOSType
, &theAEKeyword
,
352 AEDesc_Convert
, &theAEDesc
))
354 _err
= AEPutParamDesc(&_self
->ob_itself
,
357 if (_err
!= noErr
) return PyMac_Error(_err
);
363 static PyObject
*AEDesc_AEGetParamPtr(AEDescObject
*_self
, PyObject
*_args
)
365 PyObject
*_res
= NULL
;
367 AEKeyword theAEKeyword
;
368 DescType desiredType
;
370 char *dataPtr__out__
;
372 int dataPtr__in_len__
;
373 #ifndef AEGetParamPtr
374 PyMac_PRECHECK(AEGetParamPtr
);
376 if (!PyArg_ParseTuple(_args
, "O&O&i",
377 PyMac_GetOSType
, &theAEKeyword
,
378 PyMac_GetOSType
, &desiredType
,
381 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
384 goto dataPtr__error__
;
386 dataPtr__len__
= dataPtr__in_len__
;
387 _err
= AEGetParamPtr(&_self
->ob_itself
,
391 dataPtr__out__
, dataPtr__len__
, &dataPtr__len__
);
392 if (_err
!= noErr
) return PyMac_Error(_err
);
393 _res
= Py_BuildValue("O&s#",
394 PyMac_BuildOSType
, typeCode
,
395 dataPtr__out__
, (int)dataPtr__len__
);
396 free(dataPtr__out__
);
401 static PyObject
*AEDesc_AEGetParamDesc(AEDescObject
*_self
, PyObject
*_args
)
403 PyObject
*_res
= NULL
;
405 AEKeyword theAEKeyword
;
406 DescType desiredType
;
408 #ifndef AEGetParamDesc
409 PyMac_PRECHECK(AEGetParamDesc
);
411 if (!PyArg_ParseTuple(_args
, "O&O&",
412 PyMac_GetOSType
, &theAEKeyword
,
413 PyMac_GetOSType
, &desiredType
))
415 _err
= AEGetParamDesc(&_self
->ob_itself
,
419 if (_err
!= noErr
) return PyMac_Error(_err
);
420 _res
= Py_BuildValue("O&",
421 AEDesc_New
, &result
);
425 static PyObject
*AEDesc_AESizeOfParam(AEDescObject
*_self
, PyObject
*_args
)
427 PyObject
*_res
= NULL
;
429 AEKeyword theAEKeyword
;
432 #ifndef AESizeOfParam
433 PyMac_PRECHECK(AESizeOfParam
);
435 if (!PyArg_ParseTuple(_args
, "O&",
436 PyMac_GetOSType
, &theAEKeyword
))
438 _err
= AESizeOfParam(&_self
->ob_itself
,
442 if (_err
!= noErr
) return PyMac_Error(_err
);
443 _res
= Py_BuildValue("O&l",
444 PyMac_BuildOSType
, typeCode
,
449 static PyObject
*AEDesc_AEDeleteParam(AEDescObject
*_self
, PyObject
*_args
)
451 PyObject
*_res
= NULL
;
453 AEKeyword theAEKeyword
;
454 #ifndef AEDeleteParam
455 PyMac_PRECHECK(AEDeleteParam
);
457 if (!PyArg_ParseTuple(_args
, "O&",
458 PyMac_GetOSType
, &theAEKeyword
))
460 _err
= AEDeleteParam(&_self
->ob_itself
,
462 if (_err
!= noErr
) return PyMac_Error(_err
);
468 static PyObject
*AEDesc_AEGetAttributePtr(AEDescObject
*_self
, PyObject
*_args
)
470 PyObject
*_res
= NULL
;
472 AEKeyword theAEKeyword
;
473 DescType desiredType
;
475 char *dataPtr__out__
;
477 int dataPtr__in_len__
;
478 #ifndef AEGetAttributePtr
479 PyMac_PRECHECK(AEGetAttributePtr
);
481 if (!PyArg_ParseTuple(_args
, "O&O&i",
482 PyMac_GetOSType
, &theAEKeyword
,
483 PyMac_GetOSType
, &desiredType
,
486 if ((dataPtr__out__
= malloc(dataPtr__in_len__
)) == NULL
)
489 goto dataPtr__error__
;
491 dataPtr__len__
= dataPtr__in_len__
;
492 _err
= AEGetAttributePtr(&_self
->ob_itself
,
496 dataPtr__out__
, dataPtr__len__
, &dataPtr__len__
);
497 if (_err
!= noErr
) return PyMac_Error(_err
);
498 _res
= Py_BuildValue("O&s#",
499 PyMac_BuildOSType
, typeCode
,
500 dataPtr__out__
, (int)dataPtr__len__
);
501 free(dataPtr__out__
);
506 static PyObject
*AEDesc_AEGetAttributeDesc(AEDescObject
*_self
, PyObject
*_args
)
508 PyObject
*_res
= NULL
;
510 AEKeyword theAEKeyword
;
511 DescType desiredType
;
513 #ifndef AEGetAttributeDesc
514 PyMac_PRECHECK(AEGetAttributeDesc
);
516 if (!PyArg_ParseTuple(_args
, "O&O&",
517 PyMac_GetOSType
, &theAEKeyword
,
518 PyMac_GetOSType
, &desiredType
))
520 _err
= AEGetAttributeDesc(&_self
->ob_itself
,
524 if (_err
!= noErr
) return PyMac_Error(_err
);
525 _res
= Py_BuildValue("O&",
526 AEDesc_New
, &result
);
530 static PyObject
*AEDesc_AESizeOfAttribute(AEDescObject
*_self
, PyObject
*_args
)
532 PyObject
*_res
= NULL
;
534 AEKeyword theAEKeyword
;
537 #ifndef AESizeOfAttribute
538 PyMac_PRECHECK(AESizeOfAttribute
);
540 if (!PyArg_ParseTuple(_args
, "O&",
541 PyMac_GetOSType
, &theAEKeyword
))
543 _err
= AESizeOfAttribute(&_self
->ob_itself
,
547 if (_err
!= noErr
) return PyMac_Error(_err
);
548 _res
= Py_BuildValue("O&l",
549 PyMac_BuildOSType
, typeCode
,
554 static PyObject
*AEDesc_AEPutAttributePtr(AEDescObject
*_self
, PyObject
*_args
)
556 PyObject
*_res
= NULL
;
558 AEKeyword theAEKeyword
;
562 int dataPtr__in_len__
;
563 #ifndef AEPutAttributePtr
564 PyMac_PRECHECK(AEPutAttributePtr
);
566 if (!PyArg_ParseTuple(_args
, "O&O&s#",
567 PyMac_GetOSType
, &theAEKeyword
,
568 PyMac_GetOSType
, &typeCode
,
569 &dataPtr__in__
, &dataPtr__in_len__
))
571 dataPtr__len__
= dataPtr__in_len__
;
572 _err
= AEPutAttributePtr(&_self
->ob_itself
,
575 dataPtr__in__
, dataPtr__len__
);
576 if (_err
!= noErr
) return PyMac_Error(_err
);
582 static PyObject
*AEDesc_AEPutAttributeDesc(AEDescObject
*_self
, PyObject
*_args
)
584 PyObject
*_res
= NULL
;
586 AEKeyword theAEKeyword
;
588 #ifndef AEPutAttributeDesc
589 PyMac_PRECHECK(AEPutAttributeDesc
);
591 if (!PyArg_ParseTuple(_args
, "O&O&",
592 PyMac_GetOSType
, &theAEKeyword
,
593 AEDesc_Convert
, &theAEDesc
))
595 _err
= AEPutAttributeDesc(&_self
->ob_itself
,
598 if (_err
!= noErr
) return PyMac_Error(_err
);
604 #if TARGET_API_MAC_CARBON
606 static PyObject
*AEDesc_AEGetDescDataSize(AEDescObject
*_self
, PyObject
*_args
)
608 PyObject
*_res
= NULL
;
610 #ifndef AEGetDescDataSize
611 PyMac_PRECHECK(AEGetDescDataSize
);
613 if (!PyArg_ParseTuple(_args
, ""))
615 _rv
= AEGetDescDataSize(&_self
->ob_itself
);
616 _res
= Py_BuildValue("l",
622 static PyObject
*AEDesc_AESend(AEDescObject
*_self
, PyObject
*_args
)
624 PyObject
*_res
= NULL
;
628 AESendPriority sendPriority
;
631 PyMac_PRECHECK(AESend
);
633 if (!PyArg_ParseTuple(_args
, "lhl",
638 _err
= AESend(&_self
->ob_itself
,
645 if (_err
!= noErr
) return PyMac_Error(_err
);
646 _res
= Py_BuildValue("O&",
651 static PyObject
*AEDesc_AEResetTimer(AEDescObject
*_self
, PyObject
*_args
)
653 PyObject
*_res
= NULL
;
656 PyMac_PRECHECK(AEResetTimer
);
658 if (!PyArg_ParseTuple(_args
, ""))
660 _err
= AEResetTimer(&_self
->ob_itself
);
661 if (_err
!= noErr
) return PyMac_Error(_err
);
667 static PyObject
*AEDesc_AESuspendTheCurrentEvent(AEDescObject
*_self
, PyObject
*_args
)
669 PyObject
*_res
= NULL
;
671 #ifndef AESuspendTheCurrentEvent
672 PyMac_PRECHECK(AESuspendTheCurrentEvent
);
674 if (!PyArg_ParseTuple(_args
, ""))
676 _err
= AESuspendTheCurrentEvent(&_self
->ob_itself
);
677 if (_err
!= noErr
) return PyMac_Error(_err
);
683 static PyObject
*AEDesc_AEResumeTheCurrentEvent(AEDescObject
*_self
, PyObject
*_args
)
685 PyObject
*_res
= NULL
;
688 AEEventHandlerUPP dispatcher__proc__
= upp_GenericEventHandler
;
689 PyObject
*dispatcher
;
690 #ifndef AEResumeTheCurrentEvent
691 PyMac_PRECHECK(AEResumeTheCurrentEvent
);
693 if (!PyArg_ParseTuple(_args
, "O&O",
694 AEDesc_Convert
, &reply
,
697 _err
= AEResumeTheCurrentEvent(&_self
->ob_itself
,
699 dispatcher__proc__
, (long)dispatcher
);
700 if (_err
!= noErr
) return PyMac_Error(_err
);
703 Py_INCREF(dispatcher
); /* XXX leak, but needed */
707 static PyObject
*AEDesc_AEGetTheCurrentEvent(AEDescObject
*_self
, PyObject
*_args
)
709 PyObject
*_res
= NULL
;
711 #ifndef AEGetTheCurrentEvent
712 PyMac_PRECHECK(AEGetTheCurrentEvent
);
714 if (!PyArg_ParseTuple(_args
, ""))
716 _err
= AEGetTheCurrentEvent(&_self
->ob_itself
);
717 if (_err
!= noErr
) return PyMac_Error(_err
);
723 static PyObject
*AEDesc_AESetTheCurrentEvent(AEDescObject
*_self
, PyObject
*_args
)
725 PyObject
*_res
= NULL
;
727 #ifndef AESetTheCurrentEvent
728 PyMac_PRECHECK(AESetTheCurrentEvent
);
730 if (!PyArg_ParseTuple(_args
, ""))
732 _err
= AESetTheCurrentEvent(&_self
->ob_itself
);
733 if (_err
!= noErr
) return PyMac_Error(_err
);
739 static PyObject
*AEDesc_AEResolve(AEDescObject
*_self
, PyObject
*_args
)
741 PyObject
*_res
= NULL
;
746 PyMac_PRECHECK(AEResolve
);
748 if (!PyArg_ParseTuple(_args
, "h",
751 _err
= AEResolve(&_self
->ob_itself
,
754 if (_err
!= noErr
) return PyMac_Error(_err
);
755 _res
= Py_BuildValue("O&",
756 AEDesc_New
, &theToken
);
760 static PyMethodDef AEDesc_methods
[] = {
761 {"AECoerceDesc", (PyCFunction
)AEDesc_AECoerceDesc
, 1,
762 "(DescType toType) -> (AEDesc result)"},
763 {"AEDuplicateDesc", (PyCFunction
)AEDesc_AEDuplicateDesc
, 1,
764 "() -> (AEDesc result)"},
765 {"AECountItems", (PyCFunction
)AEDesc_AECountItems
, 1,
766 "() -> (long theCount)"},
767 {"AEPutPtr", (PyCFunction
)AEDesc_AEPutPtr
, 1,
768 "(long index, DescType typeCode, Buffer dataPtr) -> None"},
769 {"AEPutDesc", (PyCFunction
)AEDesc_AEPutDesc
, 1,
770 "(long index, AEDesc theAEDesc) -> None"},
771 {"AEGetNthPtr", (PyCFunction
)AEDesc_AEGetNthPtr
, 1,
772 "(long index, DescType desiredType, Buffer dataPtr) -> (AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr)"},
773 {"AEGetNthDesc", (PyCFunction
)AEDesc_AEGetNthDesc
, 1,
774 "(long index, DescType desiredType) -> (AEKeyword theAEKeyword, AEDesc result)"},
775 {"AESizeOfNthItem", (PyCFunction
)AEDesc_AESizeOfNthItem
, 1,
776 "(long index) -> (DescType typeCode, Size dataSize)"},
777 {"AEDeleteItem", (PyCFunction
)AEDesc_AEDeleteItem
, 1,
778 "(long index) -> None"},
779 {"AEPutParamPtr", (PyCFunction
)AEDesc_AEPutParamPtr
, 1,
780 "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"},
781 {"AEPutParamDesc", (PyCFunction
)AEDesc_AEPutParamDesc
, 1,
782 "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"},
783 {"AEGetParamPtr", (PyCFunction
)AEDesc_AEGetParamPtr
, 1,
784 "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"},
785 {"AEGetParamDesc", (PyCFunction
)AEDesc_AEGetParamDesc
, 1,
786 "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"},
787 {"AESizeOfParam", (PyCFunction
)AEDesc_AESizeOfParam
, 1,
788 "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"},
789 {"AEDeleteParam", (PyCFunction
)AEDesc_AEDeleteParam
, 1,
790 "(AEKeyword theAEKeyword) -> None"},
791 {"AEGetAttributePtr", (PyCFunction
)AEDesc_AEGetAttributePtr
, 1,
792 "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"},
793 {"AEGetAttributeDesc", (PyCFunction
)AEDesc_AEGetAttributeDesc
, 1,
794 "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"},
795 {"AESizeOfAttribute", (PyCFunction
)AEDesc_AESizeOfAttribute
, 1,
796 "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"},
797 {"AEPutAttributePtr", (PyCFunction
)AEDesc_AEPutAttributePtr
, 1,
798 "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"},
799 {"AEPutAttributeDesc", (PyCFunction
)AEDesc_AEPutAttributeDesc
, 1,
800 "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"},
802 #if TARGET_API_MAC_CARBON
803 {"AEGetDescDataSize", (PyCFunction
)AEDesc_AEGetDescDataSize
, 1,
806 {"AESend", (PyCFunction
)AEDesc_AESend
, 1,
807 "(AESendMode sendMode, AESendPriority sendPriority, long timeOutInTicks) -> (AppleEvent reply)"},
808 {"AEResetTimer", (PyCFunction
)AEDesc_AEResetTimer
, 1,
810 {"AESuspendTheCurrentEvent", (PyCFunction
)AEDesc_AESuspendTheCurrentEvent
, 1,
812 {"AEResumeTheCurrentEvent", (PyCFunction
)AEDesc_AEResumeTheCurrentEvent
, 1,
813 "(AppleEvent reply, EventHandler dispatcher) -> None"},
814 {"AEGetTheCurrentEvent", (PyCFunction
)AEDesc_AEGetTheCurrentEvent
, 1,
816 {"AESetTheCurrentEvent", (PyCFunction
)AEDesc_AESetTheCurrentEvent
, 1,
818 {"AEResolve", (PyCFunction
)AEDesc_AEResolve
, 1,
819 "(short callbackFlags) -> (AEDesc theToken)"},
823 PyMethodChain AEDesc_chain
= { AEDesc_methods
, NULL
};
825 static PyObject
*AEDesc_getattr(AEDescObject
*self
, char *name
)
828 if (strcmp(name
, "type") == 0)
829 return PyMac_BuildOSType(self
->ob_itself
.descriptorType
);
830 if (strcmp(name
, "data") == 0) {
832 #if !TARGET_API_MAC_CARBON
834 state
= HGetState(self
->ob_itself
.dataHandle
);
835 HLock(self
->ob_itself
.dataHandle
);
836 res
= PyString_FromStringAndSize(
837 *self
->ob_itself
.dataHandle
,
838 GetHandleSize(self
->ob_itself
.dataHandle
));
839 HUnlock(self
->ob_itself
.dataHandle
);
840 HSetState(self
->ob_itself
.dataHandle
, state
);
846 size
= AEGetDescDataSize(&self
->ob_itself
);
847 if ( (res
= PyString_FromStringAndSize(NULL
, size
)) == NULL
)
849 if ( (ptr
= PyString_AsString(res
)) == NULL
)
851 if ( (err
=AEGetDescData(&self
->ob_itself
, ptr
, size
)) < 0 )
852 return PyMac_Error(err
);
856 if (strcmp(name
, "__members__") == 0)
857 return Py_BuildValue("[ss]", "data", "type");
859 return Py_FindMethodInChain(&AEDesc_chain
, (PyObject
*)self
, name
);
862 #define AEDesc_setattr NULL
864 #define AEDesc_compare NULL
866 #define AEDesc_repr NULL
868 #define AEDesc_hash NULL
870 PyTypeObject AEDesc_Type
= {
871 PyObject_HEAD_INIT(NULL
)
873 "_AE.AEDesc", /*tp_name*/
874 sizeof(AEDescObject
), /*tp_basicsize*/
877 (destructor
) AEDesc_dealloc
, /*tp_dealloc*/
879 (getattrfunc
) AEDesc_getattr
, /*tp_getattr*/
880 (setattrfunc
) AEDesc_setattr
, /*tp_setattr*/
881 (cmpfunc
) AEDesc_compare
, /*tp_compare*/
882 (reprfunc
) AEDesc_repr
, /*tp_repr*/
883 (PyNumberMethods
*)0, /* tp_as_number */
884 (PySequenceMethods
*)0, /* tp_as_sequence */
885 (PyMappingMethods
*)0, /* tp_as_mapping */
886 (hashfunc
) AEDesc_hash
, /*tp_hash*/
889 /* --------------------- End object type AEDesc --------------------- */
892 static PyObject
*AE_AECoercePtr(PyObject
*_self
, PyObject
*_args
)
894 PyObject
*_res
= NULL
;
899 int dataPtr__in_len__
;
903 PyMac_PRECHECK(AECoercePtr
);
905 if (!PyArg_ParseTuple(_args
, "O&s#O&",
906 PyMac_GetOSType
, &typeCode
,
907 &dataPtr__in__
, &dataPtr__in_len__
,
908 PyMac_GetOSType
, &toType
))
910 dataPtr__len__
= dataPtr__in_len__
;
911 _err
= AECoercePtr(typeCode
,
912 dataPtr__in__
, dataPtr__len__
,
915 if (_err
!= noErr
) return PyMac_Error(_err
);
916 _res
= Py_BuildValue("O&",
917 AEDesc_New
, &result
);
921 static PyObject
*AE_AECreateDesc(PyObject
*_self
, PyObject
*_args
)
923 PyObject
*_res
= NULL
;
928 int dataPtr__in_len__
;
931 PyMac_PRECHECK(AECreateDesc
);
933 if (!PyArg_ParseTuple(_args
, "O&s#",
934 PyMac_GetOSType
, &typeCode
,
935 &dataPtr__in__
, &dataPtr__in_len__
))
937 dataPtr__len__
= dataPtr__in_len__
;
938 _err
= AECreateDesc(typeCode
,
939 dataPtr__in__
, dataPtr__len__
,
941 if (_err
!= noErr
) return PyMac_Error(_err
);
942 _res
= Py_BuildValue("O&",
943 AEDesc_New
, &result
);
947 static PyObject
*AE_AECreateList(PyObject
*_self
, PyObject
*_args
)
949 PyObject
*_res
= NULL
;
951 char *factoringPtr__in__
;
952 long factoringPtr__len__
;
953 int factoringPtr__in_len__
;
955 AEDescList resultList
;
957 PyMac_PRECHECK(AECreateList
);
959 if (!PyArg_ParseTuple(_args
, "s#b",
960 &factoringPtr__in__
, &factoringPtr__in_len__
,
963 factoringPtr__len__
= factoringPtr__in_len__
;
964 _err
= AECreateList(factoringPtr__in__
, factoringPtr__len__
,
967 if (_err
!= noErr
) return PyMac_Error(_err
);
968 _res
= Py_BuildValue("O&",
969 AEDesc_New
, &resultList
);
973 static PyObject
*AE_AECreateAppleEvent(PyObject
*_self
, PyObject
*_args
)
975 PyObject
*_res
= NULL
;
977 AEEventClass theAEEventClass
;
978 AEEventID theAEEventID
;
979 AEAddressDesc target
;
981 AETransactionID transactionID
;
983 #ifndef AECreateAppleEvent
984 PyMac_PRECHECK(AECreateAppleEvent
);
986 if (!PyArg_ParseTuple(_args
, "O&O&O&hl",
987 PyMac_GetOSType
, &theAEEventClass
,
988 PyMac_GetOSType
, &theAEEventID
,
989 AEDesc_Convert
, &target
,
993 _err
= AECreateAppleEvent(theAEEventClass
,
999 if (_err
!= noErr
) return PyMac_Error(_err
);
1000 _res
= Py_BuildValue("O&",
1001 AEDesc_New
, &result
);
1005 #if TARGET_API_MAC_CARBON
1007 static PyObject
*AE_AEReplaceDescData(PyObject
*_self
, PyObject
*_args
)
1009 PyObject
*_res
= NULL
;
1012 char *dataPtr__in__
;
1013 long dataPtr__len__
;
1014 int dataPtr__in_len__
;
1016 #ifndef AEReplaceDescData
1017 PyMac_PRECHECK(AEReplaceDescData
);
1019 if (!PyArg_ParseTuple(_args
, "O&s#",
1020 PyMac_GetOSType
, &typeCode
,
1021 &dataPtr__in__
, &dataPtr__in_len__
))
1023 dataPtr__len__
= dataPtr__in_len__
;
1024 _err
= AEReplaceDescData(typeCode
,
1025 dataPtr__in__
, dataPtr__len__
,
1027 if (_err
!= noErr
) return PyMac_Error(_err
);
1028 _res
= Py_BuildValue("O&",
1029 AEDesc_New
, &theAEDesc
);
1034 static PyObject
*AE_AEProcessAppleEvent(PyObject
*_self
, PyObject
*_args
)
1036 PyObject
*_res
= NULL
;
1038 EventRecord theEventRecord
;
1039 #ifndef AEProcessAppleEvent
1040 PyMac_PRECHECK(AEProcessAppleEvent
);
1042 if (!PyArg_ParseTuple(_args
, "O&",
1043 PyMac_GetEventRecord
, &theEventRecord
))
1045 _err
= AEProcessAppleEvent(&theEventRecord
);
1046 if (_err
!= noErr
) return PyMac_Error(_err
);
1052 static PyObject
*AE_AEGetInteractionAllowed(PyObject
*_self
, PyObject
*_args
)
1054 PyObject
*_res
= NULL
;
1056 AEInteractAllowed level
;
1057 #ifndef AEGetInteractionAllowed
1058 PyMac_PRECHECK(AEGetInteractionAllowed
);
1060 if (!PyArg_ParseTuple(_args
, ""))
1062 _err
= AEGetInteractionAllowed(&level
);
1063 if (_err
!= noErr
) return PyMac_Error(_err
);
1064 _res
= Py_BuildValue("b",
1069 static PyObject
*AE_AESetInteractionAllowed(PyObject
*_self
, PyObject
*_args
)
1071 PyObject
*_res
= NULL
;
1073 AEInteractAllowed level
;
1074 #ifndef AESetInteractionAllowed
1075 PyMac_PRECHECK(AESetInteractionAllowed
);
1077 if (!PyArg_ParseTuple(_args
, "b",
1080 _err
= AESetInteractionAllowed(level
);
1081 if (_err
!= noErr
) return PyMac_Error(_err
);
1087 static PyObject
*AE_AEInteractWithUser(PyObject
*_self
, PyObject
*_args
)
1089 PyObject
*_res
= NULL
;
1091 long timeOutInTicks
;
1092 #ifndef AEInteractWithUser
1093 PyMac_PRECHECK(AEInteractWithUser
);
1095 if (!PyArg_ParseTuple(_args
, "l",
1098 _err
= AEInteractWithUser(timeOutInTicks
,
1101 if (_err
!= noErr
) return PyMac_Error(_err
);
1107 static PyObject
*AE_AEInstallEventHandler(PyObject
*_self
, PyObject
*_args
)
1109 PyObject
*_res
= NULL
;
1111 AEEventClass theAEEventClass
;
1112 AEEventID theAEEventID
;
1113 AEEventHandlerUPP handler__proc__
= upp_GenericEventHandler
;
1115 #ifndef AEInstallEventHandler
1116 PyMac_PRECHECK(AEInstallEventHandler
);
1118 if (!PyArg_ParseTuple(_args
, "O&O&O",
1119 PyMac_GetOSType
, &theAEEventClass
,
1120 PyMac_GetOSType
, &theAEEventID
,
1123 _err
= AEInstallEventHandler(theAEEventClass
,
1125 handler__proc__
, (long)handler
,
1127 if (_err
!= noErr
) return PyMac_Error(_err
);
1130 Py_INCREF(handler
); /* XXX leak, but needed */
1134 static PyObject
*AE_AERemoveEventHandler(PyObject
*_self
, PyObject
*_args
)
1136 PyObject
*_res
= NULL
;
1138 AEEventClass theAEEventClass
;
1139 AEEventID theAEEventID
;
1140 #ifndef AERemoveEventHandler
1141 PyMac_PRECHECK(AERemoveEventHandler
);
1143 if (!PyArg_ParseTuple(_args
, "O&O&",
1144 PyMac_GetOSType
, &theAEEventClass
,
1145 PyMac_GetOSType
, &theAEEventID
))
1147 _err
= AERemoveEventHandler(theAEEventClass
,
1149 upp_GenericEventHandler
,
1151 if (_err
!= noErr
) return PyMac_Error(_err
);
1157 static PyObject
*AE_AEGetEventHandler(PyObject
*_self
, PyObject
*_args
)
1159 PyObject
*_res
= NULL
;
1161 AEEventClass theAEEventClass
;
1162 AEEventID theAEEventID
;
1163 AEEventHandlerUPP handler__proc__
= upp_GenericEventHandler
;
1165 #ifndef AEGetEventHandler
1166 PyMac_PRECHECK(AEGetEventHandler
);
1168 if (!PyArg_ParseTuple(_args
, "O&O&",
1169 PyMac_GetOSType
, &theAEEventClass
,
1170 PyMac_GetOSType
, &theAEEventID
))
1172 _err
= AEGetEventHandler(theAEEventClass
,
1174 &handler__proc__
, (long *)&handler
,
1176 if (_err
!= noErr
) return PyMac_Error(_err
);
1177 _res
= Py_BuildValue("O",
1179 Py_INCREF(handler
); /* XXX leak, but needed */
1183 static PyObject
*AE_AEInstallSpecialHandler(PyObject
*_self
, PyObject
*_args
)
1185 PyObject
*_res
= NULL
;
1187 AEKeyword functionClass
;
1188 #ifndef AEInstallSpecialHandler
1189 PyMac_PRECHECK(AEInstallSpecialHandler
);
1191 if (!PyArg_ParseTuple(_args
, "O&",
1192 PyMac_GetOSType
, &functionClass
))
1194 _err
= AEInstallSpecialHandler(functionClass
,
1195 upp_GenericEventHandler
,
1197 if (_err
!= noErr
) return PyMac_Error(_err
);
1203 static PyObject
*AE_AERemoveSpecialHandler(PyObject
*_self
, PyObject
*_args
)
1205 PyObject
*_res
= NULL
;
1207 AEKeyword functionClass
;
1208 #ifndef AERemoveSpecialHandler
1209 PyMac_PRECHECK(AERemoveSpecialHandler
);
1211 if (!PyArg_ParseTuple(_args
, "O&",
1212 PyMac_GetOSType
, &functionClass
))
1214 _err
= AERemoveSpecialHandler(functionClass
,
1215 upp_GenericEventHandler
,
1217 if (_err
!= noErr
) return PyMac_Error(_err
);
1223 static PyObject
*AE_AEManagerInfo(PyObject
*_self
, PyObject
*_args
)
1225 PyObject
*_res
= NULL
;
1229 #ifndef AEManagerInfo
1230 PyMac_PRECHECK(AEManagerInfo
);
1232 if (!PyArg_ParseTuple(_args
, "O&",
1233 PyMac_GetOSType
, &keyWord
))
1235 _err
= AEManagerInfo(keyWord
,
1237 if (_err
!= noErr
) return PyMac_Error(_err
);
1238 _res
= Py_BuildValue("l",
1243 static PyObject
*AE_AEObjectInit(PyObject
*_self
, PyObject
*_args
)
1245 PyObject
*_res
= NULL
;
1247 #ifndef AEObjectInit
1248 PyMac_PRECHECK(AEObjectInit
);
1250 if (!PyArg_ParseTuple(_args
, ""))
1252 _err
= AEObjectInit();
1253 if (_err
!= noErr
) return PyMac_Error(_err
);
1259 static PyObject
*AE_AEDisposeToken(PyObject
*_self
, PyObject
*_args
)
1261 PyObject
*_res
= NULL
;
1264 #ifndef AEDisposeToken
1265 PyMac_PRECHECK(AEDisposeToken
);
1267 if (!PyArg_ParseTuple(_args
, ""))
1269 _err
= AEDisposeToken(&theToken
);
1270 if (_err
!= noErr
) return PyMac_Error(_err
);
1271 _res
= Py_BuildValue("O&",
1272 AEDesc_New
, &theToken
);
1276 static PyObject
*AE_AECallObjectAccessor(PyObject
*_self
, PyObject
*_args
)
1278 PyObject
*_res
= NULL
;
1280 DescType desiredClass
;
1281 AEDesc containerToken
;
1282 DescType containerClass
;
1286 #ifndef AECallObjectAccessor
1287 PyMac_PRECHECK(AECallObjectAccessor
);
1289 if (!PyArg_ParseTuple(_args
, "O&O&O&O&O&",
1290 PyMac_GetOSType
, &desiredClass
,
1291 AEDesc_Convert
, &containerToken
,
1292 PyMac_GetOSType
, &containerClass
,
1293 PyMac_GetOSType
, &keyForm
,
1294 AEDesc_Convert
, &keyData
))
1296 _err
= AECallObjectAccessor(desiredClass
,
1302 if (_err
!= noErr
) return PyMac_Error(_err
);
1303 _res
= Py_BuildValue("O&",
1304 AEDesc_New
, &token
);
1308 static PyMethodDef AE_methods
[] = {
1309 {"AECoercePtr", (PyCFunction
)AE_AECoercePtr
, 1,
1310 "(DescType typeCode, Buffer dataPtr, DescType toType) -> (AEDesc result)"},
1311 {"AECreateDesc", (PyCFunction
)AE_AECreateDesc
, 1,
1312 "(DescType typeCode, Buffer dataPtr) -> (AEDesc result)"},
1313 {"AECreateList", (PyCFunction
)AE_AECreateList
, 1,
1314 "(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)"},
1315 {"AECreateAppleEvent", (PyCFunction
)AE_AECreateAppleEvent
, 1,
1316 "(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, AEReturnID returnID, AETransactionID transactionID) -> (AppleEvent result)"},
1318 #if TARGET_API_MAC_CARBON
1319 {"AEReplaceDescData", (PyCFunction
)AE_AEReplaceDescData
, 1,
1320 "(DescType typeCode, Buffer dataPtr) -> (AEDesc theAEDesc)"},
1322 {"AEProcessAppleEvent", (PyCFunction
)AE_AEProcessAppleEvent
, 1,
1323 "(EventRecord theEventRecord) -> None"},
1324 {"AEGetInteractionAllowed", (PyCFunction
)AE_AEGetInteractionAllowed
, 1,
1325 "() -> (AEInteractAllowed level)"},
1326 {"AESetInteractionAllowed", (PyCFunction
)AE_AESetInteractionAllowed
, 1,
1327 "(AEInteractAllowed level) -> None"},
1328 {"AEInteractWithUser", (PyCFunction
)AE_AEInteractWithUser
, 1,
1329 "(long timeOutInTicks) -> None"},
1330 {"AEInstallEventHandler", (PyCFunction
)AE_AEInstallEventHandler
, 1,
1331 "(AEEventClass theAEEventClass, AEEventID theAEEventID, EventHandler handler) -> None"},
1332 {"AERemoveEventHandler", (PyCFunction
)AE_AERemoveEventHandler
, 1,
1333 "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None"},
1334 {"AEGetEventHandler", (PyCFunction
)AE_AEGetEventHandler
, 1,
1335 "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> (EventHandler handler)"},
1336 {"AEInstallSpecialHandler", (PyCFunction
)AE_AEInstallSpecialHandler
, 1,
1337 "(AEKeyword functionClass) -> None"},
1338 {"AERemoveSpecialHandler", (PyCFunction
)AE_AERemoveSpecialHandler
, 1,
1339 "(AEKeyword functionClass) -> None"},
1340 {"AEManagerInfo", (PyCFunction
)AE_AEManagerInfo
, 1,
1341 "(AEKeyword keyWord) -> (long result)"},
1342 {"AEObjectInit", (PyCFunction
)AE_AEObjectInit
, 1,
1344 {"AEDisposeToken", (PyCFunction
)AE_AEDisposeToken
, 1,
1345 "() -> (AEDesc theToken)"},
1346 {"AECallObjectAccessor", (PyCFunction
)AE_AECallObjectAccessor
, 1,
1347 "(DescType desiredClass, AEDesc containerToken, DescType containerClass, DescType keyForm, AEDesc keyData) -> (AEDesc token)"},
1353 #if UNIVERSAL_INTERFACES_VERSION >= 0x0340
1354 typedef long refcontype
;
1356 typedef unsigned long refcontype
;
1360 GenericEventHandler(const AppleEvent
*request
, AppleEvent
*reply
, refcontype refcon
)
1362 PyObject
*handler
= (PyObject
*)refcon
;
1363 AEDescObject
*requestObject
, *replyObject
;
1364 PyObject
*args
, *res
;
1365 if ((requestObject
= (AEDescObject
*)AEDesc_New((AppleEvent
*)request
)) == NULL
) {
1368 if ((replyObject
= (AEDescObject
*)AEDesc_New(reply
)) == NULL
) {
1369 Py_DECREF(requestObject
);
1372 if ((args
= Py_BuildValue("OO", requestObject
, replyObject
)) == NULL
) {
1373 Py_DECREF(requestObject
);
1374 Py_DECREF(replyObject
);
1377 res
= PyEval_CallObject(handler
, args
);
1378 requestObject
->ob_itself
.descriptorType
= 'null';
1379 requestObject
->ob_itself
.dataHandle
= NULL
;
1380 replyObject
->ob_itself
.descriptorType
= 'null';
1381 replyObject
->ob_itself
.dataHandle
= NULL
;
1384 PySys_WriteStderr("Exception in AE event handler function\n");
1400 upp_AEIdleProc
= NewAEIdleUPP(AEIdleProc
);
1401 #if UNIVERSAL_INTERFACES_VERSION >= 0x03400
1402 upp_GenericEventHandler
= NewAEEventHandlerUPP(&GenericEventHandler
);
1404 upp_GenericEventHandler
= NewAEEventHandlerUPP(GenericEventHandler
);
1406 PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc
*, AEDesc_New
);
1407 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc
, AEDesc_Convert
);
1410 m
= Py_InitModule("_AE", AE_methods
);
1411 d
= PyModule_GetDict(m
);
1412 AE_Error
= PyMac_GetOSErrException();
1413 if (AE_Error
== NULL
||
1414 PyDict_SetItemString(d
, "Error", AE_Error
) != 0)
1416 AEDesc_Type
.ob_type
= &PyType_Type
;
1417 Py_INCREF(&AEDesc_Type
);
1418 if (PyDict_SetItemString(d
, "AEDescType", (PyObject
*)&AEDesc_Type
) != 0)
1419 Py_FatalError("can't initialize AEDescType");
1422 /* ========================= End module _AE ========================= */