2001-07-13 17:56:52 -03: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).
|
|
|
|
|
|
|
|
#error missing SetActionFilter
|
|
|
|
|
|
|
|
import string
|
|
|
|
|
|
|
|
# Declarations that change for each manager
|
2001-08-23 10:51:46 -03:00
|
|
|
MODNAME = '_Mlte' # The name of the module
|
2001-07-13 17:56:52 -03:00
|
|
|
|
|
|
|
# The following is *usually* unchanged but may still require tuning
|
2001-08-23 10:51:46 -03:00
|
|
|
MODPREFIX = 'Mlte' # The prefix for module-wide routines
|
2001-07-13 17:56:52 -03:00
|
|
|
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
|
|
|
|
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
|
|
|
|
|
|
|
|
from macsupport import *
|
|
|
|
|
|
|
|
# Create the type objects
|
|
|
|
|
|
|
|
includestuff = includestuff + """
|
|
|
|
#ifdef WITHOUT_FRAMEWORKS
|
|
|
|
#include <MacTextEditor.h>
|
|
|
|
#else
|
2001-09-01 20:38:13 -03:00
|
|
|
#include <Carbon/Carbon.h>
|
2001-07-13 17:56:52 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* For now we declare them forward here. They'll go to mactoolbox later */
|
2002-08-05 12:36:57 -03:00
|
|
|
static PyObject *TXNObj_New(TXNObject);
|
|
|
|
static int TXNObj_Convert(PyObject *, TXNObject *);
|
|
|
|
static PyObject *TXNFontMenuObj_New(TXNFontMenuObject);
|
|
|
|
static int TXNFontMenuObj_Convert(PyObject *, TXNFontMenuObject *);
|
2001-07-13 17:56:52 -03:00
|
|
|
|
|
|
|
// ADD declarations
|
|
|
|
#ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
|
|
|
|
//extern PyObject *_CFTypeRefObj_New(CFTypeRef);
|
|
|
|
//extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
|
|
|
|
|
|
|
|
//#define CFTypeRefObj_New _CFTypeRefObj_New
|
|
|
|
//#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2001-07-13 19:27:20 -03:00
|
|
|
** Parse an optional fsspec
|
2001-07-13 17:56:52 -03:00
|
|
|
*/
|
2001-07-13 19:27:20 -03:00
|
|
|
static int
|
|
|
|
OptFSSpecPtr_Convert(PyObject *v, FSSpec **p_itself)
|
|
|
|
{
|
|
|
|
static FSSpec fss;
|
|
|
|
if (v == Py_None)
|
|
|
|
{
|
|
|
|
*p_itself = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
*p_itself = &fss;
|
|
|
|
return PyMac_GetFSSpec(v, *p_itself);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Parse an optional rect
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
OptRectPtr_Convert(PyObject *v, Rect **p_itself)
|
|
|
|
{
|
|
|
|
static Rect r;
|
|
|
|
|
|
|
|
if (v == Py_None)
|
|
|
|
{
|
|
|
|
*p_itself = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
*p_itself = &r;
|
|
|
|
return PyMac_GetRect(v, *p_itself);
|
|
|
|
}
|
2001-07-13 17:56:52 -03:00
|
|
|
|
2001-07-16 18:58:44 -03:00
|
|
|
/*
|
|
|
|
** Parse an optional GWorld
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
OptGWorldObj_Convert(PyObject *v, GWorldPtr *p_itself)
|
|
|
|
{
|
|
|
|
if (v == Py_None)
|
|
|
|
{
|
|
|
|
*p_itself = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return GWorldObj_Convert(v, p_itself);
|
|
|
|
}
|
|
|
|
|
2001-07-13 17:56:52 -03:00
|
|
|
"""
|
|
|
|
|
|
|
|
initstuff = initstuff + """
|
|
|
|
// PyMac_INIT_TOOLBOX_OBJECT_NEW(xxxx);
|
|
|
|
"""
|
|
|
|
TXNObject = OpaqueByValueType("TXNObject", "TXNObj")
|
|
|
|
TXNFontMenuObject = OpaqueByValueType("TXNFontMenuObject", "TXNFontMenuObj")
|
|
|
|
|
|
|
|
TXNFrameID = Type("TXNFrameID", "l")
|
|
|
|
TXNVersionValue = Type("TXNVersionValue", "l")
|
|
|
|
TXNFeatureBits = Type("TXNFeatureBits", "l")
|
|
|
|
TXNInitOptions = Type("TXNInitOptions", "l")
|
|
|
|
TXNFrameOptions = Type("TXNFrameOptions", "l")
|
|
|
|
TXNContinuousFlags = Type("TXNContinuousFlags", "l")
|
|
|
|
TXNMatchOptions = Type("TXNMatchOptions", "l")
|
|
|
|
TXNFileType = OSTypeType("TXNFileType")
|
|
|
|
TXNFrameType = Type("TXNFrameType", "l")
|
|
|
|
TXNDataType = OSTypeType("TXNDataType")
|
|
|
|
TXNControlTag = OSTypeType("TXNControlTag")
|
|
|
|
TXNActionKey = Type("TXNActionKey", "l")
|
|
|
|
TXNTabType = Type("TXNTabType", "b")
|
|
|
|
TXNScrollBarState = Type("TXNScrollBarState", "l")
|
|
|
|
TXNOffset = Type("TXNOffset", "l")
|
|
|
|
TXNObjectRefcon = FakeType("(TXNObjectRefcon)0") # XXXX For now...
|
|
|
|
TXNErrors = OSErrType("TXNErrors", "l")
|
|
|
|
TXNTypeRunAttributes = OSTypeType("TXNTypeRunAttributes")
|
|
|
|
TXNTypeRunAttributeSizes = Type("TXNTypeRunAttributeSizes", "l")
|
|
|
|
TXNPermanentTextEncodingType = Type("TXNPermanentTextEncodingType", "l")
|
|
|
|
TXTNTag = OSTypeType("TXTNTag")
|
|
|
|
TXNBackgroundType = Type("TXNBackgroundType", "l")
|
|
|
|
DragReference = OpaqueByValueType("DragReference", "DragObj")
|
|
|
|
DragTrackingMessage = Type("DragTrackingMessage", "h")
|
|
|
|
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
|
2001-07-14 11:00:50 -03:00
|
|
|
OptRgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
|
2001-07-13 17:56:52 -03:00
|
|
|
GWorldPtr = OpaqueByValueType("GWorldPtr", "GWorldObj")
|
2001-07-16 18:58:44 -03:00
|
|
|
OptGWorldPtr = OpaqueByValueType("GWorldPtr", "OptGWorldObj")
|
2001-07-13 17:56:52 -03:00
|
|
|
MlteInBuffer = VarInputBufferType('void *', 'ByteCount', 'l')
|
|
|
|
|
2001-07-13 19:27:20 -03:00
|
|
|
OptFSSpecPtr = OpaqueByValueType("FSSpec *", "OptFSSpecPtr")
|
|
|
|
OptRectPtr = OpaqueByValueType("Rect *", "OptRectPtr")
|
2002-01-01 18:43:13 -04:00
|
|
|
|
|
|
|
UniChar = Type("UniChar", "h") # XXXX For now...
|
2001-07-13 17:56:52 -03:00
|
|
|
# ADD object type here
|
|
|
|
|
|
|
|
execfile("mltetypetest.py")
|
|
|
|
|
|
|
|
# Our (opaque) objects
|
|
|
|
|
2002-12-03 19:40:22 -04:00
|
|
|
class TXNObjDefinition(PEP253Mixin, GlobalObjectDefinition):
|
2001-07-13 17:56:52 -03:00
|
|
|
def outputCheckNewArg(self):
|
|
|
|
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
|
|
|
|
|
2002-12-03 19:40:22 -04:00
|
|
|
class TXNFontMenuObjDefinition(PEP253Mixin, GlobalObjectDefinition):
|
2001-07-13 17:56:52 -03:00
|
|
|
def outputCheckNewArg(self):
|
|
|
|
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
|
|
|
|
|
|
|
|
|
|
|
|
# ADD object class here
|
|
|
|
|
|
|
|
# From here on it's basically all boiler plate...
|
|
|
|
|
|
|
|
# Create the generator groups and link them
|
|
|
|
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
|
|
|
|
TXNObject_object = TXNObjDefinition("TXNObject", "TXNObj", "TXNObject")
|
|
|
|
TXNFontMenuObject_object = TXNFontMenuObjDefinition("TXNFontMenuObject", "TXNFontMenuObj", "TXNFontMenuObject")
|
|
|
|
|
|
|
|
# ADD object here
|
|
|
|
|
|
|
|
module.addobject(TXNObject_object)
|
|
|
|
module.addobject(TXNFontMenuObject_object)
|
|
|
|
# ADD addobject call here
|
|
|
|
|
|
|
|
# Create the generator classes used to populate the lists
|
|
|
|
Function = OSErrWeakLinkFunctionGenerator
|
|
|
|
Method = OSErrWeakLinkMethodGenerator
|
|
|
|
|
|
|
|
# Create and populate the lists
|
|
|
|
functions = []
|
|
|
|
TXNObject_methods = []
|
|
|
|
TXNFontMenuObject_methods = []
|
|
|
|
|
|
|
|
# ADD _methods initializer here
|
|
|
|
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 TXNObject_methods: TXNObject_object.add(f)
|
|
|
|
for f in TXNFontMenuObject_methods: TXNFontMenuObject_object.add(f)
|
|
|
|
|
|
|
|
# ADD Manual generators here
|
2001-07-13 19:27:20 -03:00
|
|
|
inittextension_body = """
|
|
|
|
OSStatus _err;
|
|
|
|
TXNMacOSPreferredFontDescription * iDefaultFonts = NULL;
|
|
|
|
ItemCount iCountDefaultFonts = 0;
|
|
|
|
TXNInitOptions iUsageFlags;
|
|
|
|
PyMac_PRECHECK(TXNInitTextension);
|
|
|
|
if (!PyArg_ParseTuple(_args, "l", &iUsageFlags))
|
|
|
|
return NULL;
|
|
|
|
_err = TXNInitTextension(iDefaultFonts,
|
|
|
|
iCountDefaultFonts,
|
|
|
|
iUsageFlags);
|
|
|
|
if (_err != noErr) return PyMac_Error(_err);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
_res = Py_None;
|
|
|
|
return _res;
|
|
|
|
"""
|
|
|
|
|
|
|
|
f = ManualGenerator("TXNInitTextension", inittextension_body);
|
|
|
|
f.docstring = lambda: "(TXNInitOptions) -> None"
|
|
|
|
module.add(f)
|
2001-07-13 17:56:52 -03:00
|
|
|
|
|
|
|
# generate output (open the output file as late as possible)
|
|
|
|
SetOutputFileName(OUTPUTFILE)
|
|
|
|
module.generate()
|
|
|
|
|