Ditched '_find_SET()', since it was a no-value-added wrapper around
[python/dscho.git] / Mac / Modules / qdoffs / qdoffssupport.py
blob43e1977e3ae4273faaeb7feeff2e5c52ccf687a9
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 = 'QDOffscreen.h' # The Apple header file
10 MODNAME = 'Qdoffs' # The name of the module
11 OBJECTNAME = 'GWorld' # The basic name of the objects used here
13 # The following is *usually* unchanged but may still require tuning
14 MODPREFIX = MODNAME # The prefix for module-wide routines
15 OBJECTTYPE = OBJECTNAME + 'Ptr' # The C type used to represent them
16 OBJECTPREFIX = OBJECTNAME + 'Obj' # The prefix for object methods
17 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
18 #EDITFILE = string.lower(MODPREFIX) + 'edit.py' # The manual definitions
19 OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
21 from macsupport import *
23 # Create the type objects
25 GWorldPtr = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
26 GWorldFlags = Type("GWorldFlags", "l")
27 GDHandle = OpaqueByValueType("GDHandle", "ResObj")
28 OptGDHandle = OpaqueByValueType("GDHandle", "OptResObj")
29 CTabHandle = OpaqueByValueType("CTabHandle", "OptResObj")
30 PixPatHandle = OpaqueByValueType("PixPatHandle", "ResObj")
31 PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj")
32 CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
33 GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj")
34 QDErr = OSErrType("QDErr", 'h')
36 includestuff = includestuff + """
37 #include <%s>""" % MACHEADERFILE + """
39 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
41 """
44 class MyObjectDefinition(GlobalObjectDefinition):
45 def outputCheckNewArg(self):
46 Output("if (itself == NULL) return PyMac_Error(resNotFound);")
47 ## def outputInitStructMembers(self):
48 ## GlobalObjectDefinition.outputInitStructMembers(self)
49 ## Output("SetWRefCon(itself, (long)it);")
50 ## def outputCheckConvertArg(self):
51 ## OutLbrace("if (DlgObj_Check(v))")
52 ## Output("*p_itself = ((WindowObject *)v)->ob_itself;")
53 ## Output("return 1;")
54 ## OutRbrace()
55 ## Out("""
56 ## if (v == Py_None) { *p_itself = NULL; return 1; }
57 ## if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
58 ## """)
59 def outputFreeIt(self, itselfname):
60 Output("DisposeGWorld(%s);", itselfname)
61 # From here on it's basically all boiler plate...
63 # Create the generator groups and link them
64 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
65 object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
66 module.addobject(object)
69 # Create the generator classes used to populate the lists
70 Function = OSErrFunctionGenerator
71 Method = OSErrMethodGenerator
73 # Create and populate the lists
74 functions = []
75 methods = []
76 execfile(INPUTFILE)
79 # add the populated lists to the generator groups
80 # (in a different wordl the scan program would generate this)
81 for f in functions: module.add(f)
82 for f in methods: object.add(f)
86 # generate output (open the output file as late as possible)
87 SetOutputFileName(OUTPUTFILE)
88 module.generate()