ยปCore Development>Code coverage>Mac/Modules/evt/evtsupport.py

Python code coverage for Mac/Modules/evt/evtsupport.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 = 'Events.h' # The Apple header file
10n/aMODNAME = '_Evt' # The name of the module
11n/aOBJECTNAME = 'Event' # The basic name of the objects used here
12n/aKIND = 'Record' # Usually 'Ptr' or 'Handle'
13n/a
14n/a# The following is *usually* unchanged but may still require tuning
15n/aMODPREFIX = 'Evt' # 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/a
25n/a#WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
26n/a
27n/aRgnHandle = FakeType("(RgnHandle)0")
28n/a# XXXX Should be next, but this will break a lot of code...
29n/a# RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
30n/a
31n/aKeyMap = ArrayOutputBufferType("KeyMap")
32n/a##MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
33n/a##MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
34n/aEventMask = Type("EventMask", "H")
35n/aEventKind = Type("EventKind", "H")
36n/a
37n/aincludestuff = includestuff + """
38n/a#include <Carbon/Carbon.h>
39n/a
40n/a"""
41n/a
42n/a# From here on it's basically all boiler plate...
43n/a
44n/a# Create the generator groups and link them
45n/amodule = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
46n/a
47n/a# Create the generator classes used to populate the lists
48n/aFunction = OSErrWeakLinkFunctionGenerator
49n/a##Method = OSErrWeakLinkMethodGenerator
50n/a
51n/a# Create and populate the lists
52n/afunctions = []
53n/aexecfile(INPUTFILE)
54n/a
55n/a# Move TickCount here, for convenience
56n/af = Function(UInt32, 'TickCount',
57n/a)
58n/afunctions.append(f)
59n/a
60n/a# add the populated lists to the generator groups
61n/a# (in a different wordl the scan program would generate this)
62n/afor f in functions: module.add(f)
63n/a
64n/aWaitNextEvent_body = """
65n/aBoolean _rv;
66n/aEventMask eventMask;
67n/aEventRecord theEvent;
68n/aUInt32 sleep;
69n/aHandle mouseregion = (Handle)0;
70n/a
71n/aif (!PyArg_ParseTuple(_args, "Hl|O&",
72n/a &eventMask,
73n/a &sleep,
74n/a OptResObj_Convert, &mouseregion))
75n/a return NULL;
76n/a_rv = WaitNextEvent(eventMask,
77n/a &theEvent,
78n/a sleep,
79n/a (RgnHandle)mouseregion);
80n/a_res = Py_BuildValue("bO&",
81n/a _rv,
82n/a PyMac_BuildEventRecord, &theEvent);
83n/areturn _res;
84n/a"""
85n/af = ManualGenerator("WaitNextEvent", WaitNextEvent_body);
86n/af.docstring = lambda: "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"
87n/amodule.add(f)
88n/a
89n/a
90n/a# generate output (open the output file as late as possible)
91n/aSetOutputFileName(OUTPUTFILE)
92n/amodule.generate()