1995-01-30 07:53:55 -04: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 12:02:09 -04:00
|
|
|
AEReturnID = Type("AEReturnID", "h")
|
2000-03-14 19:29:08 -04:00
|
|
|
AETransactionID = Type("AETransactionID", "l")
|
1998-02-20 12:02:09 -04:00
|
|
|
|
1995-01-30 07:53:55 -04: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):
|
2004-07-18 03:16:08 -03:00
|
|
|
def __init__(self, name = 'EventHandler', format = ''):
|
|
|
|
Type.__init__(self, name, format)
|
|
|
|
def declare(self, name):
|
|
|
|
Output("AEEventHandlerUPP %s__proc__ = upp_GenericEventHandler;", name)
|
|
|
|
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
|
|
|
|
def cleanup(self, name):
|
|
|
|
Output("Py_INCREF(%s); /* XXX leak, but needed */", name)
|
1995-01-30 07:53:55 -04:00
|
|
|
|
|
|
|
class EHNoRefConType(EHType):
|
2004-07-18 03:16:08 -03:00
|
|
|
def passInput(self, name):
|
|
|
|
return "upp_GenericEventHandler"
|
1995-01-30 07:53:55 -04:00
|
|
|
|
|
|
|
EventHandler = EHType()
|
|
|
|
EventHandlerNoRefCon = EHNoRefConType()
|
|
|
|
|
|
|
|
|
1995-02-05 12:58:33 -04:00
|
|
|
IdleProcPtr = FakeType("upp_AEIdleProc")
|
1995-06-05 19:34:12 -03:00
|
|
|
AEIdleUPP = IdleProcPtr
|
1995-02-05 12:58:33 -04:00
|
|
|
EventFilterProcPtr = FakeType("(AEFilterUPP)0")
|
1995-06-05 19:34:12 -03:00
|
|
|
AEFilterUPP = EventFilterProcPtr
|
1995-01-30 07:53:55 -04:00
|
|
|
NMRecPtr = FakeType("(NMRecPtr)0")
|
1995-02-05 12:58:33 -04:00
|
|
|
EventHandlerProcPtr = FakeType("upp_GenericEventHandler")
|
1995-06-05 19:34:12 -03:00
|
|
|
AEEventHandlerUPP = EventHandlerProcPtr
|
1995-01-30 07:53:55 -04:00
|
|
|
AlwaysFalse = FakeType("0")
|
|
|
|
|
|
|
|
|
2002-03-24 20:32:17 -04:00
|
|
|
AEFunction = OSErrWeakLinkFunctionGenerator
|
|
|
|
AEMethod = OSErrWeakLinkMethodGenerator
|
1995-01-30 07:53:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
includestuff = includestuff + """
|
2001-05-22 18:56:42 -03:00
|
|
|
#include <Carbon/Carbon.h>
|
1995-01-30 07:53:55 -04:00
|
|
|
|
2001-05-17 18:58:34 -03:00
|
|
|
#ifdef USE_TOOLBOX_OBJECT_GLUE
|
|
|
|
extern PyObject *_AEDesc_New(AEDesc *);
|
|
|
|
extern int _AEDesc_Convert(PyObject *, AEDesc *);
|
|
|
|
|
|
|
|
#define AEDesc_New _AEDesc_New
|
2003-01-17 19:11:17 -04:00
|
|
|
#define AEDesc_NewBorrowed _AEDesc_NewBorrowed
|
2001-05-17 18:58:34 -03:00
|
|
|
#define AEDesc_Convert _AEDesc_Convert
|
|
|
|
#endif
|
|
|
|
|
2002-11-29 19:40:48 -04:00
|
|
|
typedef long refcontype;
|
|
|
|
|
|
|
|
static pascal OSErr GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon); /* Forward */
|
1995-01-30 07:53:55 -04:00
|
|
|
|
1995-02-05 12:58:33 -04:00
|
|
|
AEEventHandlerUPP upp_GenericEventHandler;
|
|
|
|
|
1995-01-30 07:53:55 -04:00
|
|
|
static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn)
|
|
|
|
{
|
2004-07-18 03:16:08 -03:00
|
|
|
if ( PyOS_InterruptOccurred() )
|
|
|
|
return 1;
|
|
|
|
return 0;
|
1995-01-30 07:53:55 -04:00
|
|
|
}
|
1995-02-05 12:58:33 -04:00
|
|
|
|
|
|
|
AEIdleUPP upp_AEIdleProc;
|
1995-01-30 07:53:55 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
finalstuff = finalstuff + """
|
|
|
|
static pascal OSErr
|
2001-06-20 17:53:38 -03:00
|
|
|
GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon)
|
1995-01-30 07:53:55 -04:00
|
|
|
{
|
2004-07-18 03:16:08 -03:00
|
|
|
PyObject *handler = (PyObject *)refcon;
|
|
|
|
AEDescObject *requestObject, *replyObject;
|
|
|
|
PyObject *args, *res;
|
|
|
|
if ((requestObject = (AEDescObject *)AEDesc_New((AppleEvent *)request)) == NULL) {
|
|
|
|
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);
|
|
|
|
if (res == NULL) {
|
|
|
|
PySys_WriteStderr("Exception in AE event handler function\\n");
|
|
|
|
PyErr_Print();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
Py_DECREF(res);
|
|
|
|
return noErr;
|
1995-01-30 07:53:55 -04:00
|
|
|
}
|
2003-01-17 19:11:17 -04:00
|
|
|
|
|
|
|
PyObject *AEDesc_NewBorrowed(AEDesc *itself)
|
|
|
|
{
|
2004-07-18 03:16:08 -03:00
|
|
|
PyObject *it;
|
|
|
|
|
|
|
|
it = AEDesc_New(itself);
|
|
|
|
if (it)
|
|
|
|
((AEDescObject *)it)->ob_owned = 0;
|
|
|
|
return (PyObject *)it;
|
2003-01-17 19:11:17 -04:00
|
|
|
}
|
|
|
|
|
1995-01-30 07:53:55 -04:00
|
|
|
"""
|
|
|
|
|
1995-02-05 12:58:33 -04:00
|
|
|
initstuff = initstuff + """
|
2004-07-18 03:16:08 -03:00
|
|
|
upp_AEIdleProc = NewAEIdleUPP(AEIdleProc);
|
|
|
|
upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_NewBorrowed);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);
|
1995-02-05 12:58:33 -04:00
|
|
|
"""
|
|
|
|
|
2001-08-23 10:51:46 -03:00
|
|
|
module = MacModule('_AE', 'AE', includestuff, finalstuff, initstuff)
|
1995-01-30 07:53:55 -04:00
|
|
|
|
2002-12-03 19:40:22 -04:00
|
|
|
class AEDescDefinition(PEP253Mixin, GlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
getsetlist = [(
|
|
|
|
'type',
|
|
|
|
'return PyMac_BuildOSType(self->ob_itself.descriptorType);',
|
|
|
|
None,
|
|
|
|
'Type of this AEDesc'
|
|
|
|
), (
|
|
|
|
'data',
|
|
|
|
"""
|
|
|
|
PyObject *res;
|
|
|
|
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);
|
|
|
|
return res;
|
|
|
|
""",
|
|
|
|
None,
|
|
|
|
'The raw data in this AEDesc'
|
|
|
|
)]
|
|
|
|
|
|
|
|
def __init__(self, name, prefix = None, itselftype = None):
|
|
|
|
GlobalObjectDefinition.__init__(self, name, prefix or name, itselftype or name)
|
|
|
|
self.argref = "*"
|
|
|
|
|
|
|
|
def outputStructMembers(self):
|
|
|
|
GlobalObjectDefinition.outputStructMembers(self)
|
|
|
|
Output("int ob_owned;")
|
|
|
|
|
|
|
|
def outputInitStructMembers(self):
|
|
|
|
GlobalObjectDefinition.outputInitStructMembers(self)
|
|
|
|
Output("it->ob_owned = 1;")
|
|
|
|
|
|
|
|
def outputCleanupStructMembers(self):
|
|
|
|
Output("if (self->ob_owned) AEDisposeDesc(&self->ob_itself);")
|
1995-01-30 07:53:55 -04:00
|
|
|
|
1997-08-15 11:31:13 -03:00
|
|
|
aedescobject = AEDescDefinition('AEDesc')
|
1995-01-30 07:53:55 -04:00
|
|
|
module.addobject(aedescobject)
|
|
|
|
|
|
|
|
functions = []
|
|
|
|
aedescmethods = []
|
|
|
|
|
|
|
|
execfile('aegen.py')
|
2000-12-12 18:09:11 -04:00
|
|
|
##execfile('aedatamodelgen.py')
|
1995-01-30 07:53:55 -04:00
|
|
|
|
2003-01-17 19:11:17 -04:00
|
|
|
# Manual generator
|
|
|
|
AutoDispose_body = """
|
|
|
|
int onoff, old;
|
|
|
|
if (!PyArg_ParseTuple(_args, "i", &onoff))
|
|
|
|
return NULL;
|
|
|
|
old = _self->ob_owned;
|
|
|
|
_self->ob_owned = onoff;
|
|
|
|
_res = Py_BuildValue("i", old);
|
|
|
|
return _res;
|
|
|
|
"""
|
|
|
|
f = ManualGenerator("AutoDispose", AutoDispose_body)
|
|
|
|
f.docstring = lambda: "(int)->int. Automatically AEDisposeDesc the object on Python object cleanup"
|
|
|
|
aedescmethods.append(f)
|
|
|
|
|
1995-01-30 07:53:55 -04:00
|
|
|
for f in functions: module.add(f)
|
|
|
|
for f in aedescmethods: aedescobject.add(f)
|
|
|
|
|
2001-08-23 10:51:46 -03:00
|
|
|
SetOutputFileName('_AEmodule.c')
|
1995-01-30 07:53:55 -04:00
|
|
|
module.generate()
|