Another batch of updates...
[python/dscho.git] / Mac / Modules / qt / qtsupport.py
blob17ba808d22c85f0983885f5d6448dccae6472e7b
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 #error missing SetActionFilter
8 import string
10 # Declarations that change for each manager
11 MACHEADERFILE = 'Movies.h' # The Apple header file
12 MODNAME = 'Qt' # The name of the module
13 OBJECTNAME = 'Movie' # The basic name of the objects used here
15 # The following is *usually* unchanged but may still require tuning
16 MODPREFIX = MODNAME # The prefix for module-wide routines
17 OBJECTTYPE = "Movie" # The C type used to represent them
18 OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
19 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
20 OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
22 from macsupport import *
24 # Create the type objects
26 includestuff = includestuff + """
27 #include <%s>""" % MACHEADERFILE + """
29 /* Exported by Cmmodule.c: */
30 extern PyObject *CmpObj_New(Component);
31 extern int CmpObj_Convert(PyObject *, Component *);
32 extern PyObject *CmpInstObj_New(ComponentInstance);
33 extern int CmpInstObj_Convert(PyObject *, ComponentInstance *);
35 /* Exported by Qdmodule.c: */
36 extern PyObject *QdRGB_New(RGBColor *);
37 extern int QdRGB_Convert(PyObject *, RGBColor *);
39 /* Our own, used before defined: */
40 staticforward PyObject *TrackObj_New(Track);
41 staticforward int TrackObj_Convert(PyObject *, Track *);
42 staticforward PyObject *MovieObj_New(Movie);
43 staticforward int MovieObj_Convert(PyObject *, Movie *);
44 staticforward PyObject *MovieCtlObj_New(MovieController);
45 staticforward int MovieCtlObj_Convert(PyObject *, MovieController *);
48 """
50 # Our (opaque) objects
51 Movie = OpaqueByValueType('Movie', 'MovieObj')
52 Track = OpaqueByValueType('Track', 'TrackObj')
53 Media = OpaqueByValueType('Media', 'MediaObj')
54 UserData = OpaqueByValueType('UserData', 'UserDataObj')
55 TimeBase = OpaqueByValueType('TimeBase', 'TimeBaseObj')
56 MovieController = OpaqueByValueType('MovieController', 'MovieCtlObj')
58 # Other opaque objects
59 Component = OpaqueByValueType('Component', 'CmpObj')
60 MediaHandlerComponent = OpaqueByValueType('MediaHandlerComponent', 'CmpObj')
61 DataHandlerComponent = OpaqueByValueType('DataHandlerComponent', 'CmpObj')
63 ComponentInstance = OpaqueByValueType('ComponentInstance', 'CmpInstObj')
64 MediaHandler = OpaqueByValueType('MediaHandler', 'CmpInstObj')
65 DataHandler = OpaqueByValueType('DataHandler', 'CmpInstObj')
67 RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
68 PicHandle = OpaqueByValueType("PicHandle", "ResObj")
69 CTabHandle = OpaqueByValueType("CTabHandle", "ResObj")
70 PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj")
71 SampleDescriptionHandle = OpaqueByValueType("SampleDescriptionHandle", "ResObj")
72 TEHandle = OpaqueByValueType("TEHandle", "ResObj")
73 # Silly Apple, passing an OStype by reference...
74 OSType_ptr = OpaqueType("OSType", "PyMac_BuildOSType", "PyMac_GetOSType")
76 RGBColor = OpaqueType("RGBColor", "QdRGB")
77 RGBColor_ptr = OpaqueType("RGBColor", "QdRGB")
79 # Non-opaque types, mostly integer-ish
80 TimeValue = Type("TimeValue", "l")
81 TimeScale = Type("TimeScale", "l")
82 TimeBaseFlags = Type("TimeBaseFlags", "l")
83 QTCallBackFlags = Type("QTCallBackFlags", "h")
84 TimeBaseStatus = Type("TimeBaseStatus", "l")
85 QTCallBackType = Type("QTCallBackType", "h")
86 nextTimeFlagsEnum = Type("nextTimeFlagsEnum", "h")
87 createMovieFileFlagsEnum = Type("createMovieFileFlagsEnum", "l")
88 movieFlattenFlagsEnum = Type("movieFlattenFlagsEnum", "l")
89 dataRefAttributesFlags = Type("dataRefAttributesFlags", "l")
90 playHintsEnum = Type("playHintsEnum", "l")
91 mediaHandlerFlagsEnum = Type("mediaHandlerFlagsEnum", "l")
92 ComponentResult = Type("ComponentResult", "l")
93 HandlerError = Type("HandlerError", "l")
94 Ptr = InputOnlyType("Ptr", "s")
95 StringPtr = Type("StringPtr", "s")
96 mcactionparams = InputOnlyType("void *", "s")
98 # Could-not-be-bothered-types (NewMovieFromFile)
99 dummyshortptr = FakeType('(short *)0')
100 dummyStringPtr = FakeType('(StringPtr)0')
102 class MovieObjectDefinition(GlobalObjectDefinition):
103 def outputCheckNewArg(self):
104 Output("""if (itself == NULL) {
105 PyErr_SetString(Qt_Error,"Cannot create null Movie");
106 return NULL;
107 }""")
108 def outputFreeIt(self, itselfname):
109 Output("DisposeMovie(%s);", itselfname)
111 class TrackObjectDefinition(GlobalObjectDefinition):
112 def outputCheckNewArg(self):
113 Output("""if (itself == NULL) {
114 PyErr_SetString(Qt_Error,"Cannot create null Track");
115 return NULL;
116 }""")
117 def outputFreeIt(self, itselfname):
118 Output("DisposeMovieTrack(%s);", itselfname)
120 class MediaObjectDefinition(GlobalObjectDefinition):
121 def outputCheckNewArg(self):
122 Output("""if (itself == NULL) {
123 PyErr_SetString(Qt_Error,"Cannot create null Media");
124 return NULL;
125 }""")
126 def outputFreeIt(self, itselfname):
127 Output("DisposeTrackMedia(%s);", itselfname)
129 class UserDataObjectDefinition(GlobalObjectDefinition):
130 def outputCheckNewArg(self):
131 Output("""if (itself == NULL) {
132 PyErr_SetString(Qt_Error,"Cannot create null UserData");
133 return NULL;
134 }""")
135 def outputFreeIt(self, itselfname):
136 Output("DisposeUserData(%s);", itselfname)
138 class TimeBaseObjectDefinition(GlobalObjectDefinition):
139 def outputCheckNewArg(self):
140 Output("""if (itself == NULL) {
141 PyErr_SetString(Qt_Error,"Cannot create null TimeBase");
142 return NULL;
143 }""")
144 def outputFreeIt(self, itselfname):
145 Output("DisposeTimeBase(%s);", itselfname)
147 class MovieCtlObjectDefinition(GlobalObjectDefinition):
148 def outputCheckNewArg(self):
149 Output("""if (itself == NULL) {
150 PyErr_SetString(Qt_Error,"Cannot create null MovieController");
151 return NULL;
152 }""")
153 def outputFreeIt(self, itselfname):
154 Output("DisposeMovieController(%s);", itselfname)
156 # From here on it's basically all boiler plate...
158 # Create the generator groups and link them
159 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
160 Movie_object = MovieObjectDefinition('Movie', 'MovieObj', 'Movie')
161 Track_object = TrackObjectDefinition('Track', 'TrackObj', 'Track')
162 Media_object = MediaObjectDefinition('Media', 'MediaObj', 'Media')
163 UserData_object = UserDataObjectDefinition('UserData', 'UserDataObj', 'UserData')
164 TimeBase_object = TimeBaseObjectDefinition('TimeBase', 'TimeBaseObj', 'TimeBase')
165 MovieController_object = MovieCtlObjectDefinition('MovieController', 'MovieCtlObj', 'MovieController')
167 module.addobject(MovieController_object)
168 module.addobject(TimeBase_object)
169 module.addobject(UserData_object)
170 module.addobject(Media_object)
171 module.addobject(Track_object)
172 module.addobject(Movie_object)
174 # Create the generator classes used to populate the lists
175 Function = OSErrFunctionGenerator
176 Method = OSErrMethodGenerator
178 # Create and populate the lists
179 functions = []
180 MovieController_methods = []
181 TimeBase_methods = []
182 UserData_methods = []
183 Media_methods = []
184 Track_methods = []
185 Movie_methods = []
186 execfile(INPUTFILE)
189 # Some functions from ImageCompression.h that we need:
190 ICMAlignmentProcRecordPtr = FakeType('(ICMAlignmentProcRecordPtr)0')
191 dummyRect = FakeType('(Rect *)0')
193 f = Function(void, 'AlignWindow',
194 (WindowPtr, 'wp', InMode),
195 (Boolean, 'front', InMode),
196 (dummyRect, 'alignmentRect', InMode),
197 (ICMAlignmentProcRecordPtr, 'alignmentProc', InMode),
199 functions.append(f)
201 f = Function(void, 'DragAlignedWindow',
202 (WindowPtr, 'wp', InMode),
203 (Point, 'startPt', InMode),
204 (Rect_ptr, 'boundsRect', InMode),
205 (dummyRect, 'alignmentRect', InMode),
206 (ICMAlignmentProcRecordPtr, 'alignmentProc', InMode),
208 functions.append(f)
211 # add the populated lists to the generator groups
212 # (in a different wordl the scan program would generate this)
213 for f in functions: module.add(f)
214 for f in MovieController_methods: MovieController_object.add(f)
215 for f in TimeBase_methods: TimeBase_object.add(f)
216 for f in UserData_methods: UserData_object.add(f)
217 for f in Media_methods: Media_object.add(f)
218 for f in Track_methods: Track_object.add(f)
219 for f in Movie_methods: Movie_object.add(f)
221 # generate output (open the output file as late as possible)
222 SetOutputFileName(OUTPUTFILE)
223 module.generate()