Move setting of ioready 'wait' earlier in call chain, to
[python/dscho.git] / Mac / Modules / menu / menusupport.py
blob6c8229cc7201fa17e608b1137237dbf2071d504f
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 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 */
44 #include <Menus.h>
45 #else
46 #include <Carbon/Carbon.h>
47 #endif
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
57 #endif
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))
67 #endif
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)
76 if (itself == NULL) {
77 Py_INCREF(Py_None);
78 return Py_None;
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)
86 if ( v == Py_None ) {
87 *p_itself = NULL;
88 return 1;
90 return MenuObj_Convert(v, p_itself);
92 """
94 initstuff = initstuff + """
95 PyMac_INIT_TOOLBOX_OBJECT_NEW(MenuHandle, MenuObj_New);
96 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(MenuHandle, MenuObj_Convert);
97 """
99 class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
100 pass
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
112 functions = []
113 methods = []
114 execfile(INPUTFILE)
115 execfile(EXTRAFILE)
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)
123 module.generate()