99#include "pymactoolbox.h"
1010
1111#include <AppleEvents.h>
12+ #include <AEObjects.h>
1213
1314static pascal OSErr GenericEventHandler (); /* Forward */
1415
@@ -69,34 +70,6 @@ static void AEDesc_dealloc(self)
6970 PyMem_DEL (self );
7071}
7172
72- static PyObject * AEDesc_AESend (_self , _args )
73- AEDescObject * _self ;
74- PyObject * _args ;
75- {
76- PyObject * _res = NULL ;
77- OSErr _err ;
78- AppleEvent reply ;
79- AESendMode sendMode ;
80- AESendPriority sendPriority ;
81- long timeOutInTicks ;
82- if (!PyArg_ParseTuple (_args , "lhl" ,
83- & sendMode ,
84- & sendPriority ,
85- & timeOutInTicks ))
86- return NULL ;
87- _err = AESend (& _self -> ob_itself ,
88- & reply ,
89- sendMode ,
90- sendPriority ,
91- timeOutInTicks ,
92- upp_AEIdleProc ,
93- (AEFilterUPP )0 );
94- if (_err != noErr ) return PyMac_Error (_err );
95- _res = Py_BuildValue ("O&" ,
96- AEDesc_New , & reply );
97- return _res ;
98- }
99-
10073static PyObject * AEDesc_AEResetTimer (_self , _args )
10174 AEDescObject * _self ;
10275 PyObject * _args ;
@@ -672,9 +645,24 @@ static PyObject *AEDesc_AEPutAttributeDesc(_self, _args)
672645 return _res ;
673646}
674647
648+ #if TARGET_API_MAC_CARBON
649+
650+ static PyObject * AEDesc_AEGetDescDataSize (_self , _args )
651+ AEDescObject * _self ;
652+ PyObject * _args ;
653+ {
654+ PyObject * _res = NULL ;
655+ Size _rv ;
656+ if (!PyArg_ParseTuple (_args , "" ))
657+ return NULL ;
658+ _rv = AEGetDescDataSize (& _self -> ob_itself );
659+ _res = Py_BuildValue ("l" ,
660+ _rv );
661+ return _res ;
662+ }
663+ #endif
664+
675665static PyMethodDef AEDesc_methods [] = {
676- {"AESend" , (PyCFunction )AEDesc_AESend , 1 ,
677- "(AESendMode sendMode, AESendPriority sendPriority, long timeOutInTicks) -> (AppleEvent reply)" },
678666 {"AEResetTimer" , (PyCFunction )AEDesc_AEResetTimer , 1 ,
679667 "() -> None" },
680668 {"AESuspendTheCurrentEvent" , (PyCFunction )AEDesc_AESuspendTheCurrentEvent , 1 ,
@@ -725,6 +713,11 @@ static PyMethodDef AEDesc_methods[] = {
725713 "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None" },
726714 {"AEPutAttributeDesc" , (PyCFunction )AEDesc_AEPutAttributeDesc , 1 ,
727715 "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None" },
716+
717+ #if TARGET_API_MAC_CARBON
718+ {"AEGetDescDataSize" , (PyCFunction )AEDesc_AEGetDescDataSize , 1 ,
719+ "() -> (Size _rv)" },
720+ #endif
728721 {NULL , NULL , 0 }
729722};
730723
@@ -941,6 +934,44 @@ static PyObject *AE_AEGetEventHandler(_self, _args)
941934 return _res ;
942935}
943936
937+ static PyObject * AE_AEInstallSpecialHandler (_self , _args )
938+ PyObject * _self ;
939+ PyObject * _args ;
940+ {
941+ PyObject * _res = NULL ;
942+ OSErr _err ;
943+ AEKeyword functionClass ;
944+ if (!PyArg_ParseTuple (_args , "O&" ,
945+ PyMac_GetOSType , & functionClass ))
946+ return NULL ;
947+ _err = AEInstallSpecialHandler (functionClass ,
948+ upp_GenericEventHandler ,
949+ 0 );
950+ if (_err != noErr ) return PyMac_Error (_err );
951+ Py_INCREF (Py_None );
952+ _res = Py_None ;
953+ return _res ;
954+ }
955+
956+ static PyObject * AE_AERemoveSpecialHandler (_self , _args )
957+ PyObject * _self ;
958+ PyObject * _args ;
959+ {
960+ PyObject * _res = NULL ;
961+ OSErr _err ;
962+ AEKeyword functionClass ;
963+ if (!PyArg_ParseTuple (_args , "O&" ,
964+ PyMac_GetOSType , & functionClass ))
965+ return NULL ;
966+ _err = AERemoveSpecialHandler (functionClass ,
967+ upp_GenericEventHandler ,
968+ 0 );
969+ if (_err != noErr ) return PyMac_Error (_err );
970+ Py_INCREF (Py_None );
971+ _res = Py_None ;
972+ return _res ;
973+ }
974+
944975static PyObject * AE_AEManagerInfo (_self , _args )
945976 PyObject * _self ;
946977 PyObject * _args ;
@@ -1072,6 +1103,35 @@ static PyObject *AE_AECreateAppleEvent(_self, _args)
10721103 return _res ;
10731104}
10741105
1106+ #if TARGET_API_MAC_CARBON
1107+
1108+ static PyObject * AE_AEReplaceDescData (_self , _args )
1109+ PyObject * _self ;
1110+ PyObject * _args ;
1111+ {
1112+ PyObject * _res = NULL ;
1113+ OSErr _err ;
1114+ DescType typeCode ;
1115+ char * dataPtr__in__ ;
1116+ long dataPtr__len__ ;
1117+ int dataPtr__in_len__ ;
1118+ AEDesc theAEDesc ;
1119+ if (!PyArg_ParseTuple (_args , "O&s#" ,
1120+ PyMac_GetOSType , & typeCode ,
1121+ & dataPtr__in__ , & dataPtr__in_len__ ))
1122+ return NULL ;
1123+ dataPtr__len__ = dataPtr__in_len__ ;
1124+ _err = AEReplaceDescData (typeCode ,
1125+ dataPtr__in__ , dataPtr__len__ ,
1126+ & theAEDesc );
1127+ if (_err != noErr ) return PyMac_Error (_err );
1128+ _res = Py_BuildValue ("O&" ,
1129+ AEDesc_New , & theAEDesc );
1130+ dataPtr__error__ : ;
1131+ return _res ;
1132+ }
1133+ #endif
1134+
10751135static PyMethodDef AE_methods [] = {
10761136 {"AEProcessAppleEvent" , (PyCFunction )AE_AEProcessAppleEvent , 1 ,
10771137 "(EventRecord theEventRecord) -> None" },
@@ -1087,6 +1147,10 @@ static PyMethodDef AE_methods[] = {
10871147 "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None" },
10881148 {"AEGetEventHandler" , (PyCFunction )AE_AEGetEventHandler , 1 ,
10891149 "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> (EventHandler handler)" },
1150+ {"AEInstallSpecialHandler" , (PyCFunction )AE_AEInstallSpecialHandler , 1 ,
1151+ "(AEKeyword functionClass) -> None" },
1152+ {"AERemoveSpecialHandler" , (PyCFunction )AE_AERemoveSpecialHandler , 1 ,
1153+ "(AEKeyword functionClass) -> None" },
10901154 {"AEManagerInfo" , (PyCFunction )AE_AEManagerInfo , 1 ,
10911155 "(AEKeyword keyWord) -> (long result)" },
10921156 {"AECoercePtr" , (PyCFunction )AE_AECoercePtr , 1 ,
@@ -1097,6 +1161,11 @@ static PyMethodDef AE_methods[] = {
10971161 "(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)" },
10981162 {"AECreateAppleEvent" , (PyCFunction )AE_AECreateAppleEvent , 1 ,
10991163 "(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, AEReturnID returnID, AETransactionID transactionID) -> (AppleEvent result)" },
1164+
1165+ #if TARGET_API_MAC_CARBON
1166+ {"AEReplaceDescData" , (PyCFunction )AE_AEReplaceDescData , 1 ,
1167+ "(DescType typeCode, Buffer dataPtr) -> (AEDesc theAEDesc)" },
1168+ #endif
11001169 {NULL , NULL , 0 }
11011170};
11021171
@@ -1149,7 +1218,7 @@ void initAE()
11491218 AE_Error = PyMac_GetOSErrException ();
11501219 if (AE_Error == NULL ||
11511220 PyDict_SetItemString (d , "Error" , AE_Error ) != 0 )
1152- Py_FatalError ( "can't initialize AE.Error" ) ;
1221+ return ;
11531222 AEDesc_Type .ob_type = & PyType_Type ;
11541223 Py_INCREF (& AEDesc_Type );
11551224 if (PyDict_SetItemString (d , "AEDescType" , (PyObject * )& AEDesc_Type ) != 0 )
0 commit comments