| 1 | n/a | # This script generates a Python interface for an Apple Macintosh Manager. |
|---|
| 2 | n/a | # It uses the "bgen" package to generate C code. |
|---|
| 3 | n/a | # The function specifications are generated by scanning the mamager's header file, |
|---|
| 4 | n/a | # using the "scantools" package (customized for this particular manager). |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | import string |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | # Declarations that change for each manager |
|---|
| 9 | n/a | MACHEADERFILE = 'QuickDraw.h' # The Apple header file |
|---|
| 10 | n/a | MODNAME = '_Qd' # The name of the module |
|---|
| 11 | n/a | OBJECTNAME = 'Graf' # The basic name of the objects used here |
|---|
| 12 | n/a | |
|---|
| 13 | n/a | # The following is *usually* unchanged but may still require tuning |
|---|
| 14 | n/a | MODPREFIX = 'Qd' # The prefix for module-wide routines |
|---|
| 15 | n/a | OBJECTTYPE = OBJECTNAME + 'Ptr' # The C type used to represent them |
|---|
| 16 | n/a | OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods |
|---|
| 17 | n/a | INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner |
|---|
| 18 | n/a | EXTRAFILE = string.lower(MODPREFIX) + 'edit.py' # A similar file but hand-made |
|---|
| 19 | n/a | OUTPUTFILE = MODNAME + "module.c" # The file generated by this program |
|---|
| 20 | n/a | |
|---|
| 21 | n/a | from macsupport import * |
|---|
| 22 | n/a | |
|---|
| 23 | n/a | # Create the type objects |
|---|
| 24 | n/a | |
|---|
| 25 | n/a | class TextThingieClass(FixedInputBufferType): |
|---|
| 26 | n/a | def getargsCheck(self, name): |
|---|
| 27 | n/a | Output("/* Fool compiler warnings */") |
|---|
| 28 | n/a | Output("%s__in_len__ = %s__in_len__;", name, name) |
|---|
| 29 | n/a | |
|---|
| 30 | n/a | def declareSize(self, name): |
|---|
| 31 | n/a | Output("int %s__in_len__;", name) |
|---|
| 32 | n/a | |
|---|
| 33 | n/a | TextThingie = TextThingieClass(None) |
|---|
| 34 | n/a | |
|---|
| 35 | n/a | # These are temporary! |
|---|
| 36 | n/a | RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") |
|---|
| 37 | n/a | OptRgnHandle = OpaqueByValueType("RgnHandle", "OptResObj") |
|---|
| 38 | n/a | PicHandle = OpaqueByValueType("PicHandle", "ResObj") |
|---|
| 39 | n/a | PolyHandle = OpaqueByValueType("PolyHandle", "ResObj") |
|---|
| 40 | n/a | PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj") |
|---|
| 41 | n/a | PixPatHandle = OpaqueByValueType("PixPatHandle", "ResObj") |
|---|
| 42 | n/a | PatHandle = OpaqueByValueType("PatHandle", "ResObj") |
|---|
| 43 | n/a | CursHandle = OpaqueByValueType("CursHandle", "ResObj") |
|---|
| 44 | n/a | CCrsrHandle = OpaqueByValueType("CCrsrHandle", "ResObj") |
|---|
| 45 | n/a | CIconHandle = OpaqueByValueType("CIconHandle", "ResObj") |
|---|
| 46 | n/a | CTabHandle = OpaqueByValueType("CTabHandle", "ResObj") |
|---|
| 47 | n/a | ITabHandle = OpaqueByValueType("ITabHandle", "ResObj") |
|---|
| 48 | n/a | GDHandle = OpaqueByValueType("GDHandle", "ResObj") |
|---|
| 49 | n/a | CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj") |
|---|
| 50 | n/a | GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj") |
|---|
| 51 | n/a | BitMap_ptr = OpaqueByValueType("BitMapPtr", "BMObj") |
|---|
| 52 | n/a | const_BitMap_ptr = OpaqueByValueType("const BitMap *", "BMObj") |
|---|
| 53 | n/a | BitMap = OpaqueType("BitMap", "BMObj_NewCopied", "BUG") |
|---|
| 54 | n/a | RGBColor = OpaqueType('RGBColor', 'QdRGB') |
|---|
| 55 | n/a | RGBColor_ptr = RGBColor |
|---|
| 56 | n/a | FontInfo = OpaqueType('FontInfo', 'QdFI') |
|---|
| 57 | n/a | Component = OpaqueByValueType('Component', 'CmpObj') |
|---|
| 58 | n/a | ComponentInstance = OpaqueByValueType('ComponentInstance', 'CmpInstObj') |
|---|
| 59 | n/a | |
|---|
| 60 | n/a | Cursor = StructOutputBufferType('Cursor') |
|---|
| 61 | n/a | Cursor_ptr = StructInputBufferType('Cursor') |
|---|
| 62 | n/a | Pattern = StructOutputBufferType('Pattern') |
|---|
| 63 | n/a | Pattern_ptr = StructInputBufferType('Pattern') |
|---|
| 64 | n/a | PenState = StructOutputBufferType('PenState') |
|---|
| 65 | n/a | PenState_ptr = StructInputBufferType('PenState') |
|---|
| 66 | n/a | TruncCode = Type("TruncCode", "h") |
|---|
| 67 | n/a | |
|---|
| 68 | n/a | includestuff = includestuff + """ |
|---|
| 69 | n/a | #include <Carbon/Carbon.h> |
|---|
| 70 | n/a | |
|---|
| 71 | n/a | #ifdef USE_TOOLBOX_OBJECT_GLUE |
|---|
| 72 | n/a | extern PyObject *_GrafObj_New(GrafPtr); |
|---|
| 73 | n/a | extern int _GrafObj_Convert(PyObject *, GrafPtr *); |
|---|
| 74 | n/a | extern PyObject *_BMObj_New(BitMapPtr); |
|---|
| 75 | n/a | extern int _BMObj_Convert(PyObject *, BitMapPtr *); |
|---|
| 76 | n/a | extern PyObject *_QdRGB_New(RGBColorPtr); |
|---|
| 77 | n/a | extern int _QdRGB_Convert(PyObject *, RGBColorPtr); |
|---|
| 78 | n/a | |
|---|
| 79 | n/a | #define GrafObj_New _GrafObj_New |
|---|
| 80 | n/a | #define GrafObj_Convert _GrafObj_Convert |
|---|
| 81 | n/a | #define BMObj_New _BMObj_New |
|---|
| 82 | n/a | #define BMObj_Convert _BMObj_Convert |
|---|
| 83 | n/a | #define QdRGB_New _QdRGB_New |
|---|
| 84 | n/a | #define QdRGB_Convert _QdRGB_Convert |
|---|
| 85 | n/a | #endif |
|---|
| 86 | n/a | |
|---|
| 87 | n/a | static PyObject *BMObj_NewCopied(BitMapPtr); |
|---|
| 88 | n/a | |
|---|
| 89 | n/a | /* |
|---|
| 90 | n/a | ** Parse/generate RGB records |
|---|
| 91 | n/a | */ |
|---|
| 92 | n/a | PyObject *QdRGB_New(RGBColorPtr itself) |
|---|
| 93 | n/a | { |
|---|
| 94 | n/a | |
|---|
| 95 | n/a | return Py_BuildValue("lll", (long)itself->red, (long)itself->green, (long)itself->blue); |
|---|
| 96 | n/a | } |
|---|
| 97 | n/a | |
|---|
| 98 | n/a | int QdRGB_Convert(PyObject *v, RGBColorPtr p_itself) |
|---|
| 99 | n/a | { |
|---|
| 100 | n/a | long red, green, blue; |
|---|
| 101 | n/a | |
|---|
| 102 | n/a | if( !PyArg_ParseTuple(v, "lll", &red, &green, &blue) ) |
|---|
| 103 | n/a | return 0; |
|---|
| 104 | n/a | p_itself->red = (unsigned short)red; |
|---|
| 105 | n/a | p_itself->green = (unsigned short)green; |
|---|
| 106 | n/a | p_itself->blue = (unsigned short)blue; |
|---|
| 107 | n/a | return 1; |
|---|
| 108 | n/a | } |
|---|
| 109 | n/a | |
|---|
| 110 | n/a | /* |
|---|
| 111 | n/a | ** Generate FontInfo records |
|---|
| 112 | n/a | */ |
|---|
| 113 | n/a | static |
|---|
| 114 | n/a | PyObject *QdFI_New(FontInfo *itself) |
|---|
| 115 | n/a | { |
|---|
| 116 | n/a | |
|---|
| 117 | n/a | return Py_BuildValue("hhhh", itself->ascent, itself->descent, |
|---|
| 118 | n/a | itself->widMax, itself->leading); |
|---|
| 119 | n/a | } |
|---|
| 120 | n/a | """ |
|---|
| 121 | n/a | |
|---|
| 122 | n/a | finalstuff = finalstuff + """ |
|---|
| 123 | n/a | /* Like BMObj_New, but the original bitmap data structure is copied (and |
|---|
| 124 | n/a | ** released when the object is released) |
|---|
| 125 | n/a | */ |
|---|
| 126 | n/a | PyObject *BMObj_NewCopied(BitMapPtr itself) |
|---|
| 127 | n/a | { |
|---|
| 128 | n/a | BitMapObject *it; |
|---|
| 129 | n/a | BitMapPtr itself_copy; |
|---|
| 130 | n/a | |
|---|
| 131 | n/a | if ((itself_copy=(BitMapPtr)malloc(sizeof(BitMap))) == NULL) |
|---|
| 132 | n/a | return PyErr_NoMemory(); |
|---|
| 133 | n/a | *itself_copy = *itself; |
|---|
| 134 | n/a | it = (BitMapObject *)BMObj_New(itself_copy); |
|---|
| 135 | n/a | it->referred_bitmap = itself_copy; |
|---|
| 136 | n/a | return (PyObject *)it; |
|---|
| 137 | n/a | } |
|---|
| 138 | n/a | |
|---|
| 139 | n/a | """ |
|---|
| 140 | n/a | |
|---|
| 141 | n/a | variablestuff = "" |
|---|
| 142 | n/a | |
|---|
| 143 | n/a | initstuff = initstuff + """ |
|---|
| 144 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(BitMapPtr, BMObj_New); |
|---|
| 145 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(BitMapPtr, BMObj_Convert); |
|---|
| 146 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(GrafPtr, GrafObj_New); |
|---|
| 147 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(GrafPtr, GrafObj_Convert); |
|---|
| 148 | n/a | PyMac_INIT_TOOLBOX_OBJECT_NEW(RGBColorPtr, QdRGB_New); |
|---|
| 149 | n/a | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(RGBColor, QdRGB_Convert); |
|---|
| 150 | n/a | """ |
|---|
| 151 | n/a | |
|---|
| 152 | n/a | ## not yet... |
|---|
| 153 | n/a | ## |
|---|
| 154 | n/a | ##class Region_ObjectDefinition(GlobalObjectDefinition): |
|---|
| 155 | n/a | ## def outputCheckNewArg(self): |
|---|
| 156 | n/a | ## Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
|---|
| 157 | n/a | ## def outputFreeIt(self, itselfname): |
|---|
| 158 | n/a | ## Output("DisposeRegion(%s);", itselfname) |
|---|
| 159 | n/a | ## |
|---|
| 160 | n/a | ##class Polygon_ObjectDefinition(GlobalObjectDefinition): |
|---|
| 161 | n/a | ## def outputCheckNewArg(self): |
|---|
| 162 | n/a | ## Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
|---|
| 163 | n/a | ## def outputFreeIt(self, itselfname): |
|---|
| 164 | n/a | ## Output("KillPoly(%s);", itselfname) |
|---|
| 165 | n/a | |
|---|
| 166 | n/a | class MyGRObjectDefinition(PEP253Mixin, GlobalObjectDefinition): |
|---|
| 167 | n/a | getsetlist = [ |
|---|
| 168 | n/a | ('visRgn', |
|---|
| 169 | n/a | """RgnHandle h=NewRgn(); /* XXXX wrong dispose routine */ |
|---|
| 170 | n/a | return Py_BuildValue("O&", ResObj_New, (Handle)GetPortVisibleRegion(self->ob_itself, h)); |
|---|
| 171 | n/a | """, |
|---|
| 172 | n/a | None, |
|---|
| 173 | n/a | "Convenience attribute: return a copy of the visible region" |
|---|
| 174 | n/a | ), ( |
|---|
| 175 | n/a | 'clipRgn', |
|---|
| 176 | n/a | """RgnHandle h=NewRgn(); /* XXXX wrong dispose routine */ |
|---|
| 177 | n/a | return Py_BuildValue("O&", ResObj_New, (Handle)GetPortClipRegion(self->ob_itself, h)); |
|---|
| 178 | n/a | """, |
|---|
| 179 | n/a | None, |
|---|
| 180 | n/a | "Convenience attribute: return a copy of the clipping region" |
|---|
| 181 | n/a | )] |
|---|
| 182 | n/a | def outputCheckNewArg(self): |
|---|
| 183 | n/a | Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
|---|
| 184 | n/a | def outputCheckConvertArg(self): |
|---|
| 185 | n/a | Output("#if 1") |
|---|
| 186 | n/a | OutLbrace() |
|---|
| 187 | n/a | Output("WindowRef win;") |
|---|
| 188 | n/a | OutLbrace("if (WinObj_Convert(v, &win) && v)") |
|---|
| 189 | n/a | Output("*p_itself = (GrafPtr)GetWindowPort(win);") |
|---|
| 190 | n/a | Output("return 1;") |
|---|
| 191 | n/a | OutRbrace() |
|---|
| 192 | n/a | Output("PyErr_Clear();") |
|---|
| 193 | n/a | OutRbrace() |
|---|
| 194 | n/a | Output("#else") |
|---|
| 195 | n/a | OutLbrace("if (DlgObj_Check(v))") |
|---|
| 196 | n/a | Output("DialogRef dlg = (DialogRef)((GrafPortObject *)v)->ob_itself;") |
|---|
| 197 | n/a | Output("*p_itself = (GrafPtr)GetWindowPort(GetDialogWindow(dlg));") |
|---|
| 198 | n/a | Output("return 1;") |
|---|
| 199 | n/a | OutRbrace() |
|---|
| 200 | n/a | OutLbrace("if (WinObj_Check(v))") |
|---|
| 201 | n/a | Output("WindowRef win = (WindowRef)((GrafPortObject *)v)->ob_itself;") |
|---|
| 202 | n/a | Output("*p_itself = (GrafPtr)GetWindowPort(win);") |
|---|
| 203 | n/a | Output("return 1;") |
|---|
| 204 | n/a | OutRbrace() |
|---|
| 205 | n/a | Output("#endif") |
|---|
| 206 | n/a | |
|---|
| 207 | n/a | class MyBMObjectDefinition(PEP253Mixin, GlobalObjectDefinition): |
|---|
| 208 | n/a | getsetlist = [ |
|---|
| 209 | n/a | ( |
|---|
| 210 | n/a | 'baseAddr', |
|---|
| 211 | n/a | 'return PyInt_FromLong((long)self->ob_itself->baseAddr);', |
|---|
| 212 | n/a | None, |
|---|
| 213 | n/a | None |
|---|
| 214 | n/a | ), ( |
|---|
| 215 | n/a | 'rowBytes', |
|---|
| 216 | n/a | 'return PyInt_FromLong((long)self->ob_itself->rowBytes);', |
|---|
| 217 | n/a | None, |
|---|
| 218 | n/a | None |
|---|
| 219 | n/a | ), ( |
|---|
| 220 | n/a | 'bounds', |
|---|
| 221 | n/a | 'return Py_BuildValue("O&", PyMac_BuildRect, &self->ob_itself->bounds);', |
|---|
| 222 | n/a | None, |
|---|
| 223 | n/a | None |
|---|
| 224 | n/a | ), ( |
|---|
| 225 | n/a | 'bitmap_data', |
|---|
| 226 | n/a | 'return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(BitMap));', |
|---|
| 227 | n/a | None, |
|---|
| 228 | n/a | None |
|---|
| 229 | n/a | ), ( |
|---|
| 230 | n/a | 'pixmap_data', |
|---|
| 231 | n/a | 'return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(PixMap));', |
|---|
| 232 | n/a | None, |
|---|
| 233 | n/a | None |
|---|
| 234 | n/a | )] |
|---|
| 235 | n/a | def outputCheckNewArg(self): |
|---|
| 236 | n/a | Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
|---|
| 237 | n/a | def outputStructMembers(self): |
|---|
| 238 | n/a | # We need to more items: a pointer to privately allocated data |
|---|
| 239 | n/a | # and a python object we're referring to. |
|---|
| 240 | n/a | Output("%s ob_itself;", self.itselftype) |
|---|
| 241 | n/a | Output("PyObject *referred_object;") |
|---|
| 242 | n/a | Output("BitMap *referred_bitmap;") |
|---|
| 243 | n/a | def outputInitStructMembers(self): |
|---|
| 244 | n/a | Output("it->ob_itself = %sitself;", self.argref) |
|---|
| 245 | n/a | Output("it->referred_object = NULL;") |
|---|
| 246 | n/a | Output("it->referred_bitmap = NULL;") |
|---|
| 247 | n/a | def outputCleanupStructMembers(self): |
|---|
| 248 | n/a | Output("Py_XDECREF(self->referred_object);") |
|---|
| 249 | n/a | Output("if (self->referred_bitmap) free(self->referred_bitmap);") |
|---|
| 250 | n/a | |
|---|
| 251 | n/a | # Create the generator groups and link them |
|---|
| 252 | n/a | module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff, variablestuff) |
|---|
| 253 | n/a | ##r_object = Region_ObjectDefinition('Region', 'QdRgn', 'RgnHandle') |
|---|
| 254 | n/a | ##po_object = Polygon_ObjectDefinition('Polygon', 'QdPgn', 'PolyHandle') |
|---|
| 255 | n/a | ##module.addobject(r_object) |
|---|
| 256 | n/a | ##module.addobject(po_object) |
|---|
| 257 | n/a | gr_object = MyGRObjectDefinition("GrafPort", "GrafObj", "GrafPtr") |
|---|
| 258 | n/a | module.addobject(gr_object) |
|---|
| 259 | n/a | bm_object = MyBMObjectDefinition("BitMap", "BMObj", "BitMapPtr") |
|---|
| 260 | n/a | module.addobject(bm_object) |
|---|
| 261 | n/a | |
|---|
| 262 | n/a | |
|---|
| 263 | n/a | # Create the generator classes used to populate the lists |
|---|
| 264 | n/a | Function = OSErrWeakLinkFunctionGenerator |
|---|
| 265 | n/a | Method = OSErrWeakLinkMethodGenerator |
|---|
| 266 | n/a | |
|---|
| 267 | n/a | # Create and populate the lists |
|---|
| 268 | n/a | functions = [] |
|---|
| 269 | n/a | gr_methods = [] |
|---|
| 270 | n/a | bm_methods = [] |
|---|
| 271 | n/a | #methods = [] |
|---|
| 272 | n/a | execfile(INPUTFILE) |
|---|
| 273 | n/a | execfile(EXTRAFILE) |
|---|
| 274 | n/a | |
|---|
| 275 | n/a | # add the populated lists to the generator groups |
|---|
| 276 | n/a | # (in a different wordl the scan program would generate this) |
|---|
| 277 | n/a | for f in functions: module.add(f) |
|---|
| 278 | n/a | for f in gr_methods: gr_object.add(f) |
|---|
| 279 | n/a | for f in bm_methods: bm_object.add(f) |
|---|
| 280 | n/a | |
|---|
| 281 | n/a | # Manual generator: get data out of a bitmap |
|---|
| 282 | n/a | getdata_body = """ |
|---|
| 283 | n/a | int from, length; |
|---|
| 284 | n/a | char *cp; |
|---|
| 285 | n/a | |
|---|
| 286 | n/a | if ( !PyArg_ParseTuple(_args, "ii", &from, &length) ) |
|---|
| 287 | n/a | return NULL; |
|---|
| 288 | n/a | cp = _self->ob_itself->baseAddr+from; |
|---|
| 289 | n/a | _res = PyString_FromStringAndSize(cp, length); |
|---|
| 290 | n/a | return _res; |
|---|
| 291 | n/a | """ |
|---|
| 292 | n/a | f = ManualGenerator("getdata", getdata_body) |
|---|
| 293 | n/a | f.docstring = lambda: """(int start, int size) -> string. Return bytes from the bitmap""" |
|---|
| 294 | n/a | bm_object.add(f) |
|---|
| 295 | n/a | |
|---|
| 296 | n/a | # Manual generator: store data in a bitmap |
|---|
| 297 | n/a | putdata_body = """ |
|---|
| 298 | n/a | int from, length; |
|---|
| 299 | n/a | char *cp, *icp; |
|---|
| 300 | n/a | |
|---|
| 301 | n/a | if ( !PyArg_ParseTuple(_args, "is#", &from, &icp, &length) ) |
|---|
| 302 | n/a | return NULL; |
|---|
| 303 | n/a | cp = _self->ob_itself->baseAddr+from; |
|---|
| 304 | n/a | memcpy(cp, icp, length); |
|---|
| 305 | n/a | Py_INCREF(Py_None); |
|---|
| 306 | n/a | _res = Py_None; |
|---|
| 307 | n/a | return _res; |
|---|
| 308 | n/a | """ |
|---|
| 309 | n/a | f = ManualGenerator("putdata", putdata_body) |
|---|
| 310 | n/a | f.docstring = lambda: """(int start, string data). Store bytes into the bitmap""" |
|---|
| 311 | n/a | bm_object.add(f) |
|---|
| 312 | n/a | |
|---|
| 313 | n/a | # |
|---|
| 314 | n/a | # We manually generate a routine to create a BitMap from python data. |
|---|
| 315 | n/a | # |
|---|
| 316 | n/a | BitMap_body = """ |
|---|
| 317 | n/a | BitMap *ptr; |
|---|
| 318 | n/a | PyObject *source; |
|---|
| 319 | n/a | Rect bounds; |
|---|
| 320 | n/a | int rowbytes; |
|---|
| 321 | n/a | char *data; |
|---|
| 322 | n/a | |
|---|
| 323 | n/a | if ( !PyArg_ParseTuple(_args, "O!iO&", &PyString_Type, &source, &rowbytes, PyMac_GetRect, |
|---|
| 324 | n/a | &bounds) ) |
|---|
| 325 | n/a | return NULL; |
|---|
| 326 | n/a | data = PyString_AsString(source); |
|---|
| 327 | n/a | if ((ptr=(BitMap *)malloc(sizeof(BitMap))) == NULL ) |
|---|
| 328 | n/a | return PyErr_NoMemory(); |
|---|
| 329 | n/a | ptr->baseAddr = (Ptr)data; |
|---|
| 330 | n/a | ptr->rowBytes = rowbytes; |
|---|
| 331 | n/a | ptr->bounds = bounds; |
|---|
| 332 | n/a | if ( (_res = BMObj_New(ptr)) == NULL ) { |
|---|
| 333 | n/a | free(ptr); |
|---|
| 334 | n/a | return NULL; |
|---|
| 335 | n/a | } |
|---|
| 336 | n/a | ((BitMapObject *)_res)->referred_object = source; |
|---|
| 337 | n/a | Py_INCREF(source); |
|---|
| 338 | n/a | ((BitMapObject *)_res)->referred_bitmap = ptr; |
|---|
| 339 | n/a | return _res; |
|---|
| 340 | n/a | """ |
|---|
| 341 | n/a | |
|---|
| 342 | n/a | f = ManualGenerator("BitMap", BitMap_body) |
|---|
| 343 | n/a | f.docstring = lambda: """Take (string, int, Rect) argument and create BitMap""" |
|---|
| 344 | n/a | module.add(f) |
|---|
| 345 | n/a | |
|---|
| 346 | n/a | # |
|---|
| 347 | n/a | # And again, for turning a correctly-formatted structure into the object |
|---|
| 348 | n/a | # |
|---|
| 349 | n/a | RawBitMap_body = """ |
|---|
| 350 | n/a | BitMap *ptr; |
|---|
| 351 | n/a | PyObject *source; |
|---|
| 352 | n/a | |
|---|
| 353 | n/a | if ( !PyArg_ParseTuple(_args, "O!", &PyString_Type, &source) ) |
|---|
| 354 | n/a | return NULL; |
|---|
| 355 | n/a | if ( PyString_Size(source) != sizeof(BitMap) && PyString_Size(source) != sizeof(PixMap) ) { |
|---|
| 356 | n/a | PyErr_Format(PyExc_TypeError, |
|---|
| 357 | n/a | "Argument size was %d, should be %d (sizeof BitMap) or %d (sizeof PixMap)", |
|---|
| 358 | n/a | PyString_Size(source), sizeof(BitMap), sizeof(PixMap)); |
|---|
| 359 | n/a | return NULL; |
|---|
| 360 | n/a | } |
|---|
| 361 | n/a | ptr = (BitMapPtr)PyString_AsString(source); |
|---|
| 362 | n/a | if ( (_res = BMObj_New(ptr)) == NULL ) { |
|---|
| 363 | n/a | return NULL; |
|---|
| 364 | n/a | } |
|---|
| 365 | n/a | ((BitMapObject *)_res)->referred_object = source; |
|---|
| 366 | n/a | Py_INCREF(source); |
|---|
| 367 | n/a | return _res; |
|---|
| 368 | n/a | """ |
|---|
| 369 | n/a | |
|---|
| 370 | n/a | f = ManualGenerator("RawBitMap", RawBitMap_body) |
|---|
| 371 | n/a | f.docstring = lambda: """Take string BitMap and turn into BitMap object""" |
|---|
| 372 | n/a | module.add(f) |
|---|
| 373 | n/a | |
|---|
| 374 | n/a | # generate output (open the output file as late as possible) |
|---|
| 375 | n/a | SetOutputFileName(OUTPUTFILE) |
|---|
| 376 | n/a | module.generate() |
|---|
| 377 | n/a | SetOutputFile() # Close it |
|---|