| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
import string |
| 7 |
|
| 8 |
|
| 9 |
MACHEADERFILE = 'QDOffscreen.h' |
| 10 |
MODNAME = '_Qdoffs' |
| 11 |
OBJECTNAME = 'GWorld' |
| 12 |
|
| 13 |
|
| 14 |
MODPREFIX = 'Qdoffs' |
| 15 |
OBJECTTYPE = OBJECTNAME + 'Ptr' |
| 16 |
OBJECTPREFIX = OBJECTNAME + 'Obj' |
| 17 |
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' |
| 18 |
|
| 19 |
OUTPUTFILE = MODNAME + "module.c" |
| 20 |
|
| 21 |
from macsupport import * |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
GWorldPtr = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) |
| 26 |
GWorldFlags = Type("GWorldFlags", "l") |
| 27 |
GDHandle = OpaqueByValueType("GDHandle", "ResObj") |
| 28 |
OptGDHandle = OpaqueByValueType("GDHandle", "OptResObj") |
| 29 |
CTabHandle = OpaqueByValueType("CTabHandle", "OptResObj") |
| 30 |
PixPatHandle = OpaqueByValueType("PixPatHandle", "ResObj") |
| 31 |
PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj") |
| 32 |
CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj") |
| 33 |
GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj") |
| 34 |
QDErr = OSErrType("QDErr", 'h') |
| 35 |
|
| 36 |
includestuff = includestuff + """ |
| 37 |
#include <Carbon/Carbon.h> |
| 38 |
|
| 39 |
#ifdef USE_TOOLBOX_OBJECT_GLUE |
| 40 |
extern PyObject *_GWorldObj_New(GWorldPtr); |
| 41 |
extern int _GWorldObj_Convert(PyObject *, GWorldPtr *); |
| 42 |
|
| 43 |
#define GWorldObj_New _GWorldObj_New |
| 44 |
#define GWorldObj_Convert _GWorldObj_Convert |
| 45 |
#endif |
| 46 |
|
| 47 |
#define as_GrafPtr(gworld) ((GrafPtr)(gworld)) |
| 48 |
|
| 49 |
""" |
| 50 |
|
| 51 |
initstuff = initstuff + """ |
| 52 |
PyMac_INIT_TOOLBOX_OBJECT_NEW(GWorldPtr, GWorldObj_New); |
| 53 |
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(GWorldPtr, GWorldObj_Convert); |
| 54 |
""" |
| 55 |
|
| 56 |
class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition): |
| 57 |
|
| 58 |
def outputCheckNewArg(self): |
| 59 |
Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
def outputFreeIt(self, itselfname): |
| 73 |
Output("DisposeGWorld(%s);", itselfname) |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) |
| 78 |
object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) |
| 79 |
module.addobject(object) |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
Function = OSErrWeakLinkFunctionGenerator |
| 84 |
Method = OSErrWeakLinkMethodGenerator |
| 85 |
|
| 86 |
|
| 87 |
functions = [] |
| 88 |
methods = [] |
| 89 |
execfile(INPUTFILE) |
| 90 |
|
| 91 |
|
| 92 |
f = Method(GrafPtr, 'as_GrafPtr', (GWorldPtr, 'p', InMode)) |
| 93 |
methods.append(f) |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
pixmapgetbytes_body = """ |
| 98 |
PixMapHandle pm; |
| 99 |
int from, length; |
| 100 |
char *cp; |
| 101 |
|
| 102 |
if ( !PyArg_ParseTuple(_args, "O&ii", ResObj_Convert, &pm, &from, &length) ) |
| 103 |
return NULL; |
| 104 |
cp = GetPixBaseAddr(pm)+from; |
| 105 |
_res = PyString_FromStringAndSize(cp, length); |
| 106 |
return _res; |
| 107 |
""" |
| 108 |
f = ManualGenerator("GetPixMapBytes", pixmapgetbytes_body) |
| 109 |
f.docstring = lambda: """(pixmap, int start, int size) -> string. Return bytes from the pixmap""" |
| 110 |
functions.append(f) |
| 111 |
|
| 112 |
|
| 113 |
pixmapputbytes_body = """ |
| 114 |
PixMapHandle pm; |
| 115 |
int from, length; |
| 116 |
char *cp, *icp; |
| 117 |
|
| 118 |
if ( !PyArg_ParseTuple(_args, "O&is#", ResObj_Convert, &pm, &from, &icp, &length) ) |
| 119 |
return NULL; |
| 120 |
cp = GetPixBaseAddr(pm)+from; |
| 121 |
memcpy(cp, icp, length); |
| 122 |
Py_INCREF(Py_None); |
| 123 |
_res = Py_None; |
| 124 |
return _res; |
| 125 |
""" |
| 126 |
f = ManualGenerator("PutPixMapBytes", pixmapputbytes_body) |
| 127 |
f.docstring = lambda: """(pixmap, int start, string data). Store bytes into the pixmap""" |
| 128 |
functions.append(f) |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
for f in functions: module.add(f) |
| 133 |
for f in methods: object.add(f) |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
SetOutputFileName(OUTPUTFILE) |
| 139 |
module.generate() |