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 MACHEADERFILE
= 'Menus.h' # The Apple header file
10 MODNAME
= 'Menu' # The name of the module
11 OBJECTNAME
= 'Menu' # The basic name of the objects used here
13 # The following is *usually* unchanged but may still require tuning
14 MODPREFIX
= MODNAME
# The prefix for module-wide routines
15 OBJECTTYPE
= OBJECTNAME
+ 'Handle' # 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 EXTRAFILE
= string
.lower(MODPREFIX
) + 'edit.py' # A similar file but hand-made
19 OUTPUTFILE
= MODNAME
+ "module.c" # The file generated by this program
21 from macsupport
import *
23 # Create the type objects
25 MenuHandle
= OpaqueByValueType(OBJECTTYPE
, OBJECTPREFIX
)
28 unsigned_char
= Type('unsigned char', 'b')
30 includestuff
= includestuff
+ """
31 #include <Devices.h> /* Defines OpenDeskAcc in universal headers */
32 #include <%s>""" % MACHEADERFILE
+ """
34 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
37 class MyObjectDefinition(GlobalObjectDefinition
):
40 # Create the generator groups and link them
41 module
= MacModule(MODNAME
, MODPREFIX
, includestuff
, finalstuff
, initstuff
)
42 object = MyObjectDefinition(OBJECTNAME
, OBJECTPREFIX
, OBJECTTYPE
)
43 module
.addobject(object)
45 # Create the generator classes used to populate the lists
46 Function
= OSErrFunctionGenerator
47 Method
= OSErrMethodGenerator
49 # Create and populate the lists
55 # add the populated lists to the generator groups
56 for f
in functions
: module
.add(f
)
57 for f
in methods
: object.add(f
)
59 # generate output (open the output file as late as possible)
60 SetOutputFileName(OUTPUTFILE
)