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
= 'Menu' # 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
)
27 OptMenuRef
= OpaqueByValueType(OBJECTTYPE
, "Opt" + OBJECTPREFIX
)
28 Handle
= OpaqueByValueType("Handle", "ResObj")
29 MenuBarHandle
= OpaqueByValueType("MenuBarHandle", "ResObj")
30 MenuID
= Type("MenuID", "h")
31 MenuItemIndex
= Type("MenuItemIndex", "h")
32 MenuItemID
= Type("MenuItemID", "l")
33 MenuCommand
= Type("MenuCommand", "l")
34 MenuAttributes
= Type("MenuAttributes", "l")
35 MenuItemAttributes
= Type("MenuItemAttributes", "l")
36 unsigned_char
= Type('unsigned char', 'b')
37 FMFontFamily
= Type("FMFontFamily", "h")
38 FMFontStyle
= Type("FMFontStyle", "h")
39 UniChar
= Type("UniChar", "h")
41 includestuff
= includestuff
+ """
42 #ifdef WITHOUT_FRAMEWORKS
43 #include <Devices.h> /* Defines OpenDeskAcc in universal headers */
46 #include <Carbon/Carbon.h>
50 #ifdef USE_TOOLBOX_OBJECT_GLUE
52 extern PyObject *_MenuObj_New(MenuHandle);
53 extern int _MenuObj_Convert(PyObject *, MenuHandle *);
55 #define MenuObj_New _MenuObj_New
56 #define MenuObj_Convert _MenuObj_Convert
59 #if !ACCESSOR_CALLS_ARE_FUNCTIONS
60 #define GetMenuID(menu) ((*(menu))->menuID)
61 #define GetMenuWidth(menu) ((*(menu))->menuWidth)
62 #define GetMenuHeight(menu) ((*(menu))->menuHeight)
64 #define SetMenuID(menu, id) ((*(menu))->menuID = (id))
65 #define SetMenuWidth(menu, width) ((*(menu))->menuWidth = (width))
66 #define SetMenuHeight(menu, height) ((*(menu))->menuHeight = (height))
69 #define as_Menu(h) ((MenuHandle)h)
70 #define as_Resource(h) ((Handle)h)
73 /* Alternative version of MenuObj_New, which returns None for NULL argument */
74 PyObject *OptMenuObj_New(MenuRef itself)
80 return MenuObj_New(itself);
83 /* Alternative version of MenuObj_Convert, which returns NULL for a None argument */
84 int OptMenuObj_Convert(PyObject *v, MenuRef *p_itself)
90 return MenuObj_Convert(v, p_itself);
94 initstuff
= initstuff
+ """
95 PyMac_INIT_TOOLBOX_OBJECT_NEW(MenuHandle, MenuObj_New);
96 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(MenuHandle, MenuObj_Convert);
99 class MyObjectDefinition(PEP253Mixin
, GlobalObjectDefinition
):
102 # Create the generator groups and link them
103 module
= MacModule(MODNAME
, MODPREFIX
, includestuff
, finalstuff
, initstuff
)
104 object = MyObjectDefinition(OBJECTNAME
, OBJECTPREFIX
, OBJECTTYPE
)
105 module
.addobject(object)
107 # Create the generator classes used to populate the lists
108 Function
= OSErrWeakLinkFunctionGenerator
109 Method
= OSErrWeakLinkMethodGenerator
111 # Create and populate the lists
117 # add the populated lists to the generator groups
118 for f
in functions
: module
.add(f
)
119 for f
in methods
: object.add(f
)
121 # generate output (open the output file as late as possible)
122 SetOutputFileName(OUTPUTFILE
)