Fixed access to Quickdraw globals. Unfortunately, they now have to be
accessed as Qd.qd.xxxx
This commit is contained in:
parent
05a6d8f4c7
commit
bdd0747193
|
@ -329,6 +329,81 @@ PyTypeObject BitMap_Type = {
|
|||
/* --------------------- End object type BitMap --------------------- */
|
||||
|
||||
|
||||
/* ------------------ Object type QDGlobalsAccess ------------------- */
|
||||
|
||||
staticforward PyTypeObject QDGlobalsAccess_Type;
|
||||
|
||||
#define QDGA_Check(x) ((x)->ob_type == &QDGlobalsAccess_Type)
|
||||
|
||||
typedef struct QDGlobalsAccessObject {
|
||||
PyObject_HEAD
|
||||
} QDGlobalsAccessObject;
|
||||
|
||||
static PyObject *QDGA_New()
|
||||
{
|
||||
QDGlobalsAccessObject *it;
|
||||
it = PyObject_NEW(QDGlobalsAccessObject, &QDGlobalsAccess_Type);
|
||||
if (it == NULL) return NULL;
|
||||
return (PyObject *)it;
|
||||
}
|
||||
|
||||
static void QDGA_dealloc(self)
|
||||
QDGlobalsAccessObject *self;
|
||||
{
|
||||
PyMem_DEL(self);
|
||||
}
|
||||
|
||||
static PyMethodDef QDGA_methods[] = {
|
||||
{NULL, NULL, 0}
|
||||
};
|
||||
|
||||
static PyMethodChain QDGA_chain = { QDGA_methods, NULL };
|
||||
|
||||
static PyObject *QDGA_getattr(self, name)
|
||||
QDGlobalsAccessObject *self;
|
||||
char *name;
|
||||
{
|
||||
|
||||
if ( strcmp(name, "arrow") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.arrow, sizeof(qd.arrow));
|
||||
if ( strcmp(name, "black") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.black, sizeof(qd.black));
|
||||
if ( strcmp(name, "white") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.white, sizeof(qd.white));
|
||||
if ( strcmp(name, "gray") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.gray, sizeof(qd.gray));
|
||||
if ( strcmp(name, "ltGray") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.ltGray, sizeof(qd.ltGray));
|
||||
if ( strcmp(name, "dkGray") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.dkGray, sizeof(qd.dkGray));
|
||||
if ( strcmp(name, "screenBits") == 0 )
|
||||
return BMObj_New(&qd.screenBits);
|
||||
if ( strcmp(name, "thePort") == 0 )
|
||||
return GrafObj_New(qd.thePort);
|
||||
if ( strcmp(name, "randSeed") == 0 )
|
||||
return Py_BuildValue("l", &qd.randSeed);
|
||||
|
||||
return Py_FindMethodInChain(&QDGA_chain, (PyObject *)self, name);
|
||||
}
|
||||
|
||||
#define QDGA_setattr NULL
|
||||
|
||||
staticforward PyTypeObject QDGlobalsAccess_Type = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"QDGlobalsAccess", /*tp_name*/
|
||||
sizeof(QDGlobalsAccessObject), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor) QDGA_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc) QDGA_getattr, /*tp_getattr*/
|
||||
(setattrfunc) QDGA_setattr, /*tp_setattr*/
|
||||
};
|
||||
|
||||
/* ---------------- End object type QDGlobalsAccess ----------------- */
|
||||
|
||||
|
||||
static PyObject *Qd_SetPort(_self, _args)
|
||||
PyObject *_self;
|
||||
PyObject *_args;
|
||||
|
@ -3856,25 +3931,9 @@ void initQd()
|
|||
{
|
||||
PyObject *o;
|
||||
|
||||
o = PyString_FromStringAndSize((char *)&qd.arrow, sizeof(qd.arrow));
|
||||
if (o == NULL || PyDict_SetItemString(d, "arrow", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.arrow");
|
||||
o = PyString_FromStringAndSize((char *)&qd.black, sizeof(qd.black));
|
||||
if (o == NULL || PyDict_SetItemString(d, "black", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.black");
|
||||
o = PyString_FromStringAndSize((char *)&qd.white, sizeof(qd.white));
|
||||
if (o == NULL || PyDict_SetItemString(d, "white", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.white");
|
||||
o = PyString_FromStringAndSize((char *)&qd.gray, sizeof(qd.gray));
|
||||
if (o == NULL || PyDict_SetItemString(d, "gray", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.gray");
|
||||
o = PyString_FromStringAndSize((char *)&qd.ltGray, sizeof(qd.ltGray));
|
||||
if (o == NULL || PyDict_SetItemString(d, "ltGray", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.ltGray");
|
||||
o = PyString_FromStringAndSize((char *)&qd.dkGray, sizeof(qd.dkGray));
|
||||
if (o == NULL || PyDict_SetItemString(d, "dkGray", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.dkGray");
|
||||
/* thePort, screenBits and randSeed still missing... */
|
||||
o = QDGA_New();
|
||||
if (o == NULL || PyDict_SetItemString(d, "qd", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.qd");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -102,25 +102,9 @@ variablestuff = """
|
|||
{
|
||||
PyObject *o;
|
||||
|
||||
o = PyString_FromStringAndSize((char *)&qd.arrow, sizeof(qd.arrow));
|
||||
if (o == NULL || PyDict_SetItemString(d, "arrow", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.arrow");
|
||||
o = PyString_FromStringAndSize((char *)&qd.black, sizeof(qd.black));
|
||||
if (o == NULL || PyDict_SetItemString(d, "black", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.black");
|
||||
o = PyString_FromStringAndSize((char *)&qd.white, sizeof(qd.white));
|
||||
if (o == NULL || PyDict_SetItemString(d, "white", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.white");
|
||||
o = PyString_FromStringAndSize((char *)&qd.gray, sizeof(qd.gray));
|
||||
if (o == NULL || PyDict_SetItemString(d, "gray", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.gray");
|
||||
o = PyString_FromStringAndSize((char *)&qd.ltGray, sizeof(qd.ltGray));
|
||||
if (o == NULL || PyDict_SetItemString(d, "ltGray", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.ltGray");
|
||||
o = PyString_FromStringAndSize((char *)&qd.dkGray, sizeof(qd.dkGray));
|
||||
if (o == NULL || PyDict_SetItemString(d, "dkGray", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.dkGray");
|
||||
/* thePort, screenBits and randSeed still missing... */
|
||||
o = QDGA_New();
|
||||
if (o == NULL || PyDict_SetItemString(d, "qd", o) != 0)
|
||||
Py_FatalError("can't initialize Qd.qd");
|
||||
}
|
||||
"""
|
||||
|
||||
|
@ -252,6 +236,46 @@ class MyBMObjectDefinition(GlobalObjectDefinition):
|
|||
return PyString_FromStringAndSize((char *)self->ob_itself, sizeof(PixMap));
|
||||
""")
|
||||
|
||||
# This object is instanciated once, and will access qd globals.
|
||||
class QDGlobalsAccessObjectDefinition(ObjectDefinition):
|
||||
def outputStructMembers(self):
|
||||
pass
|
||||
def outputNew(self):
|
||||
Output()
|
||||
Output("%sPyObject *%s_New()", self.static, self.prefix)
|
||||
OutLbrace()
|
||||
Output("%s *it;", self.objecttype)
|
||||
Output("it = PyObject_NEW(%s, &%s);", self.objecttype, self.typename)
|
||||
Output("if (it == NULL) return NULL;")
|
||||
Output("return (PyObject *)it;")
|
||||
OutRbrace()
|
||||
def outputConvert(self):
|
||||
pass
|
||||
def outputCleanupStructMembers(self):
|
||||
pass
|
||||
|
||||
def outputGetattrHook(self):
|
||||
Output("""
|
||||
if ( strcmp(name, "arrow") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.arrow, sizeof(qd.arrow));
|
||||
if ( strcmp(name, "black") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.black, sizeof(qd.black));
|
||||
if ( strcmp(name, "white") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.white, sizeof(qd.white));
|
||||
if ( strcmp(name, "gray") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.gray, sizeof(qd.gray));
|
||||
if ( strcmp(name, "ltGray") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.ltGray, sizeof(qd.ltGray));
|
||||
if ( strcmp(name, "dkGray") == 0 )
|
||||
return PyString_FromStringAndSize((char *)&qd.dkGray, sizeof(qd.dkGray));
|
||||
if ( strcmp(name, "screenBits") == 0 )
|
||||
return BMObj_New(&qd.screenBits);
|
||||
if ( strcmp(name, "thePort") == 0 )
|
||||
return GrafObj_New(qd.thePort);
|
||||
if ( strcmp(name, "randSeed") == 0 )
|
||||
return Py_BuildValue("l", &qd.randSeed);
|
||||
""")
|
||||
|
||||
# Create the generator groups and link them
|
||||
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff, variablestuff)
|
||||
##r_object = Region_ObjectDefinition('Region', 'QdRgn', 'RgnHandle')
|
||||
|
@ -262,6 +286,8 @@ gr_object = MyGRObjectDefinition("GrafPort", "GrafObj", "GrafPtr")
|
|||
module.addobject(gr_object)
|
||||
bm_object = MyBMObjectDefinition("BitMap", "BMObj", "BitMapPtr")
|
||||
module.addobject(bm_object)
|
||||
qd_object = QDGlobalsAccessObjectDefinition("QDGlobalsAccess", "QDGA", "XXXX")
|
||||
module.addobject(qd_object)
|
||||
|
||||
|
||||
# Create the generator classes used to populate the lists
|
||||
|
|
Loading…
Reference in New Issue