summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/te
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2002-11-29 23:40:48 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2002-11-29 23:40:48 (GMT)
commitdbd5701d736a151d29fee4658228e16876626f47 (patch)
tree164a5bf1d9a00788bd229820df9bfa81d75933eb /Mac/Modules/te
parent818855939ac016492cb59d1fc2fea94cc0764855 (diff)
downloadcpython-dbd5701d736a151d29fee4658228e16876626f47.zip
cpython-dbd5701d736a151d29fee4658228e16876626f47.tar.gz
cpython-dbd5701d736a151d29fee4658228e16876626f47.tar.bz2
Converted the Carbon modules to use PEP252-style objects, with
descriptors in stead of manual getattr hooks to get at attributes of the objects. For Qd I have in stead gotten rid of most of the attribute access in favor of the carbon-style accessor methods (with the exception of visRgn, to be done later), and of the Carbon.Qd.qd global object, for which accessor functions are also available. For List I have fixed the fact that various methods were incorrectly generated as functions. CF is untouched: PEP252 doesn't allow "poor-mans-inheritance" with basechain, so it will have to wait for PEP253 support.
Diffstat (limited to 'Mac/Modules/te')
-rw-r--r--Mac/Modules/te/_TEmodule.c198
-rw-r--r--Mac/Modules/te/tesupport.py125
2 files changed, 235 insertions, 88 deletions
diff --git a/Mac/Modules/te/_TEmodule.c b/Mac/Modules/te/_TEmodule.c
index 1788620..a89826b 100644
--- a/Mac/Modules/te/_TEmodule.c
+++ b/Mac/Modules/te/_TEmodule.c
@@ -850,52 +850,137 @@ static PyMethodDef TEObj_methods[] = {
{NULL, NULL, 0}
};
-PyMethodChain TEObj_chain = { TEObj_methods, NULL };
-
-static PyObject *TEObj_getattr(TEObject *self, char *name)
-{
-
- if( strcmp(name, "destRect") == 0 )
- return Py_BuildValue("O&", PyMac_BuildRect,
- &(*self->ob_itself)->destRect);
- if( strcmp(name, "viewRect") == 0 )
- return Py_BuildValue("O&", PyMac_BuildRect,
- &(*self->ob_itself)->viewRect);
- if( strcmp(name, "selRect") == 0 )
- return Py_BuildValue("O&", PyMac_BuildRect,
- &(*self->ob_itself)->selRect);
- if( strcmp(name, "lineHeight") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->lineHeight);
- if( strcmp(name, "fontAscent") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->fontAscent);
- if( strcmp(name, "selPoint") == 0 )
- return Py_BuildValue("O&", PyMac_BuildPoint,
- (*self->ob_itself)->selPoint);
- if( strcmp(name, "selStart") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->selStart);
- if( strcmp(name, "selEnd") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->selEnd);
- if( strcmp(name, "active") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->active);
- if( strcmp(name, "just") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->just);
- if( strcmp(name, "teLength") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->teLength);
- if( strcmp(name, "txFont") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->txFont);
- if( strcmp(name, "txFace") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->txFace);
- if( strcmp(name, "txMode") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->txMode);
- if( strcmp(name, "txSize") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->txSize);
- if( strcmp(name, "nLines") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->nLines);
-
- return Py_FindMethodInChain(&TEObj_chain, (PyObject *)self, name);
-}
-
-#define TEObj_setattr NULL
+static PyObject *TEObj_get_destRect(TEObject *self, void *closure)
+{
+ return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->destRect);
+}
+
+#define TEObj_set_destRect NULL
+
+static PyObject *TEObj_get_viewRect(TEObject *self, void *closure)
+{
+ return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->viewRect);
+}
+
+#define TEObj_set_viewRect NULL
+
+static PyObject *TEObj_get_selRect(TEObject *self, void *closure)
+{
+ return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->selRect);
+}
+
+#define TEObj_set_selRect NULL
+
+static PyObject *TEObj_get_lineHeight(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->lineHeight);
+}
+
+#define TEObj_set_lineHeight NULL
+
+static PyObject *TEObj_get_fontAscent(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->fontAscent);
+}
+
+#define TEObj_set_fontAscent NULL
+
+static PyObject *TEObj_get_selPoint(TEObject *self, void *closure)
+{
+ return Py_BuildValue("O&", PyMac_BuildPoint, (*self->ob_itself)->selPoint);
+}
+
+#define TEObj_set_selPoint NULL
+
+static PyObject *TEObj_get_selStart(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->selStart);
+}
+
+#define TEObj_set_selStart NULL
+
+static PyObject *TEObj_get_selEnd(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->selEnd);
+}
+
+#define TEObj_set_selEnd NULL
+
+static PyObject *TEObj_get_active(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->active);
+}
+
+#define TEObj_set_active NULL
+
+static PyObject *TEObj_get_just(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->just);
+}
+
+#define TEObj_set_just NULL
+
+static PyObject *TEObj_get_teLength(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->teLength);
+}
+
+#define TEObj_set_teLength NULL
+
+static PyObject *TEObj_get_txFont(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->txFont);
+}
+
+#define TEObj_set_txFont NULL
+
+static PyObject *TEObj_get_txFace(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->txFace);
+}
+
+#define TEObj_set_txFace NULL
+
+static PyObject *TEObj_get_txMode(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->txMode);
+}
+
+#define TEObj_set_txMode NULL
+
+static PyObject *TEObj_get_txSize(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->txSize);
+}
+
+#define TEObj_set_txSize NULL
+
+static PyObject *TEObj_get_nLines(TEObject *self, void *closure)
+{
+ return Py_BuildValue("h", (*self->ob_itself)->nLines);
+}
+
+#define TEObj_set_nLines NULL
+
+static PyGetSetDef TEObj_getsetlist[] = {
+ {"destRect", (getter)TEObj_get_destRect, (setter)TEObj_set_destRect, "Destination rectangle"},
+ {"viewRect", (getter)TEObj_get_viewRect, (setter)TEObj_set_viewRect, "Viewing rectangle"},
+ {"selRect", (getter)TEObj_get_selRect, (setter)TEObj_set_selRect, "Selection rectangle"},
+ {"lineHeight", (getter)TEObj_get_lineHeight, (setter)TEObj_set_lineHeight, "Height of a line"},
+ {"fontAscent", (getter)TEObj_get_fontAscent, (setter)TEObj_set_fontAscent, "Ascent of a line"},
+ {"selPoint", (getter)TEObj_get_selPoint, (setter)TEObj_set_selPoint, "Selection Point"},
+ {"selStart", (getter)TEObj_get_selStart, (setter)TEObj_set_selStart, "Start of selection"},
+ {"selEnd", (getter)TEObj_get_selEnd, (setter)TEObj_set_selEnd, "End of selection"},
+ {"active", (getter)TEObj_get_active, (setter)TEObj_set_active, "TBD"},
+ {"just", (getter)TEObj_get_just, (setter)TEObj_set_just, "Justification"},
+ {"teLength", (getter)TEObj_get_teLength, (setter)TEObj_set_teLength, "TBD"},
+ {"txFont", (getter)TEObj_get_txFont, (setter)TEObj_set_txFont, "Current font"},
+ {"txFace", (getter)TEObj_get_txFace, (setter)TEObj_set_txFace, "Current font variant"},
+ {"txMode", (getter)TEObj_get_txMode, (setter)TEObj_set_txMode, "Current text-drawing mode"},
+ {"txSize", (getter)TEObj_get_txSize, (setter)TEObj_set_txSize, "Current font size"},
+ {"nLines", (getter)TEObj_get_nLines, (setter)TEObj_set_nLines, "TBD"},
+};
+
#define TEObj_compare NULL
@@ -912,14 +997,31 @@ PyTypeObject TE_Type = {
/* methods */
(destructor) TEObj_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- (getattrfunc) TEObj_getattr, /*tp_getattr*/
- (setattrfunc) TEObj_setattr, /*tp_setattr*/
+ (getattrfunc)0, /*tp_getattr*/
+ (setattrfunc)0, /*tp_setattr*/
(cmpfunc) TEObj_compare, /*tp_compare*/
(reprfunc) TEObj_repr, /*tp_repr*/
(PyNumberMethods *)0, /* tp_as_number */
(PySequenceMethods *)0, /* tp_as_sequence */
(PyMappingMethods *)0, /* tp_as_mapping */
(hashfunc) TEObj_hash, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ PyObject_GenericGetAttr, /*tp_getattro*/
+ PyObject_GenericSetAttr, /*tp_setattro */
+ 0, /*outputHook_tp_as_buffer*/
+ 0, /*outputHook_tp_flags*/
+ 0, /*outputHook_tp_doc*/
+ 0, /*outputHook_tp_traverse*/
+ 0, /*outputHook_tp_clear*/
+ 0, /*outputHook_tp_richcompare*/
+ 0, /*outputHook_tp_weaklistoffset*/
+ 0, /*outputHook_tp_iter*/
+ 0, /*outputHook_tp_iternext*/
+ TEObj_methods, /* tp_methods */
+ 0, /*outputHook_tp_members*/
+ TEObj_getsetlist, /*tp_getset*/
+ 0, /*outputHook_tp_base*/
};
/* ----------------------- End object type TE ----------------------- */
diff --git a/Mac/Modules/te/tesupport.py b/Mac/Modules/te/tesupport.py
index a77250c..f11e718 100644
--- a/Mac/Modules/te/tesupport.py
+++ b/Mac/Modules/te/tesupport.py
@@ -93,7 +93,91 @@ class TEMethodGenerator(OSErrWeakLinkMethodGenerator):
-class MyObjectDefinition(GlobalObjectDefinition):
+class MyObjectDefinition(PEP252Mixin, GlobalObjectDefinition):
+ # Attributes that can be set.
+ getsetlist = [
+ (
+ 'destRect',
+ 'return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->destRect);',
+ None,
+ 'Destination rectangle'
+ ), (
+ 'viewRect',
+ 'return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->viewRect);',
+ None,
+ 'Viewing rectangle'
+ ), (
+ 'selRect',
+ 'return Py_BuildValue("O&", PyMac_BuildRect, &(*self->ob_itself)->selRect);',
+ None,
+ 'Selection rectangle'
+ ), (
+ 'lineHeight',
+ 'return Py_BuildValue("h", (*self->ob_itself)->lineHeight);',
+ None,
+ 'Height of a line'
+ ), (
+ 'fontAscent',
+ 'return Py_BuildValue("h", (*self->ob_itself)->fontAscent);',
+ None,
+ 'Ascent of a line'
+ ), (
+ "selPoint",
+ 'return Py_BuildValue("O&", PyMac_BuildPoint, (*self->ob_itself)->selPoint);',
+ None,
+ 'Selection Point'
+ ), (
+ 'selStart',
+ 'return Py_BuildValue("h", (*self->ob_itself)->selStart);',
+ None,
+ 'Start of selection'
+ ), (
+ 'selEnd',
+ 'return Py_BuildValue("h", (*self->ob_itself)->selEnd);',
+ None,
+ 'End of selection'
+ ), (
+ 'active',
+ 'return Py_BuildValue("h", (*self->ob_itself)->active);',
+ None,
+ 'TBD'
+ ), (
+ 'just',
+ 'return Py_BuildValue("h", (*self->ob_itself)->just);',
+ None,
+ 'Justification'
+ ), (
+ 'teLength',
+ 'return Py_BuildValue("h", (*self->ob_itself)->teLength);',
+ None,
+ 'TBD'
+ ), (
+ 'txFont',
+ 'return Py_BuildValue("h", (*self->ob_itself)->txFont);',
+ None,
+ 'Current font'
+ ), (
+ 'txFace',
+ 'return Py_BuildValue("h", (*self->ob_itself)->txFace);',
+ None,
+ 'Current font variant'
+ ), (
+ 'txMode',
+ 'return Py_BuildValue("h", (*self->ob_itself)->txMode);',
+ None,
+ 'Current text-drawing mode'
+ ), (
+ 'txSize',
+ 'return Py_BuildValue("h", (*self->ob_itself)->txSize);',
+ None,
+ 'Current font size'
+ ), (
+ 'nLines',
+ 'return Py_BuildValue("h", (*self->ob_itself)->nLines);',
+ None,
+ 'TBD'
+ )]
+
def outputCheckNewArg(self):
Output("""if (itself == NULL) {
PyErr_SetString(TE_Error,"Cannot create null TE");
@@ -102,45 +186,6 @@ class MyObjectDefinition(GlobalObjectDefinition):
def outputFreeIt(self, itselfname):
Output("TEDispose(%s);", itselfname)
- def outputGetattrHook(self):
- Output("""
- if( strcmp(name, "destRect") == 0 )
- return Py_BuildValue("O&", PyMac_BuildRect,
- &(*self->ob_itself)->destRect);
- if( strcmp(name, "viewRect") == 0 )
- return Py_BuildValue("O&", PyMac_BuildRect,
- &(*self->ob_itself)->viewRect);
- if( strcmp(name, "selRect") == 0 )
- return Py_BuildValue("O&", PyMac_BuildRect,
- &(*self->ob_itself)->selRect);
- if( strcmp(name, "lineHeight") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->lineHeight);
- if( strcmp(name, "fontAscent") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->fontAscent);
- if( strcmp(name, "selPoint") == 0 )
- return Py_BuildValue("O&", PyMac_BuildPoint,
- (*self->ob_itself)->selPoint);
- if( strcmp(name, "selStart") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->selStart);
- if( strcmp(name, "selEnd") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->selEnd);
- if( strcmp(name, "active") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->active);
- if( strcmp(name, "just") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->just);
- if( strcmp(name, "teLength") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->teLength);
- if( strcmp(name, "txFont") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->txFont);
- if( strcmp(name, "txFace") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->txFace);
- if( strcmp(name, "txMode") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->txMode);
- if( strcmp(name, "txSize") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->txSize);
- if( strcmp(name, "nLines") == 0 )
- return Py_BuildValue("h", (*self->ob_itself)->nLines);
- """)
# From here on it's basically all boiler plate...