ยปCore Development>Code coverage>Mac/Modules/icn/icnsupport.py

Python code coverage for Mac/Modules/icn/icnsupport.py

#countcontent
1n/a# This script generates a Python interface for an Apple Macintosh Manager.
2n/a# It uses the "bgen" package to generate C code.
3n/a# The function specifications are generated by scanning the mamager's header file,
4n/a# using the "scantools" package (customized for this particular manager).
5n/a
6n/aimport string
7n/a
8n/a# Declarations that change for each manager
9n/aMACHEADERFILE = 'Icons.h' # The Apple header file
10n/aMODNAME = '_Icn' # The name of the module
11n/aOBJECTNAME = 'Icon' # The basic name of the objects used here
12n/aKIND = 'Handle' # Usually 'Ptr' or 'Handle'
13n/a
14n/a# The following is *usually* unchanged but may still require tuning
15n/aMODPREFIX = 'Icn' # The prefix for module-wide routines
16n/aOBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
17n/aOBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
18n/aINPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
19n/aOUTPUTFILE = MODNAME + "module.c" # The file generated by this program
20n/a
21n/afrom macsupport import *
22n/a
23n/a# Create the type objects
24n/aCIconHandle = OpaqueByValueType("CIconHandle", "ResObj")
25n/aIconSuiteRef = OpaqueByValueType("IconSuiteRef", "ResObj")
26n/aIconCacheRef = OpaqueByValueType("IconCacheRef", "ResObj")
27n/aIconRef = OpaqueByValueType("IconRef", "ResObj")
28n/aIconFamilyHandle = OpaqueByValueType("IconFamilyHandle", "ResObj")
29n/aRgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
30n/aIconAlignmentType = Type("IconAlignmentType", "h")
31n/aIconTransformType = Type("IconTransformType", "h")
32n/aIconSelectorValue = Type("IconSelectorValue", "l")
33n/aIconServicesUsageFlags = Type("IconServicesUsageFlags", "l")
34n/aRGBColor = OpaqueType("RGBColor", "QdRGB")
35n/aCGContextRef = OpaqueByValueType("CGContextRef", "CGContextRefObj")
36n/a
37n/a#WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
38n/a
39n/a# RgnHandle = FakeType("(RgnHandle)0")
40n/a# XXXX Should be next, but this will break a lot of code...
41n/a# RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
42n/a
43n/a# KeyMap = ArrayOutputBufferType("KeyMap")
44n/a#MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
45n/a#MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
46n/a#EventMask = Type("EventMask", "H")
47n/a#EventKind = Type("EventKind", "H")
48n/a
49n/aincludestuff = includestuff + """
50n/a#include <Carbon/Carbon.h>
51n/a
52n/a"""
53n/a
54n/aclass MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
55n/a def outputCheckNewArg(self):
56n/a Output("if (itself == NULL) return PyMac_Error(resNotFound);")
57n/a def outputCheckConvertArg(self):
58n/a OutLbrace("if (DlgObj_Check(v))")
59n/a Output("*p_itself = ((WindowObject *)v)->ob_itself;")
60n/a Output("return 1;")
61n/a OutRbrace()
62n/a Out("""
63n/a if (v == Py_None) { *p_itself = NULL; return 1; }
64n/a if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
65n/a """)
66n/a
67n/a# From here on it's basically all boiler plate...
68n/a
69n/a# Create the generator groups and link them
70n/amodule = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
71n/a##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
72n/a##module.addobject(object)
73n/a
74n/a# Create the generator classes used to populate the lists
75n/aFunction = OSErrWeakLinkFunctionGenerator
76n/a##Method = OSErrMethodGenerator
77n/a
78n/a# Create and populate the lists
79n/afunctions = []
80n/a##methods = []
81n/aexecfile(INPUTFILE)
82n/a
83n/a# add the populated lists to the generator groups
84n/a# (in a different wordl the scan program would generate this)
85n/afor f in functions: module.add(f)
86n/a##for f in methods: object.add(f)
87n/a
88n/a# generate output (open the output file as late as possible)
89n/aSetOutputFileName(OUTPUTFILE)
90n/amodule.generate()