• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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).
5
6import string
7
8# Declarations that change for each manager
9MACHEADERFILE = 'OSA.h'         # The Apple header file
10MODNAME = '_OSA'                                # The name of the module
11
12# The following is *usually* unchanged but may still require tuning
13MODPREFIX = 'OSA'                       # The prefix for module-wide routines
14OBJECTPREFIX = 'OSAObj' # The prefix for object methods
15INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
16OUTPUTFILE = MODNAME + "module.c"       # The file generated by this program
17
18from macsupport import *
19
20# Create the type objects
21
22includestuff = includestuff + """
23#if PY_VERSION_HEX < 0x02040000
24PyObject *PyMac_GetOSErrException(void);
25#endif
26#include <Carbon/Carbon.h>
27
28#ifdef USE_TOOLBOX_OBJECT_GLUE
29extern PyObject *_OSAObj_New(ComponentInstance);
30extern int _OSAObj_Convert(PyObject *, ComponentInstance *);
31
32#define OSAObj_New _OSAObj_New
33#define OSAObj_Convert _OSAObj_Convert
34#endif
35"""
36
37initstuff = initstuff + """
38/*
39        PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, OSAObj_New);
40        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, OSAObj_Convert);
41*/
42"""
43
44ComponentInstance = OpaqueByValueType('ComponentInstance', OBJECTPREFIX)
45OSAError = OSErrType("OSAError", "l")
46# OSALocalOrGlobal = Type("OSALocalOrGlobal", "l")
47OSAID = Type("OSAID", "l")
48OSADebugCallFrameRef = Type("OSADebugCallFrameRef", "l")
49OSADebugSessionRef = Type("OSADebugSessionRef", "l")
50OSADebugStepKind = Type("OSADebugStepKind", "l")
51DescType = OSTypeType("DescType")
52AEDesc = OpaqueType('AEDesc')
53AEDesc_ptr = OpaqueType('AEDesc')
54AEAddressDesc = OpaqueType('AEAddressDesc', 'AEDesc')
55AEAddressDesc_ptr = OpaqueType('AEAddressDesc', 'AEDesc')
56AEDescList = OpaqueType('AEDescList', 'AEDesc')
57AEDescList_ptr = OpaqueType('AEDescList', 'AEDesc')
58AERecord = OpaqueType('AERecord', 'AEDesc')
59AERecord_ptr = OpaqueType('AERecord', 'AEDesc')
60AppleEvent = OpaqueType('AppleEvent', 'AEDesc')
61AppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc')
62
63# NOTE: at the moment OSA.ComponentInstance is not a subclass
64# of Cm.ComponentInstance. If this is a problem it can be fixed.
65class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
66    def outputCheckNewArg(self):
67        Output("""if (itself == NULL) {
68                                PyErr_SetString(OSA_Error,"NULL ComponentInstance");
69                                return NULL;
70                        }""")
71
72    def outputCheckConvertArg(self):
73        Output("""
74                if (CmpInstObj_Convert(v, p_itself))
75                        return 1;
76                PyErr_Clear();
77                """)
78
79
80# Create the generator groups and link them
81module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
82object = MyObjectDefinition('OSAComponentInstance', OBJECTPREFIX,
83                'ComponentInstance')
84module.addobject(object)
85
86# Create the generator classes used to populate the lists
87Function = OSErrWeakLinkFunctionGenerator
88Method = OSErrWeakLinkMethodGenerator
89
90# Test which types we are still missing.
91execfile(string.lower(MODPREFIX) + 'typetest.py')
92
93# Create and populate the lists
94functions = []
95methods = []
96execfile(INPUTFILE)
97
98# add the populated lists to the generator groups
99# (in a different wordl the scan program would generate this)
100for f in functions: module.add(f)
101for f in methods: object.add(f)
102
103# generate output (open the output file as late as possible)
104SetOutputFileName(OUTPUTFILE)
105module.generate()
106