blob: d1cc1d1b743420083d31ae8bbbaed6a8316a7127 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001# 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).
5
6import string
7
8# Declarations that change for each manager
9MACHEADERFILE = 'Events.h' # The Apple header file
10MODNAME = 'Evt' # The name of the module
11OBJECTNAME = 'Event' # The basic name of the objects used here
12KIND = 'Record' # Usually 'Ptr' or 'Handle'
13
14# The following is *usually* unchanged but may still require tuning
15MODPREFIX = MODNAME # The prefix for module-wide routines
16OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
17OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
18INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
19OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
20
21from macsupport import *
22
23# Create the type objects
24
Guido van Rossume26c2631995-02-28 09:11:41 +000025#WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
Guido van Rossum17448e21995-01-30 11:53:55 +000026
Jack Jansen2b724171996-04-10 14:48:19 +000027RgnHandle = FakeType("(RgnHandle)0")
28# XXXX Should be next, but this will break a lot of code...
29# RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
Guido van Rossum17448e21995-01-30 11:53:55 +000030
31KeyMap = ArrayOutputBufferType("KeyMap")
Jack Jansend40f3c61995-10-09 23:12:22 +000032MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
33MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
34EventMask = Type("EventMask", "h")
35EventKind = Type("EventKind", "h")
Guido van Rossum17448e21995-01-30 11:53:55 +000036
37includestuff = includestuff + """
38#include <%s>""" % MACHEADERFILE + """
39
40#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
41"""
42
43class MyObjectDefinition(GlobalObjectDefinition):
44 def outputCheckNewArg(self):
45 Output("if (itself == NULL) return PyMac_Error(resNotFound);")
46 def outputCheckConvertArg(self):
47 OutLbrace("if (DlgObj_Check(v))")
48 Output("*p_itself = ((WindowObject *)v)->ob_itself;")
49 Output("return 1;")
50 OutRbrace()
51 Out("""
52 if (v == Py_None) { *p_itself = NULL; return 1; }
53 if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
54 """)
55
56# From here on it's basically all boiler plate...
57
58# Create the generator groups and link them
59module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
60##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
61##module.addobject(object)
62
63# Create the generator classes used to populate the lists
64Function = OSErrFunctionGenerator
65##Method = OSErrMethodGenerator
66
67# Create and populate the lists
68functions = []
69##methods = []
70execfile(INPUTFILE)
71
72# add the populated lists to the generator groups
73# (in a different wordl the scan program would generate this)
74for f in functions: module.add(f)
75##for f in methods: object.add(f)
76
77# generate output (open the output file as late as possible)
78SetOutputFileName(OUTPUTFILE)
79module.generate()
Guido van Rossume26c2631995-02-28 09:11:41 +000080