This commit was manufactured by cvs2svn to create tag 'r221'.
[python/dscho.git] / Mac / Modules / evt / evtsupport.py
blobc05a3ed200dc47ba3c7465eef8d33cfedc4f19e7
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 = '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
39 #include <Events.h>
40 #else
41 #include <Carbon/Carbon.h>
42 #endif
44 """
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;")
52 Output("return 1;")
53 OutRbrace()
54 Out("""
55 if (v == Py_None) { *p_itself = NULL; return 1; }
56 if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
57 """)
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
71 functions = []
72 ##methods = []
73 execfile(INPUTFILE)
75 # Move TickCount here, for convenience
76 f = Function(UInt32, 'TickCount',
78 functions.append(f)
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 = """
86 Boolean _rv;
87 EventMask eventMask;
88 EventRecord theEvent;
89 UInt32 sleep;
90 Handle mouseregion = (Handle)0;
92 if (!PyArg_ParseTuple(_args, "Hl|O&",
93 &eventMask,
94 &sleep,
95 OptResObj_Convert, &mouseregion))
96 return NULL;
97 _rv = WaitNextEvent(eventMask,
98 &theEvent,
99 sleep,
100 (RgnHandle)mouseregion);
101 _res = Py_BuildValue("bO&",
102 _rv,
103 PyMac_BuildEventRecord, &theEvent);
104 return _res;
106 f = ManualGenerator("WaitNextEvent", WaitNextEvent_body);
107 f.docstring = lambda: "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"
108 module.add(f)
111 # generate output (open the output file as late as possible)
112 SetOutputFileName(OUTPUTFILE)
113 module.generate()