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).
8 # Declarations that change for each manager
9 MODNAME
= '_Launch' # The name of the module
10 OBJECTNAME
= 'UNUSED' # The basic name of the objects used here
11 KIND
= 'Record' # Usually 'Ptr' or 'Handle'
13 # The following is *usually* unchanged but may still require tuning
14 MODPREFIX
= 'Launch' # The prefix for module-wide routines
15 OBJECTTYPE
= OBJECTNAME
+ KIND
# The C type used to represent them
16 OBJECTPREFIX
= MODPREFIX
+ 'Obj' # The prefix for object methods
17 INPUTFILE
= string
.lower(MODPREFIX
) + 'gen.py' # The file generated by the scanner
18 OUTPUTFILE
= MODNAME
+ "module.c" # The file generated by this program
20 from macsupport
import *
22 # Create the type objects
23 LSAcceptanceFlags
= Type("LSAcceptanceFlags", "l")
24 LSInitializeFlags
= Type("LSInitializeFlags", "l")
25 LSRequestedInfo
= Type("LSRequestedInfo", "l")
26 LSRolesMask
= Type("LSRolesMask", "l")
27 UniCharCount
= Type("UniCharCount", "l")
28 OptCFStringRef
= OpaqueByValueType("CFStringRef", "OptCFStringRefObj")
29 LSItemInfoRecord
= OpaqueType("LSItemInfoRecord", "LSItemInfoRecord")
31 includestuff
= includestuff
+ """
32 #if PY_VERSION_HEX < 0x02040000
33 PyObject *PyMac_GetOSErrException(void);
36 #include <ApplicationServices/ApplicationServices.h>
39 ** Optional CFStringRef. None will pass NULL
42 OptCFStringRefObj_Convert(PyObject *v, CFStringRef *spec)
48 return CFStringRefObj_Convert(v, spec);
52 OptCFStringRefObj_New(CFStringRef it)
58 return CFStringRefObj_New(it);
62 ** Convert LSItemInfoRecord to Python.
65 LSItemInfoRecord_New(LSItemInfoRecord *it)
67 return Py_BuildValue("{s:is:O&s:O&s:O&s:O&s:i}",
69 "filetype", PyMac_BuildOSType, it->filetype,
70 "creator", PyMac_BuildOSType, it->creator,
71 "extension", OptCFStringRefObj_New, it->extension,
72 "iconFileName", OptCFStringRefObj_New, it->iconFileName,
73 "kindID", it->kindID);
77 # From here on it's basically all boiler plate...
78 execfile(string
.lower(MODPREFIX
) + 'typetest.py')
80 # Create the generator groups and link them
81 module
= MacModule(MODNAME
, MODPREFIX
, includestuff
, finalstuff
, initstuff
)
82 ##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
83 ##module.addobject(object)
85 # Create the generator classes used to populate the lists
86 Function
= OSErrFunctionGenerator
87 ##Method = OSErrMethodGenerator
89 # Create and populate the lists
94 # add the populated lists to the generator groups
95 # (in a different wordl the scan program would generate this)
96 for f
in functions
: module
.add(f
)
97 ##for f in methods: object.add(f)
99 # generate output (open the output file as late as possible)
100 SetOutputFileName(OUTPUTFILE
)