1996-04-10 11:41:08 -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).
|
|
|
|
|
|
|
|
import string
|
|
|
|
|
|
|
|
# Declarations that change for each manager
|
2004-07-18 03:16:08 -03:00
|
|
|
MACHEADERFILE = 'TextEdit.h' # The Apple header file
|
|
|
|
MODNAME = '_TE' # The name of the module
|
|
|
|
OBJECTNAME = 'TE' # The basic name of the objects used here
|
|
|
|
KIND = 'Handle' # Usually 'Ptr' or 'Handle'
|
1996-04-10 11:41:08 -03:00
|
|
|
|
|
|
|
# The following is *usually* unchanged but may still require tuning
|
2004-07-18 03:16:08 -03:00
|
|
|
MODPREFIX = 'TE' # The prefix for module-wide routines
|
|
|
|
OBJECTTYPE = "TEHandle" # The C type used to represent them
|
|
|
|
OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
|
1996-04-10 11:41:08 -03: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
|
1996-04-10 11:41:08 -03:00
|
|
|
|
|
|
|
from macsupport import *
|
|
|
|
|
|
|
|
# Create the type objects
|
|
|
|
TEHandle = OpaqueByValueType("TEHandle", "TEObj")
|
|
|
|
CharsHandle = OpaqueByValueType("CharsHandle", "ResObj")
|
1999-12-23 10:32:06 -04:00
|
|
|
Handle = OpaqueByValueType("Handle", "ResObj")
|
1996-04-10 11:41:08 -03:00
|
|
|
StScrpHandle = OpaqueByValueType("StScrpHandle", "ResObj")
|
|
|
|
TEStyleHandle = OpaqueByValueType("TEStyleHandle", "ResObj")
|
|
|
|
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
|
|
|
|
|
|
|
|
TextStyle = OpaqueType("TextStyle", "TextStyle")
|
|
|
|
TextStyle_ptr = TextStyle
|
|
|
|
|
|
|
|
includestuff = includestuff + """
|
2001-05-22 18:56:42 -03:00
|
|
|
#include <Carbon/Carbon.h>
|
1996-04-10 11:41:08 -03:00
|
|
|
|
2001-05-17 18:58:34 -03:00
|
|
|
#ifdef USE_TOOLBOX_OBJECT_GLUE
|
|
|
|
extern PyObject *_TEObj_New(TEHandle);
|
|
|
|
extern int _TEObj_Convert(PyObject *, TEHandle *);
|
|
|
|
|
|
|
|
#define TEObj_New _TEObj_New
|
|
|
|
#define TEObj_Convert _TEObj_Convert
|
|
|
|
#endif
|
|
|
|
|
1999-12-23 10:32:06 -04:00
|
|
|
#define as_TE(h) ((TEHandle)h)
|
|
|
|
#define as_Resource(teh) ((Handle)teh)
|
|
|
|
|
1996-04-10 11:41:08 -03:00
|
|
|
/*
|
|
|
|
** Parse/generate TextStyle records
|
|
|
|
*/
|
2000-07-14 19:16:45 -03:00
|
|
|
static PyObject *
|
2001-05-22 18:56:42 -03:00
|
|
|
TextStyle_New(TextStylePtr itself)
|
1996-04-10 11:41:08 -03:00
|
|
|
{
|
|
|
|
|
2004-07-18 03:16:08 -03:00
|
|
|
return Py_BuildValue("lllO&", (long)itself->tsFont, (long)itself->tsFace, (long)itself->tsSize, QdRGB_New,
|
|
|
|
&itself->tsColor);
|
1996-04-10 11:41:08 -03:00
|
|
|
}
|
|
|
|
|
2000-07-14 19:16:45 -03:00
|
|
|
static int
|
2001-05-22 18:56:42 -03:00
|
|
|
TextStyle_Convert(PyObject *v, TextStylePtr p_itself)
|
1996-04-10 11:41:08 -03:00
|
|
|
{
|
2004-07-18 03:16:08 -03:00
|
|
|
long font, face, size;
|
|
|
|
|
|
|
|
if( !PyArg_ParseTuple(v, "lllO&", &font, &face, &size, QdRGB_Convert, &p_itself->tsColor) )
|
|
|
|
return 0;
|
|
|
|
p_itself->tsFont = (short)font;
|
|
|
|
p_itself->tsFace = (Style)face;
|
|
|
|
p_itself->tsSize = (short)size;
|
|
|
|
return 1;
|
1996-04-10 11:41:08 -03:00
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2001-05-17 18:58:34 -03:00
|
|
|
initstuff = initstuff + """
|
2004-07-18 03:16:08 -03:00
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_NEW(TEHandle, TEObj_New);
|
|
|
|
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(TEHandle, TEObj_Convert);
|
2001-05-17 18:58:34 -03:00
|
|
|
"""
|
|
|
|
|
2002-03-24 20:32:17 -04:00
|
|
|
class TEMethodGenerator(OSErrWeakLinkMethodGenerator):
|
2004-07-18 03:16:08 -03:00
|
|
|
"""Similar to MethodGenerator, but has self as last argument"""
|
1996-04-10 11:41:08 -03:00
|
|
|
|
2004-07-18 03:16:08 -03:00
|
|
|
def parseArgumentList(self, args):
|
|
|
|
args, a0 = args[:-1], args[-1]
|
|
|
|
t0, n0, m0 = a0
|
|
|
|
if m0 != InMode:
|
2007-08-22 20:05:23 -03:00
|
|
|
raise ValueError("method's 'self' must be 'InMode'")
|
2004-07-18 03:16:08 -03:00
|
|
|
self.itself = Variable(t0, "_self->ob_itself", SelfMode)
|
|
|
|
FunctionGenerator.parseArgumentList(self, args)
|
|
|
|
self.argumentList.append(self.itself)
|
1996-04-10 11:41:08 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-12-03 19:40:22 -04:00
|
|
|
class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
|
2004-07-18 03:16:08 -03:00
|
|
|
# XXXX Could be subtype of Resource
|
|
|
|
# Attributes that can be set.
|
|
|
|
getsetlist = [
|
|
|
|
(
|
|
|
|
'destRect',
|
|
|
|
'return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->destRect);',
|
|
|
|
None,
|
|
|
|
'Destination rectangle'
|
|
|
|
), (
|
|
|
|
'viewRect',
|
|
|
|
'return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->viewRect);',
|
|
|
|
None,
|
|
|
|
'Viewing rectangle'
|
|
|
|
), (
|
|
|
|
'selRect',
|
|
|
|
'return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->selRect);',
|
|
|
|
None,
|
|
|
|
'Selection rectangle'
|
|
|
|
), (
|
|
|
|
'lineHeight',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->lineHeight);',
|
|
|
|
None,
|
|
|
|
'Height of a line'
|
|
|
|
), (
|
|
|
|
'fontAscent',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->fontAscent);',
|
|
|
|
None,
|
|
|
|
'Ascent of a line'
|
|
|
|
), (
|
|
|
|
"selPoint",
|
|
|
|
'return Py_BuildValue("O&", PyMac_BuildPoint, (*self->ob_itself)->selPoint);',
|
|
|
|
None,
|
|
|
|
'Selection Point'
|
|
|
|
), (
|
|
|
|
'selStart',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->selStart);',
|
|
|
|
None,
|
|
|
|
'Start of selection'
|
|
|
|
), (
|
|
|
|
'selEnd',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->selEnd);',
|
|
|
|
None,
|
|
|
|
'End of selection'
|
|
|
|
), (
|
|
|
|
'active',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->active);',
|
|
|
|
None,
|
|
|
|
'TBD'
|
|
|
|
), (
|
|
|
|
'just',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->just);',
|
|
|
|
None,
|
|
|
|
'Justification'
|
|
|
|
), (
|
|
|
|
'teLength',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->teLength);',
|
|
|
|
None,
|
|
|
|
'TBD'
|
|
|
|
), (
|
|
|
|
'txFont',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->txFont);',
|
|
|
|
None,
|
|
|
|
'Current font'
|
|
|
|
), (
|
|
|
|
'txFace',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->txFace);',
|
|
|
|
None,
|
|
|
|
'Current font variant'
|
|
|
|
), (
|
|
|
|
'txMode',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->txMode);',
|
|
|
|
None,
|
|
|
|
'Current text-drawing mode'
|
|
|
|
), (
|
|
|
|
'txSize',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->txSize);',
|
|
|
|
None,
|
|
|
|
'Current font size'
|
|
|
|
), (
|
|
|
|
'nLines',
|
|
|
|
'return Py_BuildValue("h", (*self->ob_itself)->nLines);',
|
|
|
|
None,
|
|
|
|
'TBD'
|
|
|
|
)]
|
|
|
|
|
|
|
|
def outputCheckNewArg(self):
|
|
|
|
Output("""if (itself == NULL) {
|
|
|
|
PyErr_SetString(TE_Error,"Cannot create null TE");
|
|
|
|
return NULL;
|
|
|
|
}""")
|
|
|
|
def outputFreeIt(self, itselfname):
|
|
|
|
Output("TEDispose(%s);", itselfname)
|
|
|
|
|
1996-04-10 11:41:08 -03:00
|
|
|
|
|
|
|
# From here on it's basically all boiler plate...
|
|
|
|
|
|
|
|
# Create the generator groups and link them
|
|
|
|
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
|
|
|
|
object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
|
|
|
|
module.addobject(object)
|
|
|
|
|
|
|
|
# Create the generator classes used to populate the lists
|
2002-03-24 20:32:17 -04:00
|
|
|
Function = OSErrWeakLinkFunctionGenerator
|
1996-04-10 11:41:08 -03:00
|
|
|
Method = TEMethodGenerator
|
|
|
|
|
|
|
|
# Create and populate the lists
|
|
|
|
functions = []
|
|
|
|
methods = []
|
2007-08-11 21:43:29 -03:00
|
|
|
exec(open(INPUTFILE).read())
|
1996-04-10 11:41:08 -03:00
|
|
|
|
1999-12-23 10:32:06 -04:00
|
|
|
# Converter from/to handle
|
|
|
|
f = Function(TEHandle, 'as_TE', (Handle, 'h', InMode))
|
|
|
|
functions.append(f)
|
|
|
|
f = Method(Handle, 'as_Resource', (TEHandle, 'teh', InMode))
|
|
|
|
methods.append(f)
|
|
|
|
|
1996-04-10 11:41:08 -03:00
|
|
|
# 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()
|