(py-indent-right, py-outdent-left): new commands, bound to C-c C-r and
[python/dscho.git] / Mac / Modules / evt / evtsupport.py
blob6f59b8b30137d48256782d4a98f99c2f8034d492
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 = 'Events.h' # The Apple header file
10 MODNAME = 'Evt' # The name of the module
11 OBJECTNAME = 'Event' # 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
25 #WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
27 RgnHandle = FakeType("(RgnHandle)0") # XXX
29 KeyMap = ArrayOutputBufferType("KeyMap")
31 includestuff = includestuff + """
32 #include <%s>""" % MACHEADERFILE + """
33 #include <Desk.h>
35 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
36 """
38 class MyObjectDefinition(GlobalObjectDefinition):
39 def outputCheckNewArg(self):
40 Output("if (itself == NULL) return PyMac_Error(resNotFound);")
41 def outputCheckConvertArg(self):
42 OutLbrace("if (DlgObj_Check(v))")
43 Output("*p_itself = ((WindowObject *)v)->ob_itself;")
44 Output("return 1;")
45 OutRbrace()
46 Out("""
47 if (v == Py_None) { *p_itself = NULL; return 1; }
48 if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
49 """)
51 # From here on it's basically all boiler plate...
53 # Create the generator groups and link them
54 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
55 ##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
56 ##module.addobject(object)
58 # Create the generator classes used to populate the lists
59 Function = OSErrFunctionGenerator
60 ##Method = OSErrMethodGenerator
62 # Create and populate the lists
63 functions = []
64 ##methods = []
65 execfile(INPUTFILE)
66 execfile("evtedit.py")
68 # add the populated lists to the generator groups
69 # (in a different wordl the scan program would generate this)
70 for f in functions: module.add(f)
71 ##for f in methods: object.add(f)
73 # generate output (open the output file as late as possible)
74 SetOutputFileName(OUTPUTFILE)
75 module.generate()