Debian Codegraph @

cpython27/Mac/Modules/qt/qtsupport.py

raw symbols SCIP
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).
5
6 #error missing SetActionFilter
7
8 import string
9
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
14
15 # The following is *usually* unchanged but may still require tuning
16 MODPREFIX = 'Qt' # 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
21
22 from macsupport import *
23
24 # Create the type objects
25
26 includestuff = includestuff + """
27 #include <QuickTime/QuickTime.h>
28
29
30 #ifdef USE_TOOLBOX_OBJECT_GLUE
31 extern PyObject *_TrackObj_New(Track);
32 extern int _TrackObj_Convert(PyObject *, Track *);
33 extern PyObject *_MovieObj_New(Movie);
34 extern int _MovieObj_Convert(PyObject *, Movie *);
35 extern PyObject *_MovieCtlObj_New(MovieController);
36 extern int _MovieCtlObj_Convert(PyObject *, MovieController *);
37 extern PyObject *_TimeBaseObj_New(TimeBase);
38 extern int _TimeBaseObj_Convert(PyObject *, TimeBase *);
39 extern PyObject *_UserDataObj_New(UserData);
40 extern int _UserDataObj_Convert(PyObject *, UserData *);
41 extern PyObject *_MediaObj_New(Media);
42 extern int _MediaObj_Convert(PyObject *, Media *);
43
44 #define TrackObj_New _TrackObj_New
45 #define TrackObj_Convert _TrackObj_Convert
46 #define MovieObj_New _MovieObj_New
47 #define MovieObj_Convert _MovieObj_Convert
48 #define MovieCtlObj_New _MovieCtlObj_New
49 #define MovieCtlObj_Convert _MovieCtlObj_Convert
50 #define TimeBaseObj_New _TimeBaseObj_New
51 #define TimeBaseObj_Convert _TimeBaseObj_Convert
52 #define UserDataObj_New _UserDataObj_New
53 #define UserDataObj_Convert _UserDataObj_Convert
54 #define MediaObj_New _MediaObj_New
55 #define MediaObj_Convert _MediaObj_Convert
56 #endif
57
58 /* Macro to allow us to GetNextInterestingTime without duration */
59 #define GetMediaNextInterestingTimeOnly(media, flags, time, rate, rv) \
60 GetMediaNextInterestingTime(media, flags, time, rate, rv, NULL)
61
62 /*
63 ** Parse/generate time records
64 */
65 static PyObject *
66 QtTimeRecord_New(TimeRecord *itself)
67 {
68 if (itself->base)
69 return Py_BuildValue("O&lO&", PyMac_Buildwide, &itself->value, itself->scale,
70 TimeBaseObj_New, itself->base);
71 else
72 return Py_BuildValue("O&lO", PyMac_Buildwide, &itself->value, itself->scale,
73 Py_None);
74 }
75
76 static int
77 QtTimeRecord_Convert(PyObject *v, TimeRecord *p_itself)
78 {
79 PyObject *base = NULL;
80 if( !PyArg_ParseTuple(v, "O&l|O", PyMac_Getwide, &p_itself->value, &p_itself->scale,
81 &base) )
82 return 0;
83 if ( base == NULL || base == Py_None )
84 p_itself->base = NULL;
85 else
86 if ( !TimeBaseObj_Convert(base, &p_itself->base) )
87 return 0;
88 return 1;
89 }
90
91 static int
92 QtMusicMIDIPacket_Convert(PyObject *v, MusicMIDIPacket *p_itself)
93 {
94 int dummy;
95
96 if( !PyArg_ParseTuple(v, "hls#", &p_itself->length, &p_itself->reserved, p_itself->data, dummy) )
97 return 0;
98 return 1;
99 }
100
101
102
103 """
104
105 initstuff = initstuff + """
106 PyMac_INIT_TOOLBOX_OBJECT_NEW(Track, TrackObj_New);
107 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Track, TrackObj_Convert);
108 PyMac_INIT_TOOLBOX_OBJECT_NEW(Movie, MovieObj_New);
109 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Movie, MovieObj_Convert);
110 PyMac_INIT_TOOLBOX_OBJECT_NEW(MovieController, MovieCtlObj_New);
111 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(MovieController, MovieCtlObj_Convert);
112 PyMac_INIT_TOOLBOX_OBJECT_NEW(TimeBase, TimeBaseObj_New);
113 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(TimeBase, TimeBaseObj_Convert);
114 PyMac_INIT_TOOLBOX_OBJECT_NEW(UserData, UserDataObj_New);
115 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(UserData, UserDataObj_Convert);
116 PyMac_INIT_TOOLBOX_OBJECT_NEW(Media, MediaObj_New);
117 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Media, MediaObj_Convert);
118 """
119
120 # Our (opaque) objects
121 Movie = OpaqueByValueType('Movie', 'MovieObj')
122 NullMovie = FakeType("(Movie)0")
123 Track = OpaqueByValueType('Track', 'TrackObj')
124 Media = OpaqueByValueType('Media', 'MediaObj')
125 UserData = OpaqueByValueType('UserData', 'UserDataObj')
126 TimeBase = OpaqueByValueType('TimeBase', 'TimeBaseObj')
127 MovieController = OpaqueByValueType('MovieController', 'MovieCtlObj')
128 IdleManager = OpaqueByValueType('IdleManager', 'IdleManagerObj')
129 SGOutput = OpaqueByValueType('SGOutput', 'SGOutputObj')
130
131 # Other opaque objects
132 Component = OpaqueByValueType('Component', 'CmpObj')
133 MediaHandlerComponent = OpaqueByValueType('MediaHandlerComponent', 'CmpObj')
134 DataHandlerComponent = OpaqueByValueType('DataHandlerComponent', 'CmpObj')
135 CompressorComponent = OpaqueByValueType('CompressorComponent', 'CmpObj')
136 DecompressorComponent = OpaqueByValueType('DecompressorComponent', 'CmpObj')
137 CodecComponent = OpaqueByValueType('CodecComponent', 'CmpObj')
138
139 # Despite their names, these are all ComponentInstance types
140 GraphicsImportComponent = OpaqueByValueType('GraphicsImportComponent', 'CmpInstObj')
141 GraphicsExportComponent = OpaqueByValueType('GraphicsExportComponent', 'CmpInstObj')
142 ImageTranscoderComponent = OpaqueByValueType('ImageTranscoderComponent', 'CmpInstObj')
143 MovieImportComponent = OpaqueByValueType('MovieImportComponent', 'CmpInstObj')
144 MovieExportComponent = OpaqueByValueType('MovieExportComponent', 'CmpInstObj')
145 TextExportComponent = OpaqueByValueType('TextExportComponent', 'CmpInstObj')
146 GraphicImageMovieImportComponent = OpaqueByValueType('GraphicImageMovieImportComponent', 'CmpInstObj')
147 pnotComponent = OpaqueByValueType('pnotComponent', 'CmpInstObj')
148 # DataCompressorComponent, DataDecompressorComponent would go here
149 DataCodecComponent = OpaqueByValueType('DataCodecComponent', 'CmpInstObj')
150 TweenerComponent = OpaqueByValueType('TweenerComponent', 'CmpInstObj')
151 QTVideoOutputComponent = OpaqueByValueType('QTVideoOutputComponent', 'CmpInstObj')
152 SeqGrabComponent = OpaqueByValueType('SeqGrabComponent', 'CmpInstObj')
153 VideoDigitizerComponent = OpaqueByValueType('VideoDigitizerComponent', 'CmpInstObj')
154
155 ComponentInstance = OpaqueByValueType('ComponentInstance', 'CmpInstObj')
156 MediaHandler = OpaqueByValueType('MediaHandler', 'CmpInstObj')
157 DataHandler = OpaqueByValueType('DataHandler', 'CmpInstObj')
158 SGChannel = OpaqueByValueType('SGChannel', 'CmpInstObj')
159 TunePlayer = OpaqueByValueType('TunePlayer', 'CmpInstObj')
160 MusicComponent = OpaqueByValueType('MusicComponent', 'CmpInstObj')
161 NoteAllocator = OpaqueByValueType('NoteAllocator', 'CmpInstObj')
162 QTMIDIComponent = OpaqueByValueType('QTMIDIComponent', 'CmpInstObj')
163
164 ConstFSSpecPtr = FSSpec_ptr
165 GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj")
166 Byte = Boolean # XXXX For GetPaused and SetPaused
167
168 RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
169 PicHandle = OpaqueByValueType("PicHandle", "ResObj")
170 CTabHandle = OpaqueByValueType("CTabHandle", "ResObj")
171 PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj")
172 SampleDescriptionHandle = OpaqueByValueType("SampleDescriptionHandle", "ResObj")
173 ImageDescriptionHandle = OpaqueByValueType("ImageDescriptionHandle", "ResObj")
174 TextDescriptionHandle = OpaqueByValueType("TextDescriptionHandle", "ResObj")
175 TEHandle = OpaqueByValueType("TEHandle", "ResObj")
176 CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
177 GDHandle = OpaqueByValueType("GDHandle", "OptResObj")
178 AliasHandle = OpaqueByValueType("AliasHandle", "ResObj")
179 SoundDescriptionHandle = OpaqueByValueType("SoundDescriptionHandle", "ResObj")
180 VdigBufferRecListHandle = OpaqueByValueType("VdigBufferRecListHandle", "ResObj")
181 VDCompressionListHandle = OpaqueByValueType("VDCompressionListHandle", "ResObj")
182 TimeCodeDescriptionHandle = OpaqueByValueType("TimeCodeDescriptionHandle", "ResObj")
183 DataHFileTypeOrderingHandle = OpaqueByValueType("DataHFileTypeOrderingHandle", "ResObj")
184 QTMIDIPortListHandle = OpaqueByValueType("QTMIDIPortListHandle", "ResObj")
185 GenericKnobDescriptionListHandle = OpaqueByValueType("GenericKnobDescriptionListHandle", "ResObj")
186 InstrumentInfoListHandle = OpaqueByValueType("InstrumentInfoListHandle", "ResObj")
187 # Silly Apple, passing an OStype by reference...
188 OSType_ptr = OpaqueType("OSType", "PyMac_BuildOSType", "PyMac_GetOSType")
189 # And even sillier: passing floats by address
190 float_ptr = ByAddressType("float", "f")
191
192 RGBColor = OpaqueType("RGBColor", "QdRGB")
193 RGBColor_ptr = RGBColor
194 TimeRecord = OpaqueType("TimeRecord", "QtTimeRecord")
195 TimeRecord_ptr = TimeRecord
196 MusicMIDIPacket = OpaqueType("MusicMIDIPacket", "QtMusicMIDIPacket")
197 MusicMIDIPacket_ptr = MusicMIDIPacket
198
199 # Non-opaque types, mostly integer-ish
200 TimeValue = Type("TimeValue", "l")
201 TimeScale = Type("TimeScale", "l")
202 TimeBaseFlags = Type("TimeBaseFlags", "l")
203 QTCallBackFlags = Type("QTCallBackFlags", "H")
204 TimeBaseStatus = Type("TimeBaseStatus", "l")
205 QTCallBackType = Type("QTCallBackType", "H")
206 nextTimeFlagsEnum = Type("nextTimeFlagsEnum", "H")
207 createMovieFileFlagsEnum = Type("createMovieFileFlagsEnum", "l")
208 movieFlattenFlagsEnum = Type("movieFlattenFlagsEnum", "l")
209 dataRefAttributesFlags = Type("dataRefAttributesFlags", "l")
210 playHintsEnum = Type("playHintsEnum", "l")
211 mediaHandlerFlagsEnum = Type("mediaHandlerFlagsEnum", "l")
212 ComponentResult = Type("ComponentResult", "l")
213 VideoDigitizerError = Type("ComponentResult", "l")
214 HandlerError = Type("HandlerError", "l")
215 Ptr = InputOnlyType("Ptr", "s")
216 StringPtr = Type("StringPtr", "s")
217 UnsignedLongPtr = Type("unsigned long *", "s")
218 mcactionparams = InputOnlyType("void *", "s")
219 QTParameterDialog = Type("QTParameterDialog", "l")
220 QTAtomID = Type("QTAtomID", "l")
221 MCInterfaceElement = Type("MCInterfaceElement", "l")
222 CodecType = OSTypeType("CodecType")
223 GWorldPtr = OpaqueByValueType("GWorldPtr", "GWorldObj")
224 QTFloatSingle = Type("QTFloatSingle", "f")
225 CodecQ = Type("CodecQ", "l")
226 MusicController = Type("MusicController", "l")
227
228 # Could-not-be-bothered-types (NewMovieFromFile)
229 dummyshortptr = FakeType('(short *)0')
230 dummyStringPtr = FakeType('(StringPtr)0')
231
232 # Not-quite-sure-this-is-okay types
233 AtomicInstrument = OpaqueByValueType("AtomicInstrument", "ResObj")
234 AtomicInstrumentPtr = InputOnlyType("AtomicInstrumentPtr", "s")
235
236 # XXXX Need to override output_tp_newBody() to allow for None initializer.
237 class QtGlobalObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
238 def outputCheckNewArg(self):
239 # We don't allow NULL pointers to be returned by QuickTime API calls,
240 # in stead we raise an exception
241 Output("""if (itself == NULL) {
242 PyErr_SetString(Qt_Error,"Cannot create %s from NULL pointer");
243 return NULL;
244 }""", self.name)
245
246 def outputCheckConvertArg(self):
247 # But what we do allow is passing None whereever a quicktime object is
248 # expected, and pass this as NULL to the API routines. Note you can
249 # call methods too by creating an object with None as the initializer.
250 Output("if (v == Py_None)")
251 OutLbrace()
252 Output("*p_itself = NULL;")
253 Output("return 1;")
254 OutRbrace()
255
256 class MovieObjectDefinition(QtGlobalObjectDefinition):
257 def outputFreeIt(self, itselfname):
258 Output("if (%s) DisposeMovie(%s);", itselfname, itselfname)
259
260 class TrackObjectDefinition(QtGlobalObjectDefinition):
261 def outputFreeIt(self, itselfname):
262 Output("if (%s) DisposeMovieTrack(%s);", itselfname, itselfname)
263
264 class MediaObjectDefinition(QtGlobalObjectDefinition):
265 def outputFreeIt(self, itselfname):
266 Output("if (%s) DisposeTrackMedia(%s);", itselfname, itselfname)
267
268 class UserDataObjectDefinition(QtGlobalObjectDefinition):
269 def outputFreeIt(self, itselfname):
270 Output("if (%s) DisposeUserData(%s);", itselfname, itselfname)
271
272 class TimeBaseObjectDefinition(QtGlobalObjectDefinition):
273 pass
274
275 class MovieCtlObjectDefinition(QtGlobalObjectDefinition):
276 def outputFreeIt(self, itselfname):
277 Output("if (%s) DisposeMovieController(%s);", itselfname, itselfname)
278
279 class IdleManagerObjectDefinition(QtGlobalObjectDefinition):
280 pass
281
282 class SGOutputObjectDefinition(QtGlobalObjectDefinition):
283 # XXXX I'm not sure I fully understand how SGOutput works. It seems it's always tied
284 # to a specific SeqGrabComponent, but I'm not 100% sure. Also, I'm not sure all the
285 # routines that return an SGOutput actually return a *new* SGOutput. Need to read up on
286 # this.
287 pass
288
289
290 # From here on it's basically all boiler plate...
291
292 # Create the generator groups and link them
293 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
294 Movie_object = MovieObjectDefinition('Movie', 'MovieObj', 'Movie')
295 Track_object = TrackObjectDefinition('Track', 'TrackObj', 'Track')
296 Media_object = MediaObjectDefinition('Media', 'MediaObj', 'Media')
297 UserData_object = UserDataObjectDefinition('UserData', 'UserDataObj', 'UserData')
298 TimeBase_object = TimeBaseObjectDefinition('TimeBase', 'TimeBaseObj', 'TimeBase')
299 MovieController_object = MovieCtlObjectDefinition('MovieController', 'MovieCtlObj', 'MovieController')
300 IdleManager_object = IdleManagerObjectDefinition('IdleManager', 'IdleManagerObj', 'IdleManager')
301 SGOutput_object = SGOutputObjectDefinition('SGOutput', 'SGOutputObj', 'SGOutput')
302
303 module.addobject(IdleManager_object)
304 module.addobject(MovieController_object)
305 module.addobject(TimeBase_object)
306 module.addobject(UserData_object)
307 module.addobject(Media_object)
308 module.addobject(Track_object)
309 module.addobject(Movie_object)
310 module.addobject(SGOutput_object)
311
312 # Test which types we are still missing.
313 execfile(string.lower(MODPREFIX) + 'typetest.py')
314
315 # Create the generator classes used to populate the lists
316 Function = OSErrWeakLinkFunctionGenerator
317 Method = OSErrWeakLinkMethodGenerator
318
319 # Create and populate the lists
320 functions = []
321 IdleManager_methods = []
322 MovieController_methods = []
323 TimeBase_methods = []
324 UserData_methods = []
325 Media_methods = []
326 Track_methods = []
327 Movie_methods = []
328 SGOutput_methods = []
329 execfile(INPUTFILE)
330
331 #
332 # Some functions from ImageCompression.h that we need:
333 ICMAlignmentProcRecordPtr = FakeType('(ICMAlignmentProcRecordPtr)0')
334 dummyRect = FakeType('(Rect *)0')
335
336 f = Function(void, 'AlignWindow',
337 (WindowPtr, 'wp', InMode),
338 (Boolean, 'front', InMode),
339 (dummyRect, 'alignmentRect', InMode),
340 (ICMAlignmentProcRecordPtr, 'alignmentProc', InMode),
341 )
342 functions.append(f)
343
344 f = Function(void, 'DragAlignedWindow',
345 (WindowPtr, 'wp', InMode),
346 (Point, 'startPt', InMode),
347 (Rect_ptr, 'boundsRect', InMode),
348 (dummyRect, 'alignmentRect', InMode),
349 (ICMAlignmentProcRecordPtr, 'alignmentProc', InMode),
350 )
351 functions.append(f)
352
353 # And we want the version of MoviesTask without a movie argument
354 f = Function(void, 'MoviesTask',
355 (NullMovie, 'theMovie', InMode),
356 (long, 'maxMilliSecToUse', InMode),
357 )
358 functions.append(f)
359
360 # And we want a GetMediaNextInterestingTime without duration
361 f = Method(void, 'GetMediaNextInterestingTimeOnly',
362 (Media, 'theMedia', InMode),
363 (short, 'interestingTimeFlags', InMode),
364 (TimeValue, 'time', InMode),
365 (Fixed, 'rate', InMode),
366 (TimeValue, 'interestingTime', OutMode),
367 )
368 Media_methods.append(f)
369
370 # add the populated lists to the generator groups
371 # (in a different wordl the scan program would generate this)
372 for f in functions: module.add(f)
373 for f in MovieController_methods: MovieController_object.add(f)
374 for f in TimeBase_methods: TimeBase_object.add(f)
375 for f in UserData_methods: UserData_object.add(f)
376 for f in Media_methods: Media_object.add(f)
377 for f in Track_methods: Track_object.add(f)
378 for f in Movie_methods: Movie_object.add(f)
379
380 # generate output (open the output file as late as possible)
381 SetOutputFileName(OUTPUTFILE)
382 module.generate()