ยปCore Development>Code coverage>Mac/Modules/app/appsupport.py

Python code coverage for Mac/Modules/app/appsupport.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 = 'Appearance.h' # The Apple header file
10n/aMODNAME = '_App' # The name of the module
11n/aOBJECTNAME = 'ThemeDrawingState' # The basic name of the objects used here
12n/aKIND = '' # Usually 'Ptr' or 'Handle'
13n/a
14n/a# The following is *usually* unchanged but may still require tuning
15n/aMODPREFIX = 'App' # The prefix for module-wide routines
16n/aOBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
17n/aOBJECTPREFIX = OBJECTNAME + '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#MenuRef = OpaqueByValueType("MenuRef", "MenuObj")
25n/a
26n/a
27n/a#WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
28n/a
29n/aRgnHandle = FakeType("(RgnHandle)0")
30n/aNULL = FakeType("NULL")
31n/a
32n/a# XXXX Should be next, but this will break a lot of code...
33n/a# RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
34n/a
35n/a#KeyMap = ArrayOutputBufferType("KeyMap")
36n/a#MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
37n/a#MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
38n/a#EventMask = Type("EventMask", "h")
39n/a#EventKind = Type("EventKind", "h")
40n/aThemeBrush = Type("ThemeBrush", "h")
41n/aThemeColor = Type("ThemeColor", "h")
42n/aThemeTextColor = Type("ThemeTextColor", "h")
43n/aThemeMenuBarState = Type("ThemeMenuBarState", "H")
44n/aThemeMenuState = Type("ThemeMenuState", "H")
45n/aThemeMenuType = Type("ThemeMenuType", "H")
46n/aThemeMenuItemType = Type("ThemeMenuItemType", "H")
47n/aThemeFontID = Type("ThemeFontID", "H")
48n/aThemeTabStyle = Type("ThemeTabStyle", "H")
49n/aThemeTabDirection = Type("ThemeTabDirection", "H")
50n/aThemeDrawState = Type("ThemeDrawState", "l")
51n/aThemeCursor = Type("ThemeCursor", "l")
52n/aThemeCheckBoxStyle = Type("ThemeCheckBoxStyle", "H")
53n/aThemeScrollBarArrowStyle = Type("ThemeScrollBarArrowStyle", "H")
54n/aThemeScrollBarThumbStyle = Type("ThemeScrollBarThumbStyle", "H")
55n/aCTabHandle = OpaqueByValueType("CTabHandle", "ResObj")
56n/aThemeTrackEnableState = Type("ThemeTrackEnableState", "b")
57n/aThemeTrackPressState = Type("ThemeTrackPressState", "b")
58n/aThemeThumbDirection = Type("ThemeThumbDirection", "b")
59n/aThemeTrackAttributes = Type("ThemeTrackAttributes", "H")
60n/aControlPartCode = Type("ControlPartCode", "h")
61n/aThemeWindowAttributes = Type("ThemeWindowAttributes", "l")
62n/aThemeWindowType = Type("ThemeWindowType", "H")
63n/aThemeTitleBarWidget = Type("ThemeTitleBarWidget", "H")
64n/aThemeArrowOrientation = Type("ThemeArrowOrientation", "H")
65n/aThemePopupArrowSize = Type("ThemePopupArrowSize", "H")
66n/aThemeGrowDirection = Type("ThemeGrowDirection", "H")
67n/aThemeSoundKind = OSTypeType("ThemeSoundKind")
68n/aThemeDragSoundKind = OSTypeType("ThemeDragSoundKind")
69n/aThemeBackgroundKind = Type("ThemeBackgroundKind", "l")
70n/aThemeMetric = Type("ThemeMetric", "l")
71n/aRGBColor = OpaqueType("RGBColor", "QdRGB")
72n/aTruncCode = Type("TruncCode", "h")
73n/a
74n/a
75n/aThemeButtonKind = UInt16
76n/aThemeButtonDrawInfo_ptr = OpaqueType("ThemeButtonDrawInfo", "ThemeButtonDrawInfo")
77n/aThemeEraseUPP = FakeType("NULL")
78n/aThemeButtonDrawUPP = FakeType("NULL")
79n/a
80n/a
81n/aincludestuff = includestuff + """
82n/a#include <Carbon/Carbon.h>
83n/a
84n/a
85n/aint ThemeButtonDrawInfo_Convert(PyObject *v, ThemeButtonDrawInfo *p_itself)
86n/a{
87n/a return PyArg_Parse(v, "(iHH)", &p_itself->state, &p_itself->value, &p_itself->adornment);
88n/a}
89n/a
90n/a"""
91n/a
92n/aclass MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
93n/a pass
94n/a## def outputCheckNewArg(self):
95n/a## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
96n/a## def outputCheckConvertArg(self):
97n/a## OutLbrace("if (DlgObj_Check(v))")
98n/a## Output("*p_itself = ((WindowObject *)v)->ob_itself;")
99n/a## Output("return 1;")
100n/a## OutRbrace()
101n/a## Out("""
102n/a## if (v == Py_None) { *p_itself = NULL; return 1; }
103n/a## if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
104n/a## """)
105n/a
106n/a# From here on it's basically all boiler plate...
107n/a
108n/a# Create the generator groups and link them
109n/amodule = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
110n/aobject = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
111n/amodule.addobject(object)
112n/a
113n/aThemeDrawingState = OpaqueByValueType("ThemeDrawingState", "ThemeDrawingStateObj")
114n/aMethod = WeakLinkMethodGenerator
115n/a
116n/a
117n/a# Create the generator classes used to populate the lists
118n/aFunction = OSErrWeakLinkFunctionGenerator
119n/a##Method = OSErrWeakLinkMethodGenerator
120n/a
121n/a# Create and populate the lists
122n/afunctions = []
123n/amethods = []
124n/aexecfile(INPUTFILE)
125n/a
126n/a# add the populated lists to the generator groups
127n/a# (in a different wordl the scan program would generate this)
128n/afor f in functions: module.add(f)
129n/afor f in methods: object.add(f)
130n/a
131n/a# generate output (open the output file as late as possible)
132n/aSetOutputFileName(OUTPUTFILE)
133n/amodule.generate()