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")
|
|
|
|
AETransactionID = Type("AETransactionID", "h")
|
|
|
|
|
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):
|
|
|
|
def __init__(self, name = 'EventHandler', format = ''):
|
|
|
|
Type.__init__(self, name, format)
|
|
|
|
def declare(self, name):
|
1995-02-05 12:58:33 -04:00
|
|
|
Output("AEEventHandlerUPP %s__proc__ = upp_GenericEventHandler;", name)
|
1995-01-30 07:53:55 -04: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 12:58:33 -04:00
|
|
|
def cleanup(self, name):
|
|
|
|
Output("Py_INCREF(%s); /* XXX leak, but needed */", name)
|
1995-01-30 07:53:55 -04:00
|
|
|
|
|
|
|
class EHNoRefConType(EHType):
|
|
|
|
def passInput(self, name):
|
1995-02-05 12:58:33 -04:00
|
|
|
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")
|
|
|
|
|
|
|
|
|
|
|
|
AEFunction = OSErrFunctionGenerator
|
|
|
|
AEMethod = OSErrMethodGenerator
|
|
|
|
|
|
|
|
|
|
|
|
includestuff = includestuff + """
|
|
|
|
#include <AppleEvents.h>
|
|
|
|
|
1995-02-14 05:48:02 -04:00
|
|
|
#ifndef HAVE_UNIVERSAL_HEADERS
|
1995-02-05 12:58:33 -04:00
|
|
|
#define AEIdleProcPtr IdleProcPtr
|
1995-01-30 07:53:55 -04:00
|
|
|
#define AEFilterProcPtr EventFilterProcPtr
|
|
|
|
#define AEEventHandlerProcPtr EventHandlerProcPtr
|
|
|
|
#endif
|
|
|
|
|
1995-02-14 05:48:02 -04:00
|
|
|
#ifndef HAVE_UNIVERSAL_HEADERS
|
|
|
|
/* I'm trying to setup the code here so that is easily automated,
|
1995-02-05 12:58:33 -04:00
|
|
|
** as follows:
|
|
|
|
** - Use the UPP in the source
|
|
|
|
** - for pre-universal headers, #define each UPP as the corresponding ProcPtr
|
|
|
|
** - for each routine we pass we declare a upp_xxx that
|
|
|
|
** we initialize to the correct value in the init routine.
|
|
|
|
*/
|
|
|
|
#define AEIdleUPP AEIdleProcPtr
|
|
|
|
#define AEFilterUPP AEFilterProcPtr
|
|
|
|
#define AEEventHandlerUPP AEEventHandlerProcPtr
|
|
|
|
#define NewAEIdleProc(x) (x)
|
|
|
|
#define NewAEFilterProc(x) (x)
|
|
|
|
#define NewAEEventHandlerProc(x) (x)
|
|
|
|
#endif
|
|
|
|
|
1995-01-30 07:53:55 -04:00
|
|
|
static pascal OSErr GenericEventHandler(); /* Forward */
|
|
|
|
|
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)
|
|
|
|
{
|
1997-06-20 13:19:14 -03:00
|
|
|
if ( PyOS_InterruptOccurred() )
|
|
|
|
return 1;
|
|
|
|
if ( PyMac_HandleEvent(theEvent) < 0 ) {
|
1998-10-12 17:53:15 -03:00
|
|
|
PySys_WriteStderr("Exception in user event handler during AE processing\\n");
|
1997-06-20 13:19:14 -03:00
|
|
|
PyErr_Clear();
|
|
|
|
}
|
1995-02-05 12:58:33 -04:00
|
|
|
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
|
1995-02-19 11:59:49 -04:00
|
|
|
GenericEventHandler(AppleEvent *request, AppleEvent *reply, long refcon)
|
1995-01-30 07:53:55 -04:00
|
|
|
{
|
|
|
|
PyObject *handler = (PyObject *)refcon;
|
|
|
|
AEDescObject *requestObject, *replyObject;
|
|
|
|
PyObject *args, *res;
|
|
|
|
if ((requestObject = (AEDescObject *)AEDesc_New(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)
|
|
|
|
return -1;
|
|
|
|
Py_DECREF(res);
|
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
1995-02-05 12:58:33 -04:00
|
|
|
initstuff = initstuff + """
|
|
|
|
upp_AEIdleProc = NewAEIdleProc(AEIdleProc);
|
|
|
|
upp_GenericEventHandler = NewAEEventHandlerProc(GenericEventHandler);
|
|
|
|
"""
|
|
|
|
|
1995-01-30 07:53:55 -04:00
|
|
|
module = MacModule('AE', 'AE', includestuff, finalstuff, initstuff)
|
|
|
|
|
1997-08-15 11:31:13 -03:00
|
|
|
class AEDescDefinition(GlobalObjectDefinition):
|
1995-01-30 07:53:55 -04:00
|
|
|
|
|
|
|
def __init__(self, name, prefix = None, itselftype = None):
|
1997-08-15 11:31:13 -03:00
|
|
|
GlobalObjectDefinition.__init__(self, name, prefix or name, itselftype or name)
|
1995-01-30 07:53:55 -04: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;
|
|
|
|
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);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
if (strcmp(name, "__members__") == 0)
|
|
|
|
return Py_BuildValue("[ss]", "data", "type");
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
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')
|
1998-02-20 12:02:09 -04:00
|
|
|
execfile('aedatamodelgen.py')
|
1995-01-30 07:53:55 -04:00
|
|
|
|
|
|
|
for f in functions: module.add(f)
|
|
|
|
for f in aedescmethods: aedescobject.add(f)
|
|
|
|
|
|
|
|
SetOutputFileName('AEmodule.c')
|
|
|
|
module.generate()
|