qtsupport.py 9.32 KB
Newer Older
1 2 3 4 5
# This script generates a Python interface for an Apple Macintosh Manager.
# It uses the "bgen" package to generate C code.
# The function specifications are generated by scanning the mamager's header file,
# using the "scantools" package (customized for this particular manager).

6 7
#error missing SetActionFilter

8 9 10 11
import string

# Declarations that change for each manager
MACHEADERFILE = 'Movies.h'		# The Apple header file
12
MODNAME = 'Qt'				# The name of the module
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
OBJECTNAME = 'Movie'			# The basic name of the objects used here

# The following is *usually* unchanged but may still require tuning
MODPREFIX = MODNAME			# The prefix for module-wide routines
OBJECTTYPE = "Movie"		# The C type used to represent them
OBJECTPREFIX = MODPREFIX + 'Obj'	# The prefix for object methods
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
OUTPUTFILE = MODNAME + "module.c"	# The file generated by this program

from macsupport import *

# Create the type objects

includestuff = includestuff + """
#include <%s>""" % MACHEADERFILE + """
28

29

30 31 32 33
/* Macro to allow us to GetNextInterestingTime without duration */
#define GetMediaNextInterestingTimeOnly(media, flags, time, rate, rv) \
			GetMediaNextInterestingTime(media, flags, time, rate, rv, NULL)
			
34 35 36 37 38 39 40
/*
** Parse/generate time records
*/
static PyObject *
QtTimeRecord_New(itself)
	TimeRecord *itself;
{
41 42
	if (itself->base)
		return Py_BuildValue("O&lO&", PyMac_Buildwide, &itself->value, itself->scale, 
43
			TimeBaseObj_New, itself->base);
44 45 46
	else
		return  Py_BuildValue("O&lO", PyMac_Buildwide, &itself->value, itself->scale, 
			Py_None);
47 48 49 50 51 52 53
}

static int
QtTimeRecord_Convert(v, p_itself)
	PyObject *v;
	TimeRecord *p_itself;
{
54 55 56
	PyObject *base = NULL;
	if( !PyArg_ParseTuple(v, "O&l|O", PyMac_Getwide, &p_itself->value, &p_itself->scale,
			&base) )
57
		return 0;
58 59 60 61 62
	if ( base == NULL || base == Py_None )
		p_itself->base = NULL;
	else
		if ( !TimeBaseObj_Convert(base, &p_itself->base) )
			return 0;
63 64 65
	return 1;
}

66 67


68 69
"""

70 71
# Our (opaque) objects
Movie = OpaqueByValueType('Movie', 'MovieObj')
72
NullMovie = FakeType("(Movie)0")
73 74 75 76
Track = OpaqueByValueType('Track', 'TrackObj')
Media = OpaqueByValueType('Media', 'MediaObj')
UserData = OpaqueByValueType('UserData', 'UserDataObj')
TimeBase = OpaqueByValueType('TimeBase', 'TimeBaseObj')
77
MovieController = OpaqueByValueType('MovieController', 'MovieCtlObj')
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

# Other opaque objects
Component = OpaqueByValueType('Component', 'CmpObj')
MediaHandlerComponent = OpaqueByValueType('MediaHandlerComponent', 'CmpObj')
DataHandlerComponent = OpaqueByValueType('DataHandlerComponent', 'CmpObj')

ComponentInstance = OpaqueByValueType('ComponentInstance', 'CmpInstObj')
MediaHandler = OpaqueByValueType('MediaHandler', 'CmpInstObj')
DataHandler = OpaqueByValueType('DataHandler', 'CmpInstObj')

RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
PicHandle = OpaqueByValueType("PicHandle", "ResObj")
CTabHandle = OpaqueByValueType("CTabHandle", "ResObj")
PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj")
SampleDescriptionHandle = OpaqueByValueType("SampleDescriptionHandle", "ResObj")
93
ImageDescriptionHandle = OpaqueByValueType("ImageDescriptionHandle", "ResObj")
94
TEHandle = OpaqueByValueType("TEHandle", "ResObj")
95
CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
96
GDHandle = OpaqueByValueType("GDHandle", "OptResObj")
97 98
AliasHandle = OpaqueByValueType("AliasHandle", "ResObj")
SoundDescriptionHandle = OpaqueByValueType("SoundDescriptionHandle", "ResObj")
99 100
# Silly Apple, passing an OStype by reference...
OSType_ptr = OpaqueType("OSType", "PyMac_BuildOSType", "PyMac_GetOSType")
101 102
# And even sillier: passing floats by address
float_ptr = ByAddressType("float", "f")
103 104

RGBColor = OpaqueType("RGBColor", "QdRGB")
105 106 107
RGBColor_ptr = RGBColor
TimeRecord = OpaqueType("TimeRecord", "QtTimeRecord")
TimeRecord_ptr = TimeRecord
108 109

# Non-opaque types, mostly integer-ish
110 111 112
TimeValue = Type("TimeValue", "l")
TimeScale = Type("TimeScale", "l")
TimeBaseFlags = Type("TimeBaseFlags", "l")
113
QTCallBackFlags = Type("QTCallBackFlags", "H")
114
TimeBaseStatus = Type("TimeBaseStatus", "l")
115 116
QTCallBackType = Type("QTCallBackType", "H")
nextTimeFlagsEnum = Type("nextTimeFlagsEnum", "H")
117 118 119 120 121
createMovieFileFlagsEnum = Type("createMovieFileFlagsEnum", "l")
movieFlattenFlagsEnum = Type("movieFlattenFlagsEnum", "l")
dataRefAttributesFlags = Type("dataRefAttributesFlags", "l")
playHintsEnum = Type("playHintsEnum", "l")
mediaHandlerFlagsEnum = Type("mediaHandlerFlagsEnum", "l")
122 123 124
ComponentResult = Type("ComponentResult", "l")
HandlerError = Type("HandlerError", "l")
Ptr = InputOnlyType("Ptr", "s")
125 126
StringPtr = Type("StringPtr", "s")
mcactionparams = InputOnlyType("void *", "s")
127 128 129
QTParameterDialog = Type("QTParameterDialog", "l")
QTAtomID = Type("QTAtomID", "l")
MCInterfaceElement = Type("MCInterfaceElement", "l")
130 131 132
# Could-not-be-bothered-types (NewMovieFromFile)
dummyshortptr = FakeType('(short *)0')
dummyStringPtr = FakeType('(StringPtr)0')
133

134
class MovieObjectDefinition(GlobalObjectDefinition):
135 136 137 138 139 140 141 142
	def outputCheckNewArg(self):
		Output("""if (itself == NULL) {
					PyErr_SetString(Qt_Error,"Cannot create null Movie");
					return NULL;
				}""")
	def outputFreeIt(self, itselfname):
		Output("DisposeMovie(%s);", itselfname)

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
class TrackObjectDefinition(GlobalObjectDefinition):
	def outputCheckNewArg(self):
		Output("""if (itself == NULL) {
					PyErr_SetString(Qt_Error,"Cannot create null Track");
					return NULL;
				}""")
	def outputFreeIt(self, itselfname):
		Output("DisposeMovieTrack(%s);", itselfname)

class MediaObjectDefinition(GlobalObjectDefinition):
	def outputCheckNewArg(self):
		Output("""if (itself == NULL) {
					PyErr_SetString(Qt_Error,"Cannot create null Media");
					return NULL;
				}""")
	def outputFreeIt(self, itselfname):
		Output("DisposeTrackMedia(%s);", itselfname)

class UserDataObjectDefinition(GlobalObjectDefinition):
	def outputCheckNewArg(self):
		Output("""if (itself == NULL) {
					PyErr_SetString(Qt_Error,"Cannot create null UserData");
					return NULL;
				}""")
	def outputFreeIt(self, itselfname):
		Output("DisposeUserData(%s);", itselfname)

class TimeBaseObjectDefinition(GlobalObjectDefinition):
	def outputCheckNewArg(self):
		Output("""if (itself == NULL) {
					PyErr_SetString(Qt_Error,"Cannot create null TimeBase");
					return NULL;
				}""")
176 177
##	def outputFreeIt(self, itselfname):
##		Output("DisposeTimeBase(%s);", itselfname)
178

179 180 181 182 183 184 185 186 187
class MovieCtlObjectDefinition(GlobalObjectDefinition):
	def outputCheckNewArg(self):
		Output("""if (itself == NULL) {
					PyErr_SetString(Qt_Error,"Cannot create null MovieController");
					return NULL;
				}""")
	def outputFreeIt(self, itselfname):
		Output("DisposeMovieController(%s);", itselfname)

188 189 190 191
# From here on it's basically all boiler plate...

# Create the generator groups and link them
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
192 193 194 195 196
Movie_object = MovieObjectDefinition('Movie', 'MovieObj', 'Movie')
Track_object = TrackObjectDefinition('Track', 'TrackObj', 'Track')
Media_object = MediaObjectDefinition('Media', 'MediaObj', 'Media')
UserData_object = UserDataObjectDefinition('UserData', 'UserDataObj', 'UserData')
TimeBase_object = TimeBaseObjectDefinition('TimeBase', 'TimeBaseObj', 'TimeBase')
197
MovieController_object = MovieCtlObjectDefinition('MovieController', 'MovieCtlObj', 'MovieController')
198

199
module.addobject(MovieController_object)
200 201 202 203 204
module.addobject(TimeBase_object)
module.addobject(UserData_object)
module.addobject(Media_object)
module.addobject(Track_object)
module.addobject(Movie_object)
205 206

# Create the generator classes used to populate the lists
207 208
Function = OSErrFunctionGenerator
Method = OSErrMethodGenerator
209 210 211

# Create and populate the lists
functions = []
212
MovieController_methods = []
213 214 215 216 217
TimeBase_methods = []
UserData_methods = []
Media_methods = []
Track_methods = []
Movie_methods = []
218 219
execfile(INPUTFILE)

220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
#
# Some functions from ImageCompression.h that we need:
ICMAlignmentProcRecordPtr = FakeType('(ICMAlignmentProcRecordPtr)0')
dummyRect = FakeType('(Rect *)0')

f = Function(void, 'AlignWindow',
	(WindowPtr, 'wp', InMode),
	(Boolean, 'front', InMode),
	(dummyRect, 'alignmentRect', InMode),
	(ICMAlignmentProcRecordPtr, 'alignmentProc', InMode),
)
functions.append(f)

f = Function(void, 'DragAlignedWindow',
	(WindowPtr, 'wp', InMode),
	(Point, 'startPt', InMode),
	(Rect_ptr, 'boundsRect', InMode),
	(dummyRect, 'alignmentRect', InMode),
	(ICMAlignmentProcRecordPtr, 'alignmentProc', InMode),
)
functions.append(f)

242 243 244 245 246 247 248
# And we want the version of MoviesTask without a movie argument
f = Function(void, 'MoviesTask',
    (NullMovie, 'theMovie', InMode),
    (long, 'maxMilliSecToUse', InMode),
)
functions.append(f)

249 250 251 252 253 254 255 256 257
# And we want a GetMediaNextInterestingTime without duration
f = Method(void, 'GetMediaNextInterestingTimeOnly',
    (Media, 'theMedia', InMode),
    (short, 'interestingTimeFlags', InMode),
    (TimeValue, 'time', InMode),
    (Fixed, 'rate', InMode),
    (TimeValue, 'interestingTime', OutMode),
)
Media_methods.append(f)
258

259 260 261
# add the populated lists to the generator groups
# (in a different wordl the scan program would generate this)
for f in functions: module.add(f)
262
for f in MovieController_methods: MovieController_object.add(f)
263 264 265 266 267
for f in TimeBase_methods: TimeBase_object.add(f)
for f in UserData_methods: UserData_object.add(f)
for f in Media_methods: Media_object.add(f)
for f in Track_methods: Track_object.add(f)
for f in Movie_methods: Movie_object.add(f)
268 269 270 271 272

# generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE)
module.generate()