diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1996-01-29 15:44:03 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1996-01-29 15:44:03 (GMT) |
commit | bdd0747193e9e08d94e146f65254a885bdb6178b (patch) | |
tree | 09c2bdf79a933af1a016e394b3e3470f61e0c0ee /Mac/Modules/qd | |
parent | 05a6d8f4c78db6dab8628f01fcf53c7855caf1d5 (diff) | |
download | cpython-bdd0747193e9e08d94e146f65254a885bdb6178b.zip cpython-bdd0747193e9e08d94e146f65254a885bdb6178b.tar.gz cpython-bdd0747193e9e08d94e146f65254a885bdb6178b.tar.bz2 |
Fixed access to Quickdraw globals. Unfortunately, they now have to be
accessed as Qd.qd.xxxx
Diffstat (limited to 'Mac/Modules/qd')
-rw-r--r-- | Mac/Modules/qd/Qdmodule.c | 99 | ||||
-rw-r--r-- | Mac/Modules/qd/qdsupport.py | 66 |
2 files changed, 125 insertions, 40 deletions
diff --git a/Mac/Modules/qd/Qdmodule.c b/Mac/Modules/qd/Qdmodule.c index 54176f3..88cddaf 100644 --- a/Mac/Modules/qd/Qdmodule.c +++ b/Mac/Modules/qd/Qdmodule.c @@ -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; @@ -3855,26 +3930,10 @@ 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"); } diff --git a/Mac/Modules/qd/qdsupport.py b/Mac/Modules/qd/qdsupport.py index 39d9895..203f8c0 100644 --- a/Mac/Modules/qd/qdsupport.py +++ b/Mac/Modules/qd/qdsupport.py @@ -101,26 +101,10 @@ PyObject *QdFI_New(itself) 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"); } """ @@ -251,6 +235,46 @@ class MyBMObjectDefinition(GlobalObjectDefinition): if ( strcmp(name, "pixmap_data") == 0 ) 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) @@ -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 |