2003-12-03 18:34:19 -04:00
|
|
|
# This script generates a Python interface for an Apple Macintosh Manager.
|
|
|
|
# It uses the "bgen" package to generate C code.
|
|
|
|
# The function specifications are generated by scanning the mamager's header file,
|
|
|
|
# using the "scantools" package (customized for this particular manager).
|
|
|
|
|
|
|
|
import string
|
|
|
|
|
|
|
|
# Declarations that change for each manager
|
2004-07-18 03:16:08 -03:00
|
|
|
MACHEADERFILE = 'OSA.h' # The Apple header file
|
|
|
|
MODNAME = '_OSA' # The name of the module
|
2003-12-03 18:34:19 -04:00
|
|
|
|
|
|
|
# The following is *usually* unchanged but may still require tuning
|
2004-07-18 03:16:08 -03:00
|
|
|
MODPREFIX = 'OSA' # The prefix for module-wide routines
|
|
|
|
OBJECTPREFIX = 'OSAObj' # The prefix for object methods
|
2003-12-03 18:34:19 -04:00
|
|
|
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
|
2004-07-18 03:16:08 -03:00
|
|
|
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
|
2003-12-03 18:34:19 -04:00
|
|
|
|
|
|
|
from macsupport import *
|
|
|
|
|
|
|
|
# Create the type objects
|
|
|
|
|
|
|
|
includestuff = includestuff + """
|
2003-12-09 11:06:18 -04:00
|
|
|
#if PY_VERSION_HEX < 0x02040000
|
|
|
|
PyObject *PyMac_GetOSErrException(void);
|
|
|
|
#endif
|
2003-12-03 18:34:19 -04:00
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
|
|
|
|
#ifdef USE_TOOLBOX_OBJECT_GLUE
|
|
|
|
extern PyObject *_OSAObj_New(ComponentInstance);
|
|
|
|
extern int _OSAObj_Convert(PyObject *, ComponentInstance *);
|
|
|
|
|
|
|
|
#define OSAObj_New _OSAObj_New
|
|
|
|
#define OSAObj_Convert _OSAObj_Convert
|
|
|
|
#endif
|
|
|
|
"""
|
|
|
|
|
|
|
|
initstuff = initstuff + """
|
|
|
|
/*
|
2004-07-18 03:16:08 -03:00
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, OSAObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, OSAObj_Convert);
|
2003-12-03 18:34:19 -04:00
|
|
|
*/
|
|
|
|
"""
|
|
|
|
|
|
|
|
ComponentInstance = OpaqueByValueType('ComponentInstance', OBJECTPREFIX)
|
|
|
|
OSAError = OSErrType("OSAError", "l")
|
2003-12-03 19:20:13 -04:00
|
|
|
# OSALocalOrGlobal = Type("OSALocalOrGlobal", "l")
|
2003-12-03 18:34:19 -04:00
|
|
|
OSAID = Type("OSAID", "l")
|
|
|
|
OSADebugCallFrameRef = Type("OSADebugCallFrameRef", "l")
|
|
|
|
OSADebugSessionRef = Type("OSADebugSessionRef", "l")
|
|
|
|
OSADebugStepKind = Type("OSADebugStepKind", "l")
|
|
|
|
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')
|
|
|
|
|
|
|
|
# NOTE: at the moment OSA.ComponentInstance is not a subclass
|
|
|
|
# of Cm.ComponentInstance. If this is a problem it can be fixed.
|
|
|
|
class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
def outputCheckNewArg(self):
|
|
|
|
Output("""if (itself == NULL) {
|
|
|
|
PyErr_SetString(OSA_Error,"NULL ComponentInstance");
|
|
|
|
return NULL;
|
|
|
|
}""")
|
|
|
|
|
|
|
|
def outputCheckConvertArg(self):
|
|
|
|
Output("""
|
|
|
|
if (CmpInstObj_Convert(v, p_itself))
|
|
|
|
return 1;
|
|
|
|
PyErr_Clear();
|
|
|
|
""")
|
|
|
|
|
2003-12-03 18:34:19 -04:00
|
|
|
|
|
|
|
# Create the generator groups and link them
|
|
|
|
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
|
2003-12-10 11:18:18 -04:00
|
|
|
object = MyObjectDefinition('OSAComponentInstance', OBJECTPREFIX,
|
2004-07-18 03:16:08 -03:00
|
|
|
'ComponentInstance')
|
2003-12-03 18:34:19 -04:00
|
|
|
module.addobject(object)
|
|
|
|
|
|
|
|
# Create the generator classes used to populate the lists
|
|
|
|
Function = OSErrWeakLinkFunctionGenerator
|
|
|
|
Method = OSErrWeakLinkMethodGenerator
|
|
|
|
|
|
|
|
# Test which types we are still missing.
|
|
|
|
execfile(string.lower(MODPREFIX) + 'typetest.py')
|
|
|
|
|
|
|
|
# Create and populate the lists
|
|
|
|
functions = []
|
|
|
|
methods = []
|
|
|
|
execfile(INPUTFILE)
|
|
|
|
|
|
|
|
# add the populated lists to the generator groups
|
|
|
|
# (in a different wordl the scan program would generate this)
|
|
|
|
for f in functions: module.add(f)
|
|
|
|
for f in methods: object.add(f)
|
|
|
|
|
|
|
|
# generate output (open the output file as late as possible)
|
|
|
|
SetOutputFileName(OUTPUTFILE)
|
|
|
|
module.generate()
|