1 # This script generates a Python interface for an Apple Macintosh Manager.
2 # It uses the "bgen" package to generate C code.
3 # The function specifications are generated by scanning the mamager's header file,
4 # using the "scantools" package (customized for this particular manager).
6 #error missing SetActionFilter
10 # Declarations that change for each manager
11 MODNAME
= '_CG' # The name of the module
13 # The following is *usually* unchanged but may still require tuning
14 MODPREFIX
= 'CG' # The prefix for module-wide routines
15 INPUTFILE
= string
.lower(MODPREFIX
) + 'gen.py' # The file generated by the scanner
16 OUTPUTFILE
= MODNAME
+ "module.c" # The file generated by this program
18 from macsupport
import *
20 CGrafPtr
= OpaqueByValueType("CGrafPtr", "GrafObj")
21 RgnHandle
= OpaqueByValueType("RgnHandle", "ResObj")
23 # Create the type objects
25 includestuff
= includestuff
+ """
26 #include <ApplicationServices/ApplicationServices.h>
28 extern int GrafObj_Convert(PyObject *, GrafPtr *);
34 PyObject *CGPoint_New(CGPoint *itself)
37 return Py_BuildValue("(ff)",
43 CGPoint_Convert(PyObject *v, CGPoint *p_itself)
45 if( !PyArg_Parse(v, "(ff)",
52 PyObject *CGRect_New(CGRect *itself)
55 return Py_BuildValue("(ffff)",
63 CGRect_Convert(PyObject *v, CGRect *p_itself)
65 if( !PyArg_Parse(v, "(ffff)",
68 &p_itself->size.width,
69 &p_itself->size.height) )
74 PyObject *CGAffineTransform_New(CGAffineTransform *itself)
77 return Py_BuildValue("(ffffff)",
87 CGAffineTransform_Convert(PyObject *v, CGAffineTransform *p_itself)
89 if( !PyArg_Parse(v, "(ffffff)",
101 class MyOpaqueByValueType(OpaqueByValueType
):
102 """Sort of a mix between OpaqueByValueType and OpaqueType."""
103 def mkvalueArgs(self
, name
):
104 return "%s, &%s" % (self
.new
, name
)
106 CGPoint
= MyOpaqueByValueType('CGPoint', 'CGPoint')
107 CGRect
= MyOpaqueByValueType('CGRect', 'CGRect')
108 CGAffineTransform
= MyOpaqueByValueType('CGAffineTransform', 'CGAffineTransform')
110 char_ptr
= Type("char *", "s")
115 CGTextDrawingMode
= int
116 CGPathDrawingMode
= int
117 CGInterpolationQuality
= int
120 CGContextRef
= OpaqueByValueType("CGContextRef", "CGContextRefObj")
123 class MyObjectDefinition(PEP253Mixin
, GlobalObjectDefinition
):
124 def outputStructMembers(self
):
125 ObjectDefinition
.outputStructMembers(self
)
126 def outputCleanupStructMembers(self
):
127 Output("CGContextRelease(self->ob_itself);")
130 # Create the generator groups and link them
131 module
= MacModule(MODNAME
, MODPREFIX
, includestuff
, finalstuff
, initstuff
)
133 CGContextRef_object
= MyObjectDefinition('CGContextRef', 'CGContextRefObj', 'CGContextRef')
138 module
.addobject(CGContextRef_object
)
142 Function
= FunctionGenerator
143 Method
= MethodGenerator
145 CGContextRef_methods
= []
147 # ADD _methods initializer here
150 # manual method, lives in Quickdraw.h
151 f
= Method(void
, 'SyncCGContextOriginWithPort',
152 (CGContextRef
, 'ctx', InMode
),
153 (CGrafPtr
, 'port', InMode
),
155 CGContextRef_methods
.append(f
)
157 # manual method, lives in Quickdraw.h
158 f
= Method(void
, 'ClipCGContextToRegion',
159 (CGContextRef
, 'ctx', InMode
),
160 (Rect
, 'portRect', InMode
),
161 (RgnHandle
, 'region', InMode
),
163 CGContextRef_methods
.append(f
)
166 CreateCGContextForPort_body
= """\
171 if (!PyArg_ParseTuple(_args, "O&", GrafObj_Convert, &port))
174 _err = CreateCGContextForPort(port, &ctx);
176 if (_err != noErr) return PyMac_Error(_err);
177 _res = Py_BuildValue("O&", CGContextRefObj_New, ctx);
181 f
= ManualGenerator("CreateCGContextForPort", CreateCGContextForPort_body
);
182 f
.docstring
= lambda: "(CGrafPtr) -> CGContextRef"
186 # ADD add forloop here
187 for f
in CGContextRef_methods
:
188 CGContextRef_object
.add(f
)
190 # generate output (open the output file as late as possible)
191 SetOutputFileName(OUTPUTFILE
)