Import Upstream version 2.7.18
This commit is contained in:
24
Mac/Modules/ae/README
Normal file
24
Mac/Modules/ae/README
Normal file
@@ -0,0 +1,24 @@
|
||||
A quick note on what all the files here are, currently (16-7-95),
|
||||
and whether they really are source or generated.
|
||||
|
||||
aegen.py Generated by aescan, temporary file
|
||||
AEModule.c Generated by aescan, from AppleEvents.h
|
||||
AEObjects.py Generated by aescan, from AEObjects.h
|
||||
aepack.py Routines to convert python objects <-> AEDesc record
|
||||
(formerly part of aetools, now imported there)
|
||||
AERegistry.py Generated by aescan, from AERegistry.h
|
||||
aescan.py Program to scan headers and generate AE modules
|
||||
aesupport.py Helper code for aescan
|
||||
aetools.py Routines/classes to create and send appleevents
|
||||
aetypes.py Classes for python objects corresponding to AEDesc types
|
||||
(formerly part of aetools, now imported there)
|
||||
AppleEvents.py Generated by aescan, from AppleEvents.h
|
||||
AppleScript_Suite.py Generated by gensuitemodule
|
||||
echo.py Old test program (may still work) to echo events back to sender
|
||||
gensuitemodule.py Program to scan aete/aeut resources and generate python
|
||||
interface modules
|
||||
Required_Suite.py Generated by gensuitemodule
|
||||
Standard_Suite.py Generated by gensuitemodule
|
||||
tae.py Old test program (may still work) to send an appleevent
|
||||
tell.py Old test program (may still work) to send an appleevent
|
||||
test_suite.py Test program to test bits of the _Suite modules and aetools/etc
|
||||
1459
Mac/Modules/ae/_AEmodule.c
Normal file
1459
Mac/Modules/ae/_AEmodule.c
Normal file
File diff suppressed because it is too large
Load Diff
97
Mac/Modules/ae/aescan.py
Normal file
97
Mac/Modules/ae/aescan.py
Normal file
@@ -0,0 +1,97 @@
|
||||
# Scan AppleEvents.h header file, generate aegen.py and AppleEvents.py files.
|
||||
# Then run aesupport to generate AEmodule.c.
|
||||
# (Should learn how to tell the compiler to compile it as well.)
|
||||
|
||||
import sys
|
||||
import MacOS
|
||||
|
||||
from bgenlocations import TOOLBOXDIR, BGENDIR
|
||||
sys.path.append(BGENDIR)
|
||||
|
||||
from scantools import Scanner
|
||||
|
||||
def main():
|
||||
print "=== Scanning AEDataModel.h, AppleEvents.h, AERegistry.h, AEObjects.h ==="
|
||||
input = ["AEDataModel.h", "AEInteraction.h", "AppleEvents.h", "AERegistry.h", "AEObjects.h"]
|
||||
output = "aegen.py"
|
||||
defsoutput = TOOLBOXDIR + "AppleEvents.py"
|
||||
scanner = AppleEventsScanner(input, output, defsoutput)
|
||||
scanner.scan()
|
||||
scanner.close()
|
||||
print "=== Testing definitions output code ==="
|
||||
execfile(defsoutput, {}, {})
|
||||
print "=== Done Scanning and Generating, now doing 'import aesupport' ==="
|
||||
import aesupport
|
||||
print "=== Done 'import aesupport'. It's up to you to compile AEmodule.c ==="
|
||||
|
||||
class AppleEventsScanner(Scanner):
|
||||
|
||||
def destination(self, type, name, arglist):
|
||||
classname = "AEFunction"
|
||||
listname = "functions"
|
||||
if arglist:
|
||||
t, n, m = arglist[0]
|
||||
if t[-4:] == "_ptr" and m == "InMode" and \
|
||||
t[:-4] in ("AEDesc", "AEAddressDesc", "AEDescList",
|
||||
"AERecord", "AppleEvent"):
|
||||
classname = "AEMethod"
|
||||
listname = "aedescmethods"
|
||||
return classname, listname
|
||||
|
||||
def makeblacklistnames(self):
|
||||
return [
|
||||
"AEDisposeDesc",
|
||||
# "AEGetEventHandler",
|
||||
"AEGetDescData", # Use object.data
|
||||
"AEGetSpecialHandler",
|
||||
# Constants with funny definitions
|
||||
"kAEDontDisposeOnResume",
|
||||
"kAEUseStandardDispatch",
|
||||
]
|
||||
|
||||
def makeblacklisttypes(self):
|
||||
return [
|
||||
"ProcPtr",
|
||||
"AEArrayType",
|
||||
"AECoercionHandlerUPP",
|
||||
"UniversalProcPtr",
|
||||
"OSLCompareUPP",
|
||||
"OSLAccessorUPP",
|
||||
]
|
||||
|
||||
def makerepairinstructions(self):
|
||||
return [
|
||||
([("Boolean", "isSysHandler", "InMode")],
|
||||
[("AlwaysFalse", "*", "*")]),
|
||||
|
||||
([("void_ptr", "*", "InMode"), ("Size", "*", "InMode")],
|
||||
[("InBuffer", "*", "*")]),
|
||||
|
||||
([("EventHandlerProcPtr", "*", "InMode"), ("long", "*", "InMode")],
|
||||
[("EventHandler", "*", "*")]),
|
||||
|
||||
([("EventHandlerProcPtr", "*", "OutMode"), ("long", "*", "OutMode")],
|
||||
[("EventHandler", "*", "*")]),
|
||||
|
||||
([("AEEventHandlerUPP", "*", "InMode"), ("long", "*", "InMode")],
|
||||
[("EventHandler", "*", "*")]),
|
||||
|
||||
([("AEEventHandlerUPP", "*", "OutMode"), ("long", "*", "OutMode")],
|
||||
[("EventHandler", "*", "*")]),
|
||||
|
||||
([("void", "*", "OutMode"), ("Size", "*", "InMode"),
|
||||
("Size", "*", "OutMode")],
|
||||
[("VarVarOutBuffer", "*", "InOutMode")]),
|
||||
|
||||
([("AppleEvent", "theAppleEvent", "OutMode")],
|
||||
[("AppleEvent_ptr", "*", "InMode")]),
|
||||
|
||||
([("AEDescList", "theAEDescList", "OutMode")],
|
||||
[("AEDescList_ptr", "*", "InMode")]),
|
||||
]
|
||||
|
||||
def writeinitialdefs(self):
|
||||
self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
237
Mac/Modules/ae/aesupport.py
Normal file
237
Mac/Modules/ae/aesupport.py
Normal file
@@ -0,0 +1,237 @@
|
||||
# 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")
|
||||
AEReturnID = Type("AEReturnID", "h")
|
||||
AETransactionID = Type("AETransactionID", "l")
|
||||
|
||||
|
||||
|
||||
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):
|
||||
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)
|
||||
|
||||
class EHNoRefConType(EHType):
|
||||
def passInput(self, name):
|
||||
return "upp_GenericEventHandler"
|
||||
|
||||
EventHandler = EHType()
|
||||
EventHandlerNoRefCon = EHNoRefConType()
|
||||
|
||||
|
||||
IdleProcPtr = FakeType("upp_AEIdleProc")
|
||||
AEIdleUPP = IdleProcPtr
|
||||
EventFilterProcPtr = FakeType("(AEFilterUPP)0")
|
||||
AEFilterUPP = EventFilterProcPtr
|
||||
NMRecPtr = FakeType("(NMRecPtr)0")
|
||||
EventHandlerProcPtr = FakeType("upp_GenericEventHandler")
|
||||
AEEventHandlerUPP = EventHandlerProcPtr
|
||||
AlwaysFalse = FakeType("0")
|
||||
|
||||
|
||||
AEFunction = OSErrWeakLinkFunctionGenerator
|
||||
AEMethod = OSErrWeakLinkMethodGenerator
|
||||
|
||||
|
||||
includestuff = includestuff + """
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
#ifdef USE_TOOLBOX_OBJECT_GLUE
|
||||
extern PyObject *_AEDesc_New(AEDesc *);
|
||||
extern int _AEDesc_Convert(PyObject *, AEDesc *);
|
||||
|
||||
#define AEDesc_New _AEDesc_New
|
||||
#define AEDesc_NewBorrowed _AEDesc_NewBorrowed
|
||||
#define AEDesc_Convert _AEDesc_Convert
|
||||
#endif
|
||||
|
||||
typedef long refcontype;
|
||||
|
||||
static pascal OSErr GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon); /* Forward */
|
||||
|
||||
AEEventHandlerUPP upp_GenericEventHandler;
|
||||
|
||||
static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn)
|
||||
{
|
||||
if ( PyOS_InterruptOccurred() )
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
AEIdleUPP upp_AEIdleProc;
|
||||
"""
|
||||
|
||||
finalstuff = finalstuff + """
|
||||
static pascal OSErr
|
||||
GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
PyObject *AEDesc_NewBorrowed(AEDesc *itself)
|
||||
{
|
||||
PyObject *it;
|
||||
|
||||
it = AEDesc_New(itself);
|
||||
if (it)
|
||||
((AEDescObject *)it)->ob_owned = 0;
|
||||
return (PyObject *)it;
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
initstuff = initstuff + """
|
||||
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);
|
||||
"""
|
||||
|
||||
module = MacModule('_AE', 'AE', includestuff, finalstuff, initstuff)
|
||||
|
||||
class AEDescDefinition(PEP253Mixin, GlobalObjectDefinition):
|
||||
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);")
|
||||
|
||||
aedescobject = AEDescDefinition('AEDesc')
|
||||
module.addobject(aedescobject)
|
||||
|
||||
functions = []
|
||||
aedescmethods = []
|
||||
|
||||
execfile('aegen.py')
|
||||
##execfile('aedatamodelgen.py')
|
||||
|
||||
# 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)
|
||||
|
||||
for f in functions: module.add(f)
|
||||
for f in aedescmethods: aedescobject.add(f)
|
||||
|
||||
SetOutputFileName('_AEmodule.c')
|
||||
module.generate()
|
||||
Reference in New Issue
Block a user