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 #include <%s>""" % MACHEADERFILE
+ """
30 /* Macro to allow us to GetNextInterestingTime without duration */
31 #define GetMediaNextInterestingTimeOnly(media, flags, time, rate, rv) \
32 GetMediaNextInterestingTime(media, flags, time, rate, rv, NULL)
35 ** Parse/generate time records
38 QtTimeRecord_New(itself)
42 return Py_BuildValue("O&lO&", PyMac_Buildwide, &itself->value, itself->scale,
43 TimeBaseObj_New, itself->base);
45 return Py_BuildValue("O&lO", PyMac_Buildwide, &itself->value, itself->scale,
50 QtTimeRecord_Convert(v, p_itself)
54 PyObject *base = NULL;
55 if( !PyArg_ParseTuple(v, "O&l|O", PyMac_Getwide, &p_itself->value, &p_itself->scale,
58 if ( base == NULL || base == Py_None )
59 p_itself->base = NULL;
61 if ( !TimeBaseObj_Convert(base, &p_itself->base) )
70 # Our (opaque) objects
71 Movie
= OpaqueByValueType('Movie', 'MovieObj')
72 NullMovie
= FakeType("(Movie)0")
73 Track
= OpaqueByValueType('Track', 'TrackObj')
74 Media
= OpaqueByValueType('Media', 'MediaObj')
75 UserData
= OpaqueByValueType('UserData', 'UserDataObj')
76 TimeBase
= OpaqueByValueType('TimeBase', 'TimeBaseObj')
77 MovieController
= OpaqueByValueType('MovieController', 'MovieCtlObj')
79 # Other opaque objects
80 Component
= OpaqueByValueType('Component', 'CmpObj')
81 MediaHandlerComponent
= OpaqueByValueType('MediaHandlerComponent', 'CmpObj')
82 DataHandlerComponent
= OpaqueByValueType('DataHandlerComponent', 'CmpObj')
84 ComponentInstance
= OpaqueByValueType('ComponentInstance', 'CmpInstObj')
85 MediaHandler
= OpaqueByValueType('MediaHandler', 'CmpInstObj')
86 DataHandler
= OpaqueByValueType('DataHandler', 'CmpInstObj')
88 RgnHandle
= OpaqueByValueType("RgnHandle", "ResObj")
89 PicHandle
= OpaqueByValueType("PicHandle", "ResObj")
90 CTabHandle
= OpaqueByValueType("CTabHandle", "ResObj")
91 PixMapHandle
= OpaqueByValueType("PixMapHandle", "ResObj")
92 SampleDescriptionHandle
= OpaqueByValueType("SampleDescriptionHandle", "ResObj")
93 ImageDescriptionHandle
= OpaqueByValueType("ImageDescriptionHandle", "ResObj")
94 TextDescriptionHandle
= OpaqueByValueType("TextDescriptionHandle", "ResObj")
95 TEHandle
= OpaqueByValueType("TEHandle", "ResObj")
96 CGrafPtr
= OpaqueByValueType("CGrafPtr", "GrafObj")
97 GDHandle
= OpaqueByValueType("GDHandle", "OptResObj")
98 AliasHandle
= OpaqueByValueType("AliasHandle", "ResObj")
99 SoundDescriptionHandle
= OpaqueByValueType("SoundDescriptionHandle", "ResObj")
100 # Silly Apple, passing an OStype by reference...
101 OSType_ptr
= OpaqueType("OSType", "PyMac_BuildOSType", "PyMac_GetOSType")
102 # And even sillier: passing floats by address
103 float_ptr
= ByAddressType("float", "f")
105 RGBColor
= OpaqueType("RGBColor", "QdRGB")
106 RGBColor_ptr
= RGBColor
107 TimeRecord
= OpaqueType("TimeRecord", "QtTimeRecord")
108 TimeRecord_ptr
= TimeRecord
110 # Non-opaque types, mostly integer-ish
111 TimeValue
= Type("TimeValue", "l")
112 TimeScale
= Type("TimeScale", "l")
113 TimeBaseFlags
= Type("TimeBaseFlags", "l")
114 QTCallBackFlags
= Type("QTCallBackFlags", "H")
115 TimeBaseStatus
= Type("TimeBaseStatus", "l")
116 QTCallBackType
= Type("QTCallBackType", "H")
117 nextTimeFlagsEnum
= Type("nextTimeFlagsEnum", "H")
118 createMovieFileFlagsEnum
= Type("createMovieFileFlagsEnum", "l")
119 movieFlattenFlagsEnum
= Type("movieFlattenFlagsEnum", "l")
120 dataRefAttributesFlags
= Type("dataRefAttributesFlags", "l")
121 playHintsEnum
= Type("playHintsEnum", "l")
122 mediaHandlerFlagsEnum
= Type("mediaHandlerFlagsEnum", "l")
123 ComponentResult
= Type("ComponentResult", "l")
124 HandlerError
= Type("HandlerError", "l")
125 Ptr
= InputOnlyType("Ptr", "s")
126 StringPtr
= Type("StringPtr", "s")
127 mcactionparams
= InputOnlyType("void *", "s")
128 QTParameterDialog
= Type("QTParameterDialog", "l")
129 QTAtomID
= Type("QTAtomID", "l")
130 MCInterfaceElement
= Type("MCInterfaceElement", "l")
131 CodecType
= OSTypeType("CodecType")
132 GWorldPtr
= OpaqueByValueType("GWorldPtr", "GWorldObj")
133 QTFloatSingle
= Type("QTFloatSingle", "f")
135 # Could-not-be-bothered-types (NewMovieFromFile)
136 dummyshortptr
= FakeType('(short *)0')
137 dummyStringPtr
= FakeType('(StringPtr)0')
139 class MovieObjectDefinition(GlobalObjectDefinition
):
140 def outputCheckNewArg(self
):
141 Output("""if (itself == NULL) {
142 PyErr_SetString(Qt_Error,"Cannot create null Movie");
145 def outputFreeIt(self
, itselfname
):
146 Output("DisposeMovie(%s);", itselfname
)
148 class TrackObjectDefinition(GlobalObjectDefinition
):
149 def outputCheckNewArg(self
):
150 Output("""if (itself == NULL) {
151 PyErr_SetString(Qt_Error,"Cannot create null Track");
154 def outputFreeIt(self
, itselfname
):
155 Output("DisposeMovieTrack(%s);", itselfname
)
157 class MediaObjectDefinition(GlobalObjectDefinition
):
158 def outputCheckNewArg(self
):
159 Output("""if (itself == NULL) {
160 PyErr_SetString(Qt_Error,"Cannot create null Media");
163 def outputFreeIt(self
, itselfname
):
164 Output("DisposeTrackMedia(%s);", itselfname
)
166 class UserDataObjectDefinition(GlobalObjectDefinition
):
167 def outputCheckNewArg(self
):
168 Output("""if (itself == NULL) {
169 PyErr_SetString(Qt_Error,"Cannot create null UserData");
172 def outputFreeIt(self
, itselfname
):
173 Output("DisposeUserData(%s);", itselfname
)
175 class TimeBaseObjectDefinition(GlobalObjectDefinition
):
176 def outputCheckNewArg(self
):
177 Output("""if (itself == NULL) {
178 PyErr_SetString(Qt_Error,"Cannot create null TimeBase");
181 ## def outputFreeIt(self, itselfname):
182 ## Output("DisposeTimeBase(%s);", itselfname)
184 class MovieCtlObjectDefinition(GlobalObjectDefinition
):
185 def outputCheckNewArg(self
):
186 Output("""if (itself == NULL) {
187 PyErr_SetString(Qt_Error,"Cannot create null MovieController");
190 def outputFreeIt(self
, itselfname
):
191 Output("DisposeMovieController(%s);", itselfname
)
193 # From here on it's basically all boiler plate...
195 # Create the generator groups and link them
196 module
= MacModule(MODNAME
, MODPREFIX
, includestuff
, finalstuff
, initstuff
)
197 Movie_object
= MovieObjectDefinition('Movie', 'MovieObj', 'Movie')
198 Track_object
= TrackObjectDefinition('Track', 'TrackObj', 'Track')
199 Media_object
= MediaObjectDefinition('Media', 'MediaObj', 'Media')
200 UserData_object
= UserDataObjectDefinition('UserData', 'UserDataObj', 'UserData')
201 TimeBase_object
= TimeBaseObjectDefinition('TimeBase', 'TimeBaseObj', 'TimeBase')
202 MovieController_object
= MovieCtlObjectDefinition('MovieController', 'MovieCtlObj', 'MovieController')
204 module
.addobject(MovieController_object
)
205 module
.addobject(TimeBase_object
)
206 module
.addobject(UserData_object
)
207 module
.addobject(Media_object
)
208 module
.addobject(Track_object
)
209 module
.addobject(Movie_object
)
211 # Create the generator classes used to populate the lists
212 Function
= OSErrFunctionGenerator
213 Method
= OSErrMethodGenerator
215 # Create and populate the lists
217 MovieController_methods
= []
218 TimeBase_methods
= []
219 UserData_methods
= []
226 # Some functions from ImageCompression.h that we need:
227 ICMAlignmentProcRecordPtr
= FakeType('(ICMAlignmentProcRecordPtr)0')
228 dummyRect
= FakeType('(Rect *)0')
230 f
= Function(void
, 'AlignWindow',
231 (WindowPtr
, 'wp', InMode
),
232 (Boolean
, 'front', InMode
),
233 (dummyRect
, 'alignmentRect', InMode
),
234 (ICMAlignmentProcRecordPtr
, 'alignmentProc', InMode
),
238 f
= Function(void
, 'DragAlignedWindow',
239 (WindowPtr
, 'wp', InMode
),
240 (Point
, 'startPt', InMode
),
241 (Rect_ptr
, 'boundsRect', InMode
),
242 (dummyRect
, 'alignmentRect', InMode
),
243 (ICMAlignmentProcRecordPtr
, 'alignmentProc', InMode
),
247 # And we want the version of MoviesTask without a movie argument
248 f
= Function(void
, 'MoviesTask',
249 (NullMovie
, 'theMovie', InMode
),
250 (long, 'maxMilliSecToUse', InMode
),
254 # And we want a GetMediaNextInterestingTime without duration
255 f
= Method(void
, 'GetMediaNextInterestingTimeOnly',
256 (Media
, 'theMedia', InMode
),
257 (short
, 'interestingTimeFlags', InMode
),
258 (TimeValue
, 'time', InMode
),
259 (Fixed
, 'rate', InMode
),
260 (TimeValue
, 'interestingTime', OutMode
),
262 Media_methods
.append(f
)
264 # add the populated lists to the generator groups
265 # (in a different wordl the scan program would generate this)
266 for f
in functions
: module
.add(f
)
267 for f
in MovieController_methods
: MovieController_object
.add(f
)
268 for f
in TimeBase_methods
: TimeBase_object
.add(f
)
269 for f
in UserData_methods
: UserData_object
.add(f
)
270 for f
in Media_methods
: Media_object
.add(f
)
271 for f
in Track_methods
: Track_object
.add(f
)
272 for f
in Movie_methods
: Movie_object
.add(f
)
274 # generate output (open the output file as late as possible)
275 SetOutputFileName(OUTPUTFILE
)