ยปCore Development>Code coverage>Mac/Modules/help/helpsupport.py

Python code coverage for Mac/Modules/help/helpsupport.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/aMODNAME = '_Help' # The name of the module
10n/aOBJECTNAME = 'UNUSED' # The basic name of the objects used here
11n/aKIND = 'Record' # Usually 'Ptr' or 'Handle'
12n/a
13n/a# The following is *usually* unchanged but may still require tuning
14n/aMODPREFIX = 'Help' # The prefix for module-wide routines
15n/aOBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
16n/aOBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
17n/aINPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
18n/aOUTPUTFILE = MODNAME + "module.c" # The file generated by this program
19n/a
20n/afrom macsupport import *
21n/a
22n/a# Create the type objects
23n/aMenuRef = OpaqueByValueType("MenuRef", "MenuObj")
24n/aMenuItemIndex = Type("MenuItemIndex", "H")
25n/a
26n/a#WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
27n/a
28n/a#RgnHandle = FakeType("(RgnHandle)0")
29n/a# XXXX Should be next, but this will break a lot of code...
30n/a# RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
31n/a
32n/a#KeyMap = ArrayOutputBufferType("KeyMap")
33n/a##MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
34n/a##MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
35n/a#EventMask = Type("EventMask", "H")
36n/a#EventKind = Type("EventKind", "H")
37n/a
38n/aincludestuff = includestuff + """
39n/a#include <Carbon/Carbon.h>
40n/a"""
41n/a
42n/aclass MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
43n/a def outputCheckNewArg(self):
44n/a Output("if (itself == NULL) return PyMac_Error(resNotFound);")
45n/a def outputCheckConvertArg(self):
46n/a OutLbrace("if (DlgObj_Check(v))")
47n/a Output("*p_itself = ((WindowObject *)v)->ob_itself;")
48n/a Output("return 1;")
49n/a OutRbrace()
50n/a Out("""
51n/a if (v == Py_None) { *p_itself = NULL; return 1; }
52n/a if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
53n/a """)
54n/a
55n/a# From here on it's basically all boiler plate...
56n/a
57n/a# Create the generator groups and link them
58n/amodule = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
59n/a##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
60n/a##module.addobject(object)
61n/a
62n/a# Create the generator classes used to populate the lists
63n/aFunction = OSErrFunctionGenerator
64n/a##Method = OSErrMethodGenerator
65n/a
66n/a# Create and populate the lists
67n/afunctions = []
68n/a##methods = []
69n/aexecfile(INPUTFILE)
70n/a
71n/a# add the populated lists to the generator groups
72n/a# (in a different wordl the scan program would generate this)
73n/afor f in functions: module.add(f)
74n/a##for f in methods: object.add(f)
75n/a
76n/a# generate output (open the output file as late as possible)
77n/aSetOutputFileName(OUTPUTFILE)
78n/amodule.generate()