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).
9 addpack
.addpack(':Tools:bgen:bgen')
11 # Declarations that change for each manager
12 MACHEADERFILE
= 'QuickDraw.h' # The Apple header file
13 MODNAME
= 'Qd' # The name of the module
14 OBJECTNAME
= 'Graf' # The basic name of the objects used here
16 # The following is *usually* unchanged but may still require tuning
17 MODPREFIX
= MODNAME
# The prefix for module-wide routines
18 OBJECTTYPE
= OBJECTNAME
+ 'Ptr' # The C type used to represent them
19 OBJECTPREFIX
= MODPREFIX
+ 'Obj' # The prefix for object methods
20 INPUTFILE
= string
.lower(MODPREFIX
) + 'gen.py' # The file generated by the scanner
21 EXTRAFILE
= string
.lower(MODPREFIX
) + 'edit.py' # A similar file but hand-made
22 OUTPUTFILE
= MODNAME
+ "module.c" # The file generated by this program
24 from macsupport
import *
26 # Create the type objects
30 class TextThingieClass(FixedInputBufferType
):
31 def getargsCheck(self
, name
):
34 TextThingie
= TextThingieClass(None)
36 # These are temporary!
38 RgnHandle
= OpaqueByValueType("RgnHandle", "ResObj")
39 PicHandle
= OpaqueByValueType("PicHandle", "ResObj")
40 PolyHandle
= OpaqueByValueType("PolyHandle", "ResObj")
41 PixMapHandle
= OpaqueByValueType("PixMapHandle", "ResObj")
42 PixPatHandle
= OpaqueByValueType("PixPatHandle", "ResObj")
44 includestuff
= includestuff
+ """
45 #include <%s>""" % MACHEADERFILE
+ """
48 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
51 class MyObjectDefinition(GlobalObjectDefinition
):
52 def outputCheckNewArg(self
):
53 Output("if (itself == NULL) return PyMac_Error(resNotFound);")
54 def outputCheckConvertArg(self
):
55 OutLbrace("if (DlgObj_Check(v))")
56 Output("*p_itself = ((WindowObject *)v)->ob_itself;")
60 if (v == Py_None) { *p_itself = NULL; return 1; }
61 if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
63 def outputFreeIt(self
, itselfname
):
64 Output("DisposeWindow(%s);", itselfname
)
66 # From here on it's basically all boiler plate...
68 # Create the generator groups and link them
69 module
= MacModule(MODNAME
, MODPREFIX
, includestuff
, finalstuff
, initstuff
)
70 ##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
71 ##module.addobject(object)
73 # Create the generator classes used to populate the lists
74 Function
= OSErrFunctionGenerator
75 Method
= OSErrMethodGenerator
77 # Create and populate the lists
83 # add the populated lists to the generator groups
84 # (in a different wordl the scan program would generate this)
85 for f
in functions
: module
.add(f
)
86 for f
in methods
: object.add(f
)
88 # generate output (open the output file as late as possible)
89 SetOutputFileName(OUTPUTFILE
)
91 SetOutputFile() # Close it