@@ -667,18 +667,19 @@ static PyObject *AEDesc_AEResumeTheCurrentEvent(_self, _args)
667667 PyObject * _res = NULL ;
668668 OSErr _err ;
669669 AppleEvent reply ;
670- long handlerRefcon ;
671- if (!PyArg_ParseTuple (_args , "O&l" ,
670+ AEEventHandlerUPP dispatcher__proc__ = upp_GenericEventHandler ;
671+ PyObject * dispatcher ;
672+ if (!PyArg_ParseTuple (_args , "O&O" ,
672673 AEDesc_Convert , & reply ,
673- & handlerRefcon ))
674+ & dispatcher ))
674675 return NULL ;
675676 _err = AEResumeTheCurrentEvent (& _self -> ob_itself ,
676677 & reply ,
677- upp_GenericEventHandler ,
678- handlerRefcon );
678+ dispatcher__proc__ , (long )dispatcher );
679679 if (_err != noErr ) return PyMac_Error (_err );
680680 Py_INCREF (Py_None );
681681 _res = Py_None ;
682+ Py_INCREF (dispatcher ); /* XXX leak, but needed */
682683 return _res ;
683684}
684685
@@ -760,7 +761,7 @@ static PyMethodDef AEDesc_methods[] = {
760761 {"AESuspendTheCurrentEvent" , (PyCFunction )AEDesc_AESuspendTheCurrentEvent , 1 ,
761762 "() -> None" },
762763 {"AEResumeTheCurrentEvent" , (PyCFunction )AEDesc_AEResumeTheCurrentEvent , 1 ,
763- "(AppleEvent reply, long handlerRefcon ) -> None" },
764+ "(AppleEvent reply, EventHandler dispatcher ) -> None" },
764765 {"AEGetTheCurrentEvent" , (PyCFunction )AEDesc_AEGetTheCurrentEvent , 1 ,
765766 "() -> None" },
766767 {"AESetTheCurrentEvent" , (PyCFunction )AEDesc_AESetTheCurrentEvent , 1 ,
@@ -1002,20 +1003,21 @@ static PyObject *AE_AEInstallEventHandler(_self, _args)
10021003 OSErr _err ;
10031004 AEEventClass theAEEventClass ;
10041005 AEEventID theAEEventID ;
1005- long handlerRefcon ;
1006- if (!PyArg_ParseTuple (_args , "O&O&l" ,
1006+ AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler ;
1007+ PyObject * handler ;
1008+ if (!PyArg_ParseTuple (_args , "O&O&O" ,
10071009 PyMac_GetOSType , & theAEEventClass ,
10081010 PyMac_GetOSType , & theAEEventID ,
1009- & handlerRefcon ))
1011+ & handler ))
10101012 return NULL ;
10111013 _err = AEInstallEventHandler (theAEEventClass ,
10121014 theAEEventID ,
1013- upp_GenericEventHandler ,
1014- handlerRefcon ,
1015+ handler__proc__ , (long )handler ,
10151016 0 );
10161017 if (_err != noErr ) return PyMac_Error (_err );
10171018 Py_INCREF (Py_None );
10181019 _res = Py_None ;
1020+ Py_INCREF (handler ); /* XXX leak, but needed */
10191021 return _res ;
10201022}
10211023
@@ -1041,6 +1043,30 @@ static PyObject *AE_AERemoveEventHandler(_self, _args)
10411043 return _res ;
10421044}
10431045
1046+ static PyObject * AE_AEGetEventHandler (_self , _args )
1047+ PyObject * _self ;
1048+ PyObject * _args ;
1049+ {
1050+ PyObject * _res = NULL ;
1051+ OSErr _err ;
1052+ AEEventClass theAEEventClass ;
1053+ AEEventID theAEEventID ;
1054+ long procptr , handlerptr ;
1055+
1056+ if (!PyArg_ParseTuple (_args , "O&O&" ,
1057+ PyMac_GetOSType , & theAEEventClass ,
1058+ PyMac_GetOSType , & theAEEventID ))
1059+ return NULL ;
1060+ _err = AEGetEventHandler (theAEEventClass ,
1061+ theAEEventID ,
1062+ (AEEventHandlerUPP * )& procptr , & handlerptr ,
1063+ 0 );
1064+ if (_err != noErr ) return PyMac_Error (_err );
1065+ _res = Py_BuildValue ("ll" ,
1066+ (long )procptr , (long )handlerptr );
1067+ return _res ;
1068+ }
1069+
10441070static PyObject * AE_AEManagerInfo (_self , _args )
10451071 PyObject * _self ;
10461072 PyObject * _args ;
@@ -1078,9 +1104,11 @@ static PyMethodDef AE_methods[] = {
10781104 {"AEInteractWithUser" , (PyCFunction )AE_AEInteractWithUser , 1 ,
10791105 "(long timeOutInTicks) -> None" },
10801106 {"AEInstallEventHandler" , (PyCFunction )AE_AEInstallEventHandler , 1 ,
1081- "(AEEventClass theAEEventClass, AEEventID theAEEventID, long handlerRefcon ) -> None" },
1107+ "(AEEventClass theAEEventClass, AEEventID theAEEventID, EventHandler handler ) -> None" },
10821108 {"AERemoveEventHandler" , (PyCFunction )AE_AERemoveEventHandler , 1 ,
10831109 "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None" },
1110+ {"AEGetEventHandler" , (PyCFunction )AE_AEGetEventHandler , 1 ,
1111+ "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> (EventHandler handler)" },
10841112 {"AEManagerInfo" , (PyCFunction )AE_AEManagerInfo , 1 ,
10851113 "(AEKeyword keyWord) -> (long result)" },
10861114 {NULL , NULL , 0 }
0 commit comments