This commit was manufactured by cvs2svn to create tag 'r22b2-mac'.
[python/dscho.git] / Mac / Modules / menu / menusupport.py
blob31575942c45486ed18b1fb5e6e89de497773e5e7
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).
6 import string
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)
26 MenuRef = MenuHandle
27 Handle = OpaqueByValueType("Handle", "ResObj")
28 MenuBarHandle = OpaqueByValueType("MenuBarHandle", "ResObj")
29 MenuID = Type("MenuID", "h")
30 MenuItemIndex = Type("MenuItemIndex", "h")
31 MenuCommand = Type("MenuCommand", "l")
32 MenuAttributes = Type("MenuAttributes", "l")
33 MenuItemAttributes = Type("MenuItemAttributes", "l")
34 unsigned_char = Type('unsigned char', 'b')
35 FMFontFamily = Type("FMFontFamily", "h")
36 FMFontStyle = Type("FMFontStyle", "h")
38 includestuff = includestuff + """
39 #ifdef WITHOUT_FRAMEWORKS
40 #include <Devices.h> /* Defines OpenDeskAcc in universal headers */
41 #include <Menus.h>
42 #else
43 #include <Carbon/Carbon.h>
44 #endif
47 #ifdef USE_TOOLBOX_OBJECT_GLUE
49 extern PyObject *_MenuObj_New(MenuHandle);
50 extern int _MenuObj_Convert(PyObject *, MenuHandle *);
52 #define MenuObj_New _MenuObj_New
53 #define MenuObj_Convert _MenuObj_Convert
54 #endif
56 #if !ACCESSOR_CALLS_ARE_FUNCTIONS
57 #define GetMenuID(menu) ((*(menu))->menuID)
58 #define GetMenuWidth(menu) ((*(menu))->menuWidth)
59 #define GetMenuHeight(menu) ((*(menu))->menuHeight)
61 #define SetMenuID(menu, id) ((*(menu))->menuID = (id))
62 #define SetMenuWidth(menu, width) ((*(menu))->menuWidth = (width))
63 #define SetMenuHeight(menu, height) ((*(menu))->menuHeight = (height))
64 #endif
66 #define as_Menu(h) ((MenuHandle)h)
67 #define as_Resource(h) ((Handle)h)
68 """
70 initstuff = initstuff + """
71 PyMac_INIT_TOOLBOX_OBJECT_NEW(MenuHandle, MenuObj_New);
72 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(MenuHandle, MenuObj_Convert);
73 """
75 class MyObjectDefinition(GlobalObjectDefinition):
76 pass
78 # Create the generator groups and link them
79 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
80 object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
81 module.addobject(object)
83 # Create the generator classes used to populate the lists
84 Function = OSErrWeakLinkFunctionGenerator
85 Method = OSErrWeakLinkMethodGenerator
87 # Create and populate the lists
88 functions = []
89 methods = []
90 execfile(INPUTFILE)
91 execfile(EXTRAFILE)
93 # add the populated lists to the generator groups
94 for f in functions: module.add(f)
95 for f in methods: object.add(f)
97 # generate output (open the output file as late as possible)
98 SetOutputFileName(OUTPUTFILE)
99 module.generate()