qtsupport.py revision 0e04eecdbf8467cf3fe055e41e96fa48507b998c
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 8import string 9 10# Declarations that change for each manager 11MACHEADERFILE = 'Movies.h' # The Apple header file 12MODNAME = 'Qt' # The name of the module 13OBJECTNAME = 'Movie' # The basic name of the objects used here 14 15# The following is *usually* unchanged but may still require tuning 16MODPREFIX = MODNAME # The prefix for module-wide routines 17OBJECTTYPE = "Movie" # The C type used to represent them 18OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods 19INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner 20OUTPUTFILE = MODNAME + "module.c" # The file generated by this program 21 22from macsupport import * 23 24# Create the type objects 25 26includestuff = includestuff + """ 27#include <%s>""" % MACHEADERFILE + """ 28 29#ifdef USE_TOOLBOX_OBJECT_GLUE 30extern PyObject *_TrackObj_New(Track); 31extern int _TrackObj_Convert(PyObject *, Track *); 32extern PyObject *_MovieObj_New(Movie); 33extern int _MovieObj_Convert(PyObject *, Movie *); 34extern PyObject *_MovieCtlObj_New(MovieController); 35extern int _MovieCtlObj_Convert(PyObject *, MovieController *); 36extern PyObject *_TimeBaseObj_New(TimeBase); 37extern int _TimeBaseObj_Convert(PyObject *, TimeBase *); 38extern PyObject *_UserDataObj_New(UserData); 39extern int _UserDataObj_Convert(PyObject *, UserData *); 40extern PyObject *_MediaObj_New(Media); 41extern int _MediaObj_Convert(PyObject *, Media *); 42 43#define TrackObj_New _TrackObj_New 44#define TrackObj_Convert _TrackObj_Convert 45#define MovieObj_New _MovieObj_New 46#define MovieObj_Convert _MovieObj_Convert 47#define MovieCtlObj_New _MovieCtlObj_New 48#define MovieCtlObj_Convert _MovieCtlObj_Convert 49#define TimeBaseObj_New _TimeBaseObj_New 50#define TimeBaseObj_Convert _TimeBaseObj_Convert 51#define UserDataObj_New _UserDataObj_New 52#define UserDataObj_Convert _UserDataObj_Convert 53#define MediaObj_New _MediaObj_New 54#define MediaObj_Convert _MediaObj_Convert 55#endif 56 57/* Macro to allow us to GetNextInterestingTime without duration */ 58#define GetMediaNextInterestingTimeOnly(media, flags, time, rate, rv) \ 59 GetMediaNextInterestingTime(media, flags, time, rate, rv, NULL) 60 61/* 62** Parse/generate time records 63*/ 64static PyObject * 65QtTimeRecord_New(itself) 66 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 76static int 77QtTimeRecord_Convert(v, p_itself) 78 PyObject *v; 79 TimeRecord *p_itself; 80{ 81 PyObject *base = NULL; 82 if( !PyArg_ParseTuple(v, "O&l|O", PyMac_Getwide, &p_itself->value, &p_itself->scale, 83 &base) ) 84 return 0; 85 if ( base == NULL || base == Py_None ) 86 p_itself->base = NULL; 87 else 88 if ( !TimeBaseObj_Convert(base, &p_itself->base) ) 89 return 0; 90 return 1; 91} 92 93 94 95""" 96 97initstuff = initstuff + """ 98 PyMac_INIT_TOOLBOX_OBJECT_NEW(TrackObj_New); 99 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(TrackObj_Convert); 100 PyMac_INIT_TOOLBOX_OBJECT_NEW(MovieObj_New); 101 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(MovieObj_Convert); 102 PyMac_INIT_TOOLBOX_OBJECT_NEW(MovieCtlObj_New); 103 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(MovieCtlObj_Convert); 104 PyMac_INIT_TOOLBOX_OBJECT_NEW(TimeBaseObj_New); 105 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(TimeBaseObj_Convert); 106 PyMac_INIT_TOOLBOX_OBJECT_NEW(UserDataObj_New); 107 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(UserDataObj_Convert); 108 PyMac_INIT_TOOLBOX_OBJECT_NEW(MediaObj_New); 109 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(MediaObj_Convert); 110""" 111 112# Our (opaque) objects 113Movie = OpaqueByValueType('Movie', 'MovieObj') 114NullMovie = FakeType("(Movie)0") 115Track = OpaqueByValueType('Track', 'TrackObj') 116Media = OpaqueByValueType('Media', 'MediaObj') 117UserData = OpaqueByValueType('UserData', 'UserDataObj') 118TimeBase = OpaqueByValueType('TimeBase', 'TimeBaseObj') 119MovieController = OpaqueByValueType('MovieController', 'MovieCtlObj') 120 121# Other opaque objects 122Component = OpaqueByValueType('Component', 'CmpObj') 123MediaHandlerComponent = OpaqueByValueType('MediaHandlerComponent', 'CmpObj') 124DataHandlerComponent = OpaqueByValueType('DataHandlerComponent', 'CmpObj') 125 126ComponentInstance = OpaqueByValueType('ComponentInstance', 'CmpInstObj') 127MediaHandler = OpaqueByValueType('MediaHandler', 'CmpInstObj') 128DataHandler = OpaqueByValueType('DataHandler', 'CmpInstObj') 129 130RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") 131PicHandle = OpaqueByValueType("PicHandle", "ResObj") 132CTabHandle = OpaqueByValueType("CTabHandle", "ResObj") 133PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj") 134SampleDescriptionHandle = OpaqueByValueType("SampleDescriptionHandle", "ResObj") 135ImageDescriptionHandle = OpaqueByValueType("ImageDescriptionHandle", "ResObj") 136TextDescriptionHandle = OpaqueByValueType("TextDescriptionHandle", "ResObj") 137TEHandle = OpaqueByValueType("TEHandle", "ResObj") 138CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj") 139GDHandle = OpaqueByValueType("GDHandle", "OptResObj") 140AliasHandle = OpaqueByValueType("AliasHandle", "ResObj") 141SoundDescriptionHandle = OpaqueByValueType("SoundDescriptionHandle", "ResObj") 142# Silly Apple, passing an OStype by reference... 143OSType_ptr = OpaqueType("OSType", "PyMac_BuildOSType", "PyMac_GetOSType") 144# And even sillier: passing floats by address 145float_ptr = ByAddressType("float", "f") 146 147RGBColor = OpaqueType("RGBColor", "QdRGB") 148RGBColor_ptr = RGBColor 149TimeRecord = OpaqueType("TimeRecord", "QtTimeRecord") 150TimeRecord_ptr = TimeRecord 151 152# Non-opaque types, mostly integer-ish 153TimeValue = Type("TimeValue", "l") 154TimeScale = Type("TimeScale", "l") 155TimeBaseFlags = Type("TimeBaseFlags", "l") 156QTCallBackFlags = Type("QTCallBackFlags", "H") 157TimeBaseStatus = Type("TimeBaseStatus", "l") 158QTCallBackType = Type("QTCallBackType", "H") 159nextTimeFlagsEnum = Type("nextTimeFlagsEnum", "H") 160createMovieFileFlagsEnum = Type("createMovieFileFlagsEnum", "l") 161movieFlattenFlagsEnum = Type("movieFlattenFlagsEnum", "l") 162dataRefAttributesFlags = Type("dataRefAttributesFlags", "l") 163playHintsEnum = Type("playHintsEnum", "l") 164mediaHandlerFlagsEnum = Type("mediaHandlerFlagsEnum", "l") 165ComponentResult = Type("ComponentResult", "l") 166HandlerError = Type("HandlerError", "l") 167Ptr = InputOnlyType("Ptr", "s") 168StringPtr = Type("StringPtr", "s") 169mcactionparams = InputOnlyType("void *", "s") 170QTParameterDialog = Type("QTParameterDialog", "l") 171QTAtomID = Type("QTAtomID", "l") 172MCInterfaceElement = Type("MCInterfaceElement", "l") 173CodecType = OSTypeType("CodecType") 174GWorldPtr = OpaqueByValueType("GWorldPtr", "GWorldObj") 175QTFloatSingle = Type("QTFloatSingle", "f") 176 177# Could-not-be-bothered-types (NewMovieFromFile) 178dummyshortptr = FakeType('(short *)0') 179dummyStringPtr = FakeType('(StringPtr)0') 180 181class MovieObjectDefinition(GlobalObjectDefinition): 182 def outputCheckNewArg(self): 183 Output("""if (itself == NULL) { 184 PyErr_SetString(Qt_Error,"Cannot create null Movie"); 185 return NULL; 186 }""") 187 def outputFreeIt(self, itselfname): 188 Output("DisposeMovie(%s);", itselfname) 189 190class TrackObjectDefinition(GlobalObjectDefinition): 191 def outputCheckNewArg(self): 192 Output("""if (itself == NULL) { 193 PyErr_SetString(Qt_Error,"Cannot create null Track"); 194 return NULL; 195 }""") 196 def outputFreeIt(self, itselfname): 197 Output("DisposeMovieTrack(%s);", itselfname) 198 199class MediaObjectDefinition(GlobalObjectDefinition): 200 def outputCheckNewArg(self): 201 Output("""if (itself == NULL) { 202 PyErr_SetString(Qt_Error,"Cannot create null Media"); 203 return NULL; 204 }""") 205 def outputFreeIt(self, itselfname): 206 Output("DisposeTrackMedia(%s);", itselfname) 207 208class UserDataObjectDefinition(GlobalObjectDefinition): 209 def outputCheckNewArg(self): 210 Output("""if (itself == NULL) { 211 PyErr_SetString(Qt_Error,"Cannot create null UserData"); 212 return NULL; 213 }""") 214 def outputFreeIt(self, itselfname): 215 Output("DisposeUserData(%s);", itselfname) 216 217class TimeBaseObjectDefinition(GlobalObjectDefinition): 218 def outputCheckNewArg(self): 219 Output("""if (itself == NULL) { 220 PyErr_SetString(Qt_Error,"Cannot create null TimeBase"); 221 return NULL; 222 }""") 223## def outputFreeIt(self, itselfname): 224## Output("DisposeTimeBase(%s);", itselfname) 225 226class MovieCtlObjectDefinition(GlobalObjectDefinition): 227 def outputCheckNewArg(self): 228 Output("""if (itself == NULL) { 229 PyErr_SetString(Qt_Error,"Cannot create null MovieController"); 230 return NULL; 231 }""") 232 def outputFreeIt(self, itselfname): 233 Output("DisposeMovieController(%s);", itselfname) 234 235# From here on it's basically all boiler plate... 236 237# Create the generator groups and link them 238module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) 239Movie_object = MovieObjectDefinition('Movie', 'MovieObj', 'Movie') 240Track_object = TrackObjectDefinition('Track', 'TrackObj', 'Track') 241Media_object = MediaObjectDefinition('Media', 'MediaObj', 'Media') 242UserData_object = UserDataObjectDefinition('UserData', 'UserDataObj', 'UserData') 243TimeBase_object = TimeBaseObjectDefinition('TimeBase', 'TimeBaseObj', 'TimeBase') 244MovieController_object = MovieCtlObjectDefinition('MovieController', 'MovieCtlObj', 'MovieController') 245 246module.addobject(MovieController_object) 247module.addobject(TimeBase_object) 248module.addobject(UserData_object) 249module.addobject(Media_object) 250module.addobject(Track_object) 251module.addobject(Movie_object) 252 253# Create the generator classes used to populate the lists 254Function = OSErrFunctionGenerator 255Method = OSErrMethodGenerator 256 257# Create and populate the lists 258functions = [] 259MovieController_methods = [] 260TimeBase_methods = [] 261UserData_methods = [] 262Media_methods = [] 263Track_methods = [] 264Movie_methods = [] 265execfile(INPUTFILE) 266 267# 268# Some functions from ImageCompression.h that we need: 269ICMAlignmentProcRecordPtr = FakeType('(ICMAlignmentProcRecordPtr)0') 270dummyRect = FakeType('(Rect *)0') 271 272f = Function(void, 'AlignWindow', 273 (WindowPtr, 'wp', InMode), 274 (Boolean, 'front', InMode), 275 (dummyRect, 'alignmentRect', InMode), 276 (ICMAlignmentProcRecordPtr, 'alignmentProc', InMode), 277) 278functions.append(f) 279 280f = Function(void, 'DragAlignedWindow', 281 (WindowPtr, 'wp', InMode), 282 (Point, 'startPt', InMode), 283 (Rect_ptr, 'boundsRect', InMode), 284 (dummyRect, 'alignmentRect', InMode), 285 (ICMAlignmentProcRecordPtr, 'alignmentProc', InMode), 286) 287functions.append(f) 288 289# And we want the version of MoviesTask without a movie argument 290f = Function(void, 'MoviesTask', 291 (NullMovie, 'theMovie', InMode), 292 (long, 'maxMilliSecToUse', InMode), 293) 294functions.append(f) 295 296# And we want a GetMediaNextInterestingTime without duration 297f = Method(void, 'GetMediaNextInterestingTimeOnly', 298 (Media, 'theMedia', InMode), 299 (short, 'interestingTimeFlags', InMode), 300 (TimeValue, 'time', InMode), 301 (Fixed, 'rate', InMode), 302 (TimeValue, 'interestingTime', OutMode), 303) 304Media_methods.append(f) 305 306# add the populated lists to the generator groups 307# (in a different wordl the scan program would generate this) 308for f in functions: module.add(f) 309for f in MovieController_methods: MovieController_object.add(f) 310for f in TimeBase_methods: TimeBase_object.add(f) 311for f in UserData_methods: UserData_object.add(f) 312for f in Media_methods: Media_object.add(f) 313for f in Track_methods: Track_object.add(f) 314for f in Movie_methods: Movie_object.add(f) 315 316# generate output (open the output file as late as possible) 317SetOutputFileName(OUTPUTFILE) 318module.generate() 319 320