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).
9 addpack
.addpack(':Tools:bgen:bgen')
11 # Declarations that change for each manager
12 MACHEADERFILE
= 'Menus.h' # The Apple header file
13 MODNAME
= 'Menu' # The name of the module
14 OBJECTNAME
= 'Menu' # The basic name of the objects used here
16 # The following is *usually* unchanged but may still require tuning
17 MODPREFIX
= MODNAME
# The prefix for module-wide routines
18 OBJECTTYPE
= OBJECTNAME
+ 'Handle' # The C type used to represent them
19 OBJECTPREFIX
= MODPREFIX
+ 'Obj' # The prefix for object methods
20 INPUTFILE
= string
.lower(MODPREFIX
) + 'gen.py' # The file generated by the scanner
21 EXTRAFILE
= string
.lower(MODPREFIX
) + 'edit.py' # A similar file but hand-made
22 OUTPUTFILE
= MODNAME
+ "module.c" # The file generated by this program
24 from macsupport
import *
26 # Create the type objects
28 MenuHandle
= OpaqueByValueType(OBJECTTYPE
, OBJECTPREFIX
)
31 unsigned_char
= Type('unsigned char', 'b')
33 includestuff
= includestuff
+ """
34 #include <Devices.h> /* Defines OpenDeskAcc in universal headers */
35 #include <Desk.h> /* Defines OpenDeskAcc in old headers */
36 #include <%s>""" % MACHEADERFILE
+ """
38 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
41 class MyObjectDefinition(GlobalObjectDefinition
):
44 # Create the generator groups and link them
45 module
= MacModule(MODNAME
, MODPREFIX
, includestuff
, finalstuff
, initstuff
)
46 object = MyObjectDefinition(OBJECTNAME
, OBJECTPREFIX
, OBJECTTYPE
)
47 module
.addobject(object)
49 # Create the generator classes used to populate the lists
50 Function
= OSErrFunctionGenerator
51 Method
= OSErrMethodGenerator
53 # Create and populate the lists
59 # add the populated lists to the generator groups
60 for f
in functions
: module
.add(f
)
61 for f
in methods
: object.add(f
)
63 # generate output (open the output file as late as possible)
64 SetOutputFileName(OUTPUTFILE
)