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
= '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
= 'Evt' # 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")
28 # XXXX Should be next, but this will break a lot of code...
29 # RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
31 KeyMap
= ArrayOutputBufferType("KeyMap")
32 ##MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
33 ##MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
34 EventMask
= Type("EventMask", "H")
35 EventKind
= Type("EventKind", "H")
37 includestuff
= includestuff
+ """
38 #ifdef WITHOUT_FRAMEWORKS
41 #include <Carbon/Carbon.h>
46 class MyObjectDefinition(GlobalObjectDefinition
):
47 def outputCheckNewArg(self
):
48 Output("if (itself == NULL) return PyMac_Error(resNotFound);")
49 def outputCheckConvertArg(self
):
50 OutLbrace("if (DlgObj_Check(v))")
51 Output("*p_itself = ((WindowObject *)v)->ob_itself;")
55 if (v == Py_None) { *p_itself = NULL; return 1; }
56 if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
59 # From here on it's basically all boiler plate...
61 # Create the generator groups and link them
62 module
= MacModule(MODNAME
, MODPREFIX
, includestuff
, finalstuff
, initstuff
)
63 ##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
64 ##module.addobject(object)
66 # Create the generator classes used to populate the lists
67 Function
= OSErrWeakLinkFunctionGenerator
68 ##Method = OSErrWeakLinkMethodGenerator
70 # Create and populate the lists
75 # Move TickCount here, for convenience
76 f
= Function(UInt32
, 'TickCount',
80 # add the populated lists to the generator groups
81 # (in a different wordl the scan program would generate this)
82 for f
in functions
: module
.add(f
)
83 ##for f in methods: object.add(f)
85 WaitNextEvent_body
= """
90 Handle mouseregion = (Handle)0;
92 if (!PyArg_ParseTuple(_args, "Hl|O&",
95 OptResObj_Convert, &mouseregion))
97 _rv = WaitNextEvent(eventMask,
100 (RgnHandle)mouseregion);
101 _res = Py_BuildValue("bO&",
103 PyMac_BuildEventRecord, &theEvent);
106 f
= ManualGenerator("WaitNextEvent", WaitNextEvent_body
);
107 f
.docstring
= lambda: "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"
111 # generate output (open the output file as late as possible)
112 SetOutputFileName(OUTPUTFILE
)