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
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 #ifdef WITHOUT_FRAMEWORKS
30 /* #include <Carbon/Carbon.h> */
31 #include <QuickTime/QuickTime.h>
35 #ifdef USE_TOOLBOX_OBJECT_GLUE
36 extern PyObject *_TrackObj_New(Track);
37 extern int _TrackObj_Convert(PyObject *, Track *);
38 extern PyObject *_MovieObj_New(Movie);
39 extern int _MovieObj_Convert(PyObject *, Movie *);
40 extern PyObject *_MovieCtlObj_New(MovieController);
41 extern int _MovieCtlObj_Convert(PyObject *, MovieController *);
42 extern PyObject *_TimeBaseObj_New(TimeBase);
43 extern int _TimeBaseObj_Convert(PyObject *, TimeBase *);
44 extern PyObject *_UserDataObj_New(UserData);
45 extern int _UserDataObj_Convert(PyObject *, UserData *);
46 extern PyObject *_MediaObj_New(Media);
47 extern int _MediaObj_Convert(PyObject *, Media *);
49 #define TrackObj_New _TrackObj_New
50 #define TrackObj_Convert _TrackObj_Convert
51 #define MovieObj_New _MovieObj_New
52 #define MovieObj_Convert _MovieObj_Convert
53 #define MovieCtlObj_New _MovieCtlObj_New
54 #define MovieCtlObj_Convert _MovieCtlObj_Convert
55 #define TimeBaseObj_New _TimeBaseObj_New
56 #define TimeBaseObj_Convert _TimeBaseObj_Convert
57 #define UserDataObj_New _UserDataObj_New
58 #define UserDataObj_Convert _UserDataObj_Convert
59 #define MediaObj_New _MediaObj_New
60 #define MediaObj_Convert _MediaObj_Convert
63 /* Macro to allow us to GetNextInterestingTime without duration */
64 #define GetMediaNextInterestingTimeOnly(media, flags, time, rate, rv) \
65 GetMediaNextInterestingTime(media, flags, time, rate, rv, NULL)
68 ** Parse/generate time records
71 QtTimeRecord_New(TimeRecord *itself)
74 return Py_BuildValue("O&lO&", PyMac_Buildwide, &itself->value, itself->scale,
75 TimeBaseObj_New, itself->base);
77 return Py_BuildValue("O&lO", PyMac_Buildwide, &itself->value, itself->scale,
82 QtTimeRecord_Convert(PyObject *v, TimeRecord *p_itself)
84 PyObject *base = NULL;
85 if( !PyArg_ParseTuple(v, "O&l|O", PyMac_Getwide, &p_itself->value, &p_itself->scale,
88 if ( base == NULL || base == Py_None )
89 p_itself->base = NULL;
91 if ( !TimeBaseObj_Convert(base, &p_itself->base) )
100 initstuff
= initstuff
+ """
101 PyMac_INIT_TOOLBOX_OBJECT_NEW(Track, TrackObj_New);
102 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Track, TrackObj_Convert);
103 PyMac_INIT_TOOLBOX_OBJECT_NEW(Movie, MovieObj_New);
104 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Movie, MovieObj_Convert);
105 PyMac_INIT_TOOLBOX_OBJECT_NEW(MovieController, MovieCtlObj_New);
106 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(MovieController, MovieCtlObj_Convert);
107 PyMac_INIT_TOOLBOX_OBJECT_NEW(TimeBase, TimeBaseObj_New);
108 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(TimeBase, TimeBaseObj_Convert);
109 PyMac_INIT_TOOLBOX_OBJECT_NEW(UserData, UserDataObj_New);
110 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(UserData, UserDataObj_Convert);
111 PyMac_INIT_TOOLBOX_OBJECT_NEW(Media, MediaObj_New);
112 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Media, MediaObj_Convert);
115 # Our (opaque) objects
116 Movie
= OpaqueByValueType('Movie', 'MovieObj')
117 NullMovie
= FakeType("(Movie)0")
118 Track
= OpaqueByValueType('Track', 'TrackObj')
119 Media
= OpaqueByValueType('Media', 'MediaObj')
120 UserData
= OpaqueByValueType('UserData', 'UserDataObj')
121 TimeBase
= OpaqueByValueType('TimeBase', 'TimeBaseObj')
122 MovieController
= OpaqueByValueType('MovieController', 'MovieCtlObj')
124 # Other opaque objects
125 Component
= OpaqueByValueType('Component', 'CmpObj')
126 MediaHandlerComponent
= OpaqueByValueType('MediaHandlerComponent', 'CmpObj')
127 DataHandlerComponent
= OpaqueByValueType('DataHandlerComponent', 'CmpObj')
129 ComponentInstance
= OpaqueByValueType('ComponentInstance', 'CmpInstObj')
130 MediaHandler
= OpaqueByValueType('MediaHandler', 'CmpInstObj')
131 DataHandler
= OpaqueByValueType('DataHandler', 'CmpInstObj')
133 RgnHandle
= OpaqueByValueType("RgnHandle", "ResObj")
134 PicHandle
= OpaqueByValueType("PicHandle", "ResObj")
135 CTabHandle
= OpaqueByValueType("CTabHandle", "ResObj")
136 PixMapHandle
= OpaqueByValueType("PixMapHandle", "ResObj")
137 SampleDescriptionHandle
= OpaqueByValueType("SampleDescriptionHandle", "ResObj")
138 ImageDescriptionHandle
= OpaqueByValueType("ImageDescriptionHandle", "ResObj")
139 TextDescriptionHandle
= OpaqueByValueType("TextDescriptionHandle", "ResObj")
140 TEHandle
= OpaqueByValueType("TEHandle", "ResObj")
141 CGrafPtr
= OpaqueByValueType("CGrafPtr", "GrafObj")
142 GDHandle
= OpaqueByValueType("GDHandle", "OptResObj")
143 AliasHandle
= OpaqueByValueType("AliasHandle", "ResObj")
144 SoundDescriptionHandle
= OpaqueByValueType("SoundDescriptionHandle", "ResObj")
145 # Silly Apple, passing an OStype by reference...
146 OSType_ptr
= OpaqueType("OSType", "PyMac_BuildOSType", "PyMac_GetOSType")
147 # And even sillier: passing floats by address
148 float_ptr
= ByAddressType("float", "f")
150 RGBColor
= OpaqueType("RGBColor", "QdRGB")
151 RGBColor_ptr
= RGBColor
152 TimeRecord
= OpaqueType("TimeRecord", "QtTimeRecord")
153 TimeRecord_ptr
= TimeRecord
155 # Non-opaque types, mostly integer-ish
156 TimeValue
= Type("TimeValue", "l")
157 TimeScale
= Type("TimeScale", "l")
158 TimeBaseFlags
= Type("TimeBaseFlags", "l")
159 QTCallBackFlags
= Type("QTCallBackFlags", "H")
160 TimeBaseStatus
= Type("TimeBaseStatus", "l")
161 QTCallBackType
= Type("QTCallBackType", "H")
162 nextTimeFlagsEnum
= Type("nextTimeFlagsEnum", "H")
163 createMovieFileFlagsEnum
= Type("createMovieFileFlagsEnum", "l")
164 movieFlattenFlagsEnum
= Type("movieFlattenFlagsEnum", "l")
165 dataRefAttributesFlags
= Type("dataRefAttributesFlags", "l")
166 playHintsEnum
= Type("playHintsEnum", "l")
167 mediaHandlerFlagsEnum
= Type("mediaHandlerFlagsEnum", "l")
168 ComponentResult
= Type("ComponentResult", "l")
169 HandlerError
= Type("HandlerError", "l")
170 Ptr
= InputOnlyType("Ptr", "s")
171 StringPtr
= Type("StringPtr", "s")
172 mcactionparams
= InputOnlyType("void *", "s")
173 QTParameterDialog
= Type("QTParameterDialog", "l")
174 QTAtomID
= Type("QTAtomID", "l")
175 MCInterfaceElement
= Type("MCInterfaceElement", "l")
176 CodecType
= OSTypeType("CodecType")
177 GWorldPtr
= OpaqueByValueType("GWorldPtr", "GWorldObj")
178 QTFloatSingle
= Type("QTFloatSingle", "f")
180 # Could-not-be-bothered-types (NewMovieFromFile)
181 dummyshortptr
= FakeType('(short *)0')
182 dummyStringPtr
= FakeType('(StringPtr)0')
184 class MovieObjectDefinition(GlobalObjectDefinition
):
185 def outputCheckNewArg(self
):
186 Output("""if (itself == NULL) {
187 PyErr_SetString(Qt_Error,"Cannot create null Movie");
190 def outputFreeIt(self
, itselfname
):
191 Output("DisposeMovie(%s);", itselfname
)
193 class TrackObjectDefinition(GlobalObjectDefinition
):
194 def outputCheckNewArg(self
):
195 Output("""if (itself == NULL) {
196 PyErr_SetString(Qt_Error,"Cannot create null Track");
199 def outputFreeIt(self
, itselfname
):
200 Output("DisposeMovieTrack(%s);", itselfname
)
202 class MediaObjectDefinition(GlobalObjectDefinition
):
203 def outputCheckNewArg(self
):
204 Output("""if (itself == NULL) {
205 PyErr_SetString(Qt_Error,"Cannot create null Media");
208 def outputFreeIt(self
, itselfname
):
209 Output("DisposeTrackMedia(%s);", itselfname
)
211 class UserDataObjectDefinition(GlobalObjectDefinition
):
212 def outputCheckNewArg(self
):
213 Output("""if (itself == NULL) {
214 PyErr_SetString(Qt_Error,"Cannot create null UserData");
217 def outputFreeIt(self
, itselfname
):
218 Output("DisposeUserData(%s);", itselfname
)
220 class TimeBaseObjectDefinition(GlobalObjectDefinition
):
221 def outputCheckNewArg(self
):
222 Output("""if (itself == NULL) {
223 PyErr_SetString(Qt_Error,"Cannot create null TimeBase");
226 ## def outputFreeIt(self, itselfname):
227 ## Output("DisposeTimeBase(%s);", itselfname)
229 class MovieCtlObjectDefinition(GlobalObjectDefinition
):
230 def outputCheckNewArg(self
):
231 Output("""if (itself == NULL) {
232 PyErr_SetString(Qt_Error,"Cannot create null MovieController");
235 def outputFreeIt(self
, itselfname
):
236 Output("DisposeMovieController(%s);", itselfname
)
238 # From here on it's basically all boiler plate...
240 # Create the generator groups and link them
241 module
= MacModule(MODNAME
, MODPREFIX
, includestuff
, finalstuff
, initstuff
)
242 Movie_object
= MovieObjectDefinition('Movie', 'MovieObj', 'Movie')
243 Track_object
= TrackObjectDefinition('Track', 'TrackObj', 'Track')
244 Media_object
= MediaObjectDefinition('Media', 'MediaObj', 'Media')
245 UserData_object
= UserDataObjectDefinition('UserData', 'UserDataObj', 'UserData')
246 TimeBase_object
= TimeBaseObjectDefinition('TimeBase', 'TimeBaseObj', 'TimeBase')
247 MovieController_object
= MovieCtlObjectDefinition('MovieController', 'MovieCtlObj', 'MovieController')
249 module
.addobject(MovieController_object
)
250 module
.addobject(TimeBase_object
)
251 module
.addobject(UserData_object
)
252 module
.addobject(Media_object
)
253 module
.addobject(Track_object
)
254 module
.addobject(Movie_object
)
256 # Create the generator classes used to populate the lists
257 Function
= OSErrFunctionGenerator
258 Method
= OSErrMethodGenerator
260 # Create and populate the lists
262 MovieController_methods
= []
263 TimeBase_methods
= []
264 UserData_methods
= []
271 # Some functions from ImageCompression.h that we need:
272 ICMAlignmentProcRecordPtr
= FakeType('(ICMAlignmentProcRecordPtr)0')
273 dummyRect
= FakeType('(Rect *)0')
275 f
= Function(void
, 'AlignWindow',
276 (WindowPtr
, 'wp', InMode
),
277 (Boolean
, 'front', InMode
),
278 (dummyRect
, 'alignmentRect', InMode
),
279 (ICMAlignmentProcRecordPtr
, 'alignmentProc', InMode
),
283 f
= Function(void
, 'DragAlignedWindow',
284 (WindowPtr
, 'wp', InMode
),
285 (Point
, 'startPt', InMode
),
286 (Rect_ptr
, 'boundsRect', InMode
),
287 (dummyRect
, 'alignmentRect', InMode
),
288 (ICMAlignmentProcRecordPtr
, 'alignmentProc', InMode
),
292 # And we want the version of MoviesTask without a movie argument
293 f
= Function(void
, 'MoviesTask',
294 (NullMovie
, 'theMovie', InMode
),
295 (long, 'maxMilliSecToUse', InMode
),
299 # And we want a GetMediaNextInterestingTime without duration
300 f
= Method(void
, 'GetMediaNextInterestingTimeOnly',
301 (Media
, 'theMedia', InMode
),
302 (short
, 'interestingTimeFlags', InMode
),
303 (TimeValue
, 'time', InMode
),
304 (Fixed
, 'rate', InMode
),
305 (TimeValue
, 'interestingTime', OutMode
),
307 Media_methods
.append(f
)
309 # add the populated lists to the generator groups
310 # (in a different wordl the scan program would generate this)
311 for f
in functions
: module
.add(f
)
312 for f
in MovieController_methods
: MovieController_object
.add(f
)
313 for f
in TimeBase_methods
: TimeBase_object
.add(f
)
314 for f
in UserData_methods
: UserData_object
.add(f
)
315 for f
in Media_methods
: Media_object
.add(f
)
316 for f
in Track_methods
: Track_object
.add(f
)
317 for f
in Movie_methods
: Movie_object
.add(f
)
319 # generate output (open the output file as late as possible)
320 SetOutputFileName(OUTPUTFILE
)