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
= '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" */
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;")
56 ## if (v == Py_None) { *p_itself = NULL; return 1; }
57 ## if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
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
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
)