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
= 'Appearance.h' # The Apple header file
10 MODNAME
= 'App' # The name of the module
11 OBJECTNAME
= 'UNUSED' # The basic name of the objects used here
12 KIND
= 'Record' # Usually 'Ptr' or 'Handle'
14 # The following is *usually* unchanged but may still require tuning
15 MODPREFIX
= MODNAME
# The prefix for module-wide routines
16 OBJECTTYPE
= OBJECTNAME
+ KIND
# The C type used to represent them
17 OBJECTPREFIX
= MODPREFIX
+ 'Obj' # The prefix for object methods
18 INPUTFILE
= string
.lower(MODPREFIX
) + 'gen.py' # The file generated by the scanner
19 OUTPUTFILE
= MODNAME
+ "module.c" # The file generated by this program
21 from macsupport
import *
23 # Create the type objects
24 #MenuRef = OpaqueByValueType("MenuRef", "MenuObj")
27 #WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
29 RgnHandle
= FakeType("(RgnHandle)0")
30 # XXXX Should be next, but this will break a lot of code...
31 # RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
33 #KeyMap = ArrayOutputBufferType("KeyMap")
34 #MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
35 #MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
36 #EventMask = Type("EventMask", "h")
37 #EventKind = Type("EventKind", "h")
38 ThemeBrush
= Type("ThemeBrush", "h")
39 ThemeColor
= Type("ThemeColor", "h")
40 ThemeTextColor
= Type("ThemeTextColor", "h")
41 ThemeMenuBarState
= Type("ThemeMenuBarState", "h")
42 ThemeMenuState
= Type("ThemeMenuState", "h")
43 ThemeMenuType
= Type("ThemeMenuType", "h")
44 ThemeMenuItemType
= Type("ThemeMenuItemType", "h")
45 ThemeDrawState
= Type("ThemeDrawState", "l")
46 CTabHandle
= OpaqueByValueType("CTabHandle", "ResObj")
49 includestuff
= includestuff
+ """
50 #include <%s>""" % MACHEADERFILE
+ """
52 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
55 ## class MyObjectDefinition(GlobalObjectDefinition):
56 ## def outputCheckNewArg(self):
57 ## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
58 ## def outputCheckConvertArg(self):
59 ## OutLbrace("if (DlgObj_Check(v))")
60 ## Output("*p_itself = ((WindowObject *)v)->ob_itself;")
61 ## Output("return 1;")
64 ## if (v == Py_None) { *p_itself = NULL; return 1; }
65 ## if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
68 # From here on it's basically all boiler plate...
70 # Create the generator groups and link them
71 module
= MacModule(MODNAME
, MODPREFIX
, includestuff
, finalstuff
, initstuff
)
72 ##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
73 ##module.addobject(object)
75 # Create the generator classes used to populate the lists
76 Function
= OSErrFunctionGenerator
77 ##Method = OSErrMethodGenerator
79 # Create and populate the lists
84 # add the populated lists to the generator groups
85 # (in a different wordl the scan program would generate this)
86 for f
in functions
: module
.add(f
)
87 ##for f in methods: object.add(f)
89 # generate output (open the output file as late as possible)
90 SetOutputFileName(OUTPUTFILE
)