1995-01-30 11:53:55 +00:00
|
|
|
# This script will generate the AppleEvents interface for Python.
|
|
|
|
# It uses the "bgen" package to generate C code.
|
|
|
|
# It execs the file aegen.py which contain the function definitions
|
|
|
|
# (aegen.py was generated by aescan.py, scanning the <AppleEvents.h> header file).
|
|
|
|
|
|
|
|
|
|
|
|
from macsupport import *
|
|
|
|
|
|
|
|
|
|
|
|
AEArrayType = Type("AEArrayType", "c")
|
|
|
|
AESendMode = Type("AESendMode", "l")
|
|
|
|
AESendPriority = Type("AESendPriority", "h")
|
|
|
|
AEInteractAllowed = Type("AEInteractAllowed", "b")
|
1998-02-20 16:02:09 +00:00
|
|
|
AEReturnID = Type("AEReturnID", "h")
|
2000-03-14 23:29:08 +00:00
|
|
|
AETransactionID = Type("AETransactionID", "l")
|
1998-02-20 16:02:09 +00:00
|
|
|
|
1995-01-30 11:53:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
AEEventClass = OSTypeType('AEEventClass')
|
|
|
|
AEEventID = OSTypeType('AEEventID')
|
|
|
|
AEKeyword = OSTypeType('AEKeyword')
|
|
|
|
DescType = OSTypeType('DescType')
|
|
|
|
|
|
|
|
|
|
|
|
AEDesc = OpaqueType('AEDesc')
|
|
|
|
AEDesc_ptr = OpaqueType('AEDesc')
|
|
|
|
|
|
|
|
AEAddressDesc = OpaqueType('AEAddressDesc', 'AEDesc')
|
|
|
|
AEAddressDesc_ptr = OpaqueType('AEAddressDesc', 'AEDesc')
|
|
|
|
|
|
|
|
AEDescList = OpaqueType('AEDescList', 'AEDesc')
|
|
|
|
AEDescList_ptr = OpaqueType('AEDescList', 'AEDesc')
|
|
|
|
|
|
|
|
AERecord = OpaqueType('AERecord', 'AEDesc')
|
|
|
|
AERecord_ptr = OpaqueType('AERecord', 'AEDesc')
|
|
|
|
|
|
|
|
AppleEvent = OpaqueType('AppleEvent', 'AEDesc')
|
|
|
|
AppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc')
|
|
|
|
|
|
|
|
|
|
|
|
class EHType(Type):
|
|
|
|
def __init__(self, name = 'EventHandler', format = ''):
|
|
|
|
Type.__init__(self, name, format)
|
|
|
|
def declare(self, name):
|
1995-02-05 16:58:33 +00:00
|
|
|
Output("AEEventHandlerUPP %s__proc__ = upp_GenericEventHandler;", name)
|
1995-01-30 11:53:55 +00:00
|
|
|
Output("PyObject *%s;", name)
|
|
|
|
def getargsFormat(self):
|
|
|
|
return "O"
|
|
|
|
def getargsArgs(self, name):
|
|
|
|
return "&%s" % name
|
|
|
|
def passInput(self, name):
|
|
|
|
return "%s__proc__, (long)%s" % (name, name)
|
|
|
|
def passOutput(self, name):
|
|
|
|
return "&%s__proc__, (long *)&%s" % (name, name)
|
|
|
|
def mkvalueFormat(self):
|
|
|
|
return "O"
|
|
|
|
def mkvalueArgs(self, name):
|
|
|
|
return name
|
1995-02-05 16:58:33 +00:00
|
|
|
def cleanup(self, name):
|
|
|
|
Output("Py_INCREF(%s); /* XXX leak, but needed */", name)
|
1995-01-30 11:53:55 +00:00
|
|
|
|
|
|
|
class EHNoRefConType(EHType):
|
|
|
|
def passInput(self, name):
|
1995-02-05 16:58:33 +00:00
|
|
|
return "upp_GenericEventHandler"
|
1995-01-30 11:53:55 +00:00
|
|
|
|
|
|
|
EventHandler = EHType()
|
|
|
|
EventHandlerNoRefCon = EHNoRefConType()
|
|
|
|
|
|
|
|
|
1995-02-05 16:58:33 +00:00
|
|
|
IdleProcPtr = FakeType("upp_AEIdleProc")
|
1995-06-05 22:34:12 +00:00
|
|
|
AEIdleUPP = IdleProcPtr
|
1995-02-05 16:58:33 +00:00
|
|
|
EventFilterProcPtr = FakeType("(AEFilterUPP)0")
|
1995-06-05 22:34:12 +00:00
|
|
|
AEFilterUPP = EventFilterProcPtr
|
1995-01-30 11:53:55 +00:00
|
|
|
NMRecPtr = FakeType("(NMRecPtr)0")
|
1995-02-05 16:58:33 +00:00
|
|
|
EventHandlerProcPtr = FakeType("upp_GenericEventHandler")
|
1995-06-05 22:34:12 +00:00
|
|
|
AEEventHandlerUPP = EventHandlerProcPtr
|
1995-01-30 11:53:55 +00:00
|
|
|
AlwaysFalse = FakeType("0")
|
|
|
|
|
|
|
|
|
2002-03-25 00:32:17 +00:00
|
|
|
AEFunction = OSErrWeakLinkFunctionGenerator
|
|
|
|
AEMethod = OSErrWeakLinkMethodGenerator
|
1995-01-30 11:53:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
includestuff = includestuff + """
|
2001-05-22 21:56:42 +00:00
|
|
|
#ifdef WITHOUT_FRAMEWORKS
|
1995-01-30 11:53:55 +00:00
|
|
|
#include <AppleEvents.h>
|
2000-12-10 23:43:49 +00:00
|
|
|
#include <AEObjects.h>
|
2001-05-22 21:56:42 +00:00
|
|
|
#else
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#endif
|
1995-01-30 11:53:55 +00:00
|
|
|
|
2001-05-17 21:58:34 +00:00
|
|
|
#ifdef USE_TOOLBOX_OBJECT_GLUE
|
|
|
|
extern PyObject *_AEDesc_New(AEDesc *);
|
|
|
|
extern int _AEDesc_Convert(PyObject *, AEDesc *);
|
|
|
|
|
|
|
|
#define AEDesc_New _AEDesc_New
|
|
|
|
#define AEDesc_Convert _AEDesc_Convert
|
|
|
|
#endif
|
|
|
|
|
1995-01-30 11:53:55 +00:00
|
|
|
static pascal OSErr GenericEventHandler(); /* Forward */
|
|
|
|
|
1995-02-05 16:58:33 +00:00
|
|
|
AEEventHandlerUPP upp_GenericEventHandler;
|
|
|
|
|
1995-01-30 11:53:55 +00:00
|
|
|
static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn)
|
|
|
|
{
|
1997-06-20 16:19:14 +00:00
|
|
|
if ( PyOS_InterruptOccurred() )
|
|
|
|
return 1;
|
2001-09-01 23:38:50 +00:00
|
|
|
#if !TARGET_API_MAC_OSX
|
1997-06-20 16:19:14 +00:00
|
|
|
if ( PyMac_HandleEvent(theEvent) < 0 ) {
|
1998-10-12 20:53:15 +00:00
|
|
|
PySys_WriteStderr("Exception in user event handler during AE processing\\n");
|
1997-06-20 16:19:14 +00:00
|
|
|
PyErr_Clear();
|
|
|
|
}
|
2001-09-01 23:38:50 +00:00
|
|
|
#endif
|
1995-02-05 16:58:33 +00:00
|
|
|
return 0;
|
1995-01-30 11:53:55 +00:00
|
|
|
}
|
1995-02-05 16:58:33 +00:00
|
|
|
|
|
|
|
AEIdleUPP upp_AEIdleProc;
|
1995-01-30 11:53:55 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
finalstuff = finalstuff + """
|
2001-06-20 20:53:38 +00:00
|
|
|
#if UNIVERSAL_INTERFACES_VERSION >= 0x0340
|
|
|
|
typedef long refcontype;
|
|
|
|
#else
|
|
|
|
typedef unsigned long refcontype;
|
|
|
|
#endif
|
|
|
|
|
1995-01-30 11:53:55 +00:00
|
|
|
static pascal OSErr
|
2001-06-20 20:53:38 +00:00
|
|
|
GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon)
|
1995-01-30 11:53:55 +00:00
|
|
|
{
|
|
|
|
PyObject *handler = (PyObject *)refcon;
|
|
|
|
AEDescObject *requestObject, *replyObject;
|
|
|
|
PyObject *args, *res;
|
2000-07-14 22:16:45 +00:00
|
|
|
if ((requestObject = (AEDescObject *)AEDesc_New((AppleEvent *)request)) == NULL) {
|
1995-01-30 11:53:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) {
|
|
|
|
Py_DECREF(requestObject);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) {
|
|
|
|
Py_DECREF(requestObject);
|
|
|
|
Py_DECREF(replyObject);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
res = PyEval_CallObject(handler, args);
|
|
|
|
requestObject->ob_itself.descriptorType = 'null';
|
|
|
|
requestObject->ob_itself.dataHandle = NULL;
|
|
|
|
replyObject->ob_itself.descriptorType = 'null';
|
|
|
|
replyObject->ob_itself.dataHandle = NULL;
|
|
|
|
Py_DECREF(args);
|
2002-01-04 13:49:36 +00:00
|
|
|
if (res == NULL) {
|
|
|
|
PySys_WriteStderr("Exception in AE event handler function\\n");
|
|
|
|
PyErr_Print();
|
1995-01-30 11:53:55 +00:00
|
|
|
return -1;
|
2002-01-04 13:49:36 +00:00
|
|
|
}
|
1995-01-30 11:53:55 +00:00
|
|
|
Py_DECREF(res);
|
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
1995-02-05 16:58:33 +00:00
|
|
|
initstuff = initstuff + """
|
2001-05-22 21:56:42 +00:00
|
|
|
upp_AEIdleProc = NewAEIdleUPP(AEIdleProc);
|
2001-06-20 21:44:38 +00:00
|
|
|
#if UNIVERSAL_INTERFACES_VERSION >= 0x03400
|
2001-06-20 20:53:38 +00:00
|
|
|
upp_GenericEventHandler = NewAEEventHandlerUPP(&GenericEventHandler);
|
|
|
|
#else
|
2001-05-22 21:56:42 +00:00
|
|
|
upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler);
|
2001-06-20 20:53:38 +00:00
|
|
|
#endif
|
2001-05-22 21:56:42 +00:00
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);
|
1995-02-05 16:58:33 +00:00
|
|
|
"""
|
|
|
|
|
2001-08-23 13:51:46 +00:00
|
|
|
module = MacModule('_AE', 'AE', includestuff, finalstuff, initstuff)
|
1995-01-30 11:53:55 +00:00
|
|
|
|
1997-08-15 14:31:13 +00:00
|
|
|
class AEDescDefinition(GlobalObjectDefinition):
|
1995-01-30 11:53:55 +00:00
|
|
|
|
|
|
|
def __init__(self, name, prefix = None, itselftype = None):
|
1997-08-15 14:31:13 +00:00
|
|
|
GlobalObjectDefinition.__init__(self, name, prefix or name, itselftype or name)
|
1995-01-30 11:53:55 +00:00
|
|
|
self.argref = "*"
|
|
|
|
|
|
|
|
def outputFreeIt(self, name):
|
|
|
|
Output("AEDisposeDesc(&%s);", name)
|
|
|
|
|
|
|
|
def outputGetattrHook(self):
|
|
|
|
Output("""
|
|
|
|
if (strcmp(name, "type") == 0)
|
|
|
|
return PyMac_BuildOSType(self->ob_itself.descriptorType);
|
|
|
|
if (strcmp(name, "data") == 0) {
|
|
|
|
PyObject *res;
|
2000-07-14 22:37:27 +00:00
|
|
|
#if !TARGET_API_MAC_CARBON
|
1995-01-30 11:53:55 +00:00
|
|
|
char state;
|
|
|
|
state = HGetState(self->ob_itself.dataHandle);
|
|
|
|
HLock(self->ob_itself.dataHandle);
|
|
|
|
res = PyString_FromStringAndSize(
|
|
|
|
*self->ob_itself.dataHandle,
|
|
|
|
GetHandleSize(self->ob_itself.dataHandle));
|
|
|
|
HUnlock(self->ob_itself.dataHandle);
|
|
|
|
HSetState(self->ob_itself.dataHandle, state);
|
2000-06-02 21:35:07 +00:00
|
|
|
#else
|
|
|
|
Size size;
|
|
|
|
char *ptr;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
size = AEGetDescDataSize(&self->ob_itself);
|
|
|
|
if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
|
|
|
|
return NULL;
|
|
|
|
if ( (ptr = PyString_AsString(res)) == NULL )
|
|
|
|
return NULL;
|
|
|
|
if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
|
|
|
|
return PyMac_Error(err);
|
|
|
|
#endif
|
1995-01-30 11:53:55 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
if (strcmp(name, "__members__") == 0)
|
|
|
|
return Py_BuildValue("[ss]", "data", "type");
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
1997-08-15 14:31:13 +00:00
|
|
|
aedescobject = AEDescDefinition('AEDesc')
|
1995-01-30 11:53:55 +00:00
|
|
|
module.addobject(aedescobject)
|
|
|
|
|
|
|
|
functions = []
|
|
|
|
aedescmethods = []
|
|
|
|
|
|
|
|
execfile('aegen.py')
|
2000-12-12 22:09:11 +00:00
|
|
|
##execfile('aedatamodelgen.py')
|
1995-01-30 11:53:55 +00:00
|
|
|
|
|
|
|
for f in functions: module.add(f)
|
|
|
|
for f in aedescmethods: aedescobject.add(f)
|
|
|
|
|
2001-08-23 13:51:46 +00:00
|
|
|
SetOutputFileName('_AEmodule.c')
|
1995-01-30 11:53:55 +00:00
|
|
|
module.generate()
|