diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2002-11-29 23:40:48 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2002-11-29 23:40:48 (GMT) |
commit | dbd5701d736a151d29fee4658228e16876626f47 (patch) | |
tree | 164a5bf1d9a00788bd229820df9bfa81d75933eb /Mac/Modules/list | |
parent | 818855939ac016492cb59d1fc2fea94cc0764855 (diff) | |
download | cpython-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/list')
-rw-r--r-- | Mac/Modules/list/_Listmodule.c | 414 | ||||
-rw-r--r-- | Mac/Modules/list/listscan.py | 2 | ||||
-rw-r--r-- | Mac/Modules/list/listsupport.py | 58 |
3 files changed, 224 insertions, 250 deletions
diff --git a/Mac/Modules/list/_Listmodule.c b/Mac/Modules/list/_Listmodule.c index 99805b6..559f543 100644 --- a/Mac/Modules/list/_Listmodule.c +++ b/Mac/Modules/list/_Listmodule.c @@ -542,6 +542,138 @@ static PyObject *ListObj_LGetCellDataLocation(ListObject *_self, PyObject *_args return _res; } +static PyObject *ListObj_GetListPort(ListObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + CGrafPtr _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetListPort(_self->ob_itself); + _res = Py_BuildValue("O&", + GrafObj_New, _rv); + return _res; +} + +static PyObject *ListObj_GetListVerticalScrollBar(ListObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + ControlHandle _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetListVerticalScrollBar(_self->ob_itself); + _res = Py_BuildValue("O&", + CtlObj_New, _rv); + return _res; +} + +static PyObject *ListObj_GetListHorizontalScrollBar(ListObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + ControlHandle _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetListHorizontalScrollBar(_self->ob_itself); + _res = Py_BuildValue("O&", + CtlObj_New, _rv); + return _res; +} + +static PyObject *ListObj_GetListActive(ListObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + Boolean _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetListActive(_self->ob_itself); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *ListObj_GetListClickTime(ListObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + SInt32 _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetListClickTime(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *ListObj_GetListRefCon(ListObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + SInt32 _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetListRefCon(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *ListObj_GetListDefinition(ListObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + Handle _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetListDefinition(_self->ob_itself); + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *ListObj_GetListUserHandle(ListObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + Handle _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetListUserHandle(_self->ob_itself); + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *ListObj_GetListDataHandle(ListObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + DataHandle _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetListDataHandle(_self->ob_itself); + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *ListObj_GetListFlags(ListObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OptionBits _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetListFlags(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *ListObj_GetListSelectionFlags(ListObject *_self, PyObject *_args) +{ + PyObject *_res = NULL; + OptionBits _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetListSelectionFlags(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + static PyObject *ListObj_as_Resource(ListObject *_self, PyObject *_args) { PyObject *_res = NULL; @@ -601,48 +733,73 @@ static PyMethodDef ListObj_methods[] = { PyDoc_STR("(Point theCell) -> None")}, {"LGetCellDataLocation", (PyCFunction)ListObj_LGetCellDataLocation, 1, PyDoc_STR("(Point theCell) -> (short offset, short len)")}, + {"GetListPort", (PyCFunction)ListObj_GetListPort, 1, + PyDoc_STR("() -> (CGrafPtr _rv)")}, + {"GetListVerticalScrollBar", (PyCFunction)ListObj_GetListVerticalScrollBar, 1, + PyDoc_STR("() -> (ControlHandle _rv)")}, + {"GetListHorizontalScrollBar", (PyCFunction)ListObj_GetListHorizontalScrollBar, 1, + PyDoc_STR("() -> (ControlHandle _rv)")}, + {"GetListActive", (PyCFunction)ListObj_GetListActive, 1, + PyDoc_STR("() -> (Boolean _rv)")}, + {"GetListClickTime", (PyCFunction)ListObj_GetListClickTime, 1, + PyDoc_STR("() -> (SInt32 _rv)")}, + {"GetListRefCon", (PyCFunction)ListObj_GetListRefCon, 1, + PyDoc_STR("() -> (SInt32 _rv)")}, + {"GetListDefinition", (PyCFunction)ListObj_GetListDefinition, 1, + PyDoc_STR("() -> (Handle _rv)")}, + {"GetListUserHandle", (PyCFunction)ListObj_GetListUserHandle, 1, + PyDoc_STR("() -> (Handle _rv)")}, + {"GetListDataHandle", (PyCFunction)ListObj_GetListDataHandle, 1, + PyDoc_STR("() -> (DataHandle _rv)")}, + {"GetListFlags", (PyCFunction)ListObj_GetListFlags, 1, + PyDoc_STR("() -> (OptionBits _rv)")}, + {"GetListSelectionFlags", (PyCFunction)ListObj_GetListSelectionFlags, 1, + PyDoc_STR("() -> (OptionBits _rv)")}, {"as_Resource", (PyCFunction)ListObj_as_Resource, 1, PyDoc_STR("() -> (Handle _rv)")}, {NULL, NULL, 0} }; -PyMethodChain ListObj_chain = { ListObj_methods, NULL }; +static PyObject *ListObj_get_listFlags(ListObject *self, void *closure) +{ + return Py_BuildValue("l", (long)GetListFlags(self->ob_itself) & 0xff); +} -static PyObject *ListObj_getattr(ListObject *self, char *name) +static int ListObj_set_listFlags(ListObject *self, PyObject *v, void *closure) { - { - if ( strcmp(name, "listFlags") == 0 ) - return Py_BuildValue("l", (long)GetListFlags(self->ob_itself) & 0xff); - if ( strcmp(name, "selFlags") == 0 ) - return Py_BuildValue("l", (long)GetListSelectionFlags(self->ob_itself) & 0xff); - if ( strcmp(name, "cellSize") == 0 ) - return Py_BuildValue("O&", PyMac_BuildPoint, (*self->ob_itself)->cellSize); - } - return Py_FindMethodInChain(&ListObj_chain, (PyObject *)self, name); + if (!PyArg_Parse(v, "B", &(*self->ob_itself)->listFlags)) return -1; + return 0; } -static int -ListObj_setattr(ListObject *self, char *name, PyObject *value) +static PyObject *ListObj_get_selFlags(ListObject *self, void *closure) { - long intval; - int err = 0; - - if ( value == NULL ) { - PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute"); - return -1; - } - if (strcmp(name, "listFlags") == 0 ) - err = PyArg_Parse(value, "B", &(*self->ob_itself)->listFlags); - else if (strcmp(name, "selFlags") == 0 ) - err = PyArg_Parse(value, "B", &(*self->ob_itself)->selFlags); - else if (strcmp(name, "cellSize") == 0 ) - err = PyArg_Parse(value, "O&", PyMac_GetPoint, &(*self->ob_itself)->cellSize); - else - PyErr_SetString(PyExc_AttributeError, "No such attribute"); - if (err) return 0; - else return -1; + return Py_BuildValue("l", (long)GetListSelectionFlags(self->ob_itself) & 0xff); +} + +static int ListObj_set_selFlags(ListObject *self, PyObject *v, void *closure) +{ + if (!PyArg_Parse(v, "B", &(*self->ob_itself)->selFlags)) return -1; + return 0; +} + +static PyObject *ListObj_get_cellSize(ListObject *self, void *closure) +{ + return Py_BuildValue("O&", PyMac_BuildPoint, (*self->ob_itself)->cellSize); +} + +static int ListObj_set_cellSize(ListObject *self, PyObject *v, void *closure) +{ + if (!PyArg_Parse(v, "O&", PyMac_GetPoint, &(*self->ob_itself)->cellSize)) return -1; + return 0; } +static PyGetSetDef ListObj_getsetlist[] = { + {"listFlags", (getter)ListObj_get_listFlags, (setter)ListObj_set_listFlags, NULL}, + {"selFlags", (getter)ListObj_get_selFlags, (setter)ListObj_set_selFlags, NULL}, + {"cellSize", (getter)ListObj_get_cellSize, (setter)ListObj_set_cellSize, NULL}, + {NULL, NULL, NULL, NULL}, +}; + #define ListObj_compare NULL @@ -659,14 +816,31 @@ PyTypeObject List_Type = { /* methods */ (destructor) ListObj_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ - (getattrfunc) ListObj_getattr, /*tp_getattr*/ - (setattrfunc) ListObj_setattr, /*tp_setattr*/ + (getattrfunc)0, /*tp_getattr*/ + (setattrfunc)0, /*tp_setattr*/ (cmpfunc) ListObj_compare, /*tp_compare*/ (reprfunc) ListObj_repr, /*tp_repr*/ (PyNumberMethods *)0, /* tp_as_number */ (PySequenceMethods *)0, /* tp_as_sequence */ (PyMappingMethods *)0, /* tp_as_mapping */ (hashfunc) ListObj_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*/ + ListObj_methods, /* tp_methods */ + 0, /*outputHook_tp_members*/ + ListObj_getsetlist, /*tp_getset*/ + 0, /*outputHook_tp_base*/ }; /* ---------------------- End object type List ---------------------- */ @@ -783,160 +957,6 @@ static PyObject *List_LNew(PyObject *_self, PyObject *_args) return _res; } -static PyObject *List_GetListPort(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - CGrafPtr _rv; - ListHandle list; - if (!PyArg_ParseTuple(_args, "O&", - ListObj_Convert, &list)) - return NULL; - _rv = GetListPort(list); - _res = Py_BuildValue("O&", - GrafObj_New, _rv); - return _res; -} - -static PyObject *List_GetListVerticalScrollBar(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - ControlHandle _rv; - ListHandle list; - if (!PyArg_ParseTuple(_args, "O&", - ListObj_Convert, &list)) - return NULL; - _rv = GetListVerticalScrollBar(list); - _res = Py_BuildValue("O&", - CtlObj_New, _rv); - return _res; -} - -static PyObject *List_GetListHorizontalScrollBar(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - ControlHandle _rv; - ListHandle list; - if (!PyArg_ParseTuple(_args, "O&", - ListObj_Convert, &list)) - return NULL; - _rv = GetListHorizontalScrollBar(list); - _res = Py_BuildValue("O&", - CtlObj_New, _rv); - return _res; -} - -static PyObject *List_GetListActive(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Boolean _rv; - ListHandle list; - if (!PyArg_ParseTuple(_args, "O&", - ListObj_Convert, &list)) - return NULL; - _rv = GetListActive(list); - _res = Py_BuildValue("b", - _rv); - return _res; -} - -static PyObject *List_GetListClickTime(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - ListHandle list; - if (!PyArg_ParseTuple(_args, "O&", - ListObj_Convert, &list)) - return NULL; - _rv = GetListClickTime(list); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *List_GetListRefCon(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - ListHandle list; - if (!PyArg_ParseTuple(_args, "O&", - ListObj_Convert, &list)) - return NULL; - _rv = GetListRefCon(list); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *List_GetListDefinition(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Handle _rv; - ListHandle list; - if (!PyArg_ParseTuple(_args, "O&", - ListObj_Convert, &list)) - return NULL; - _rv = GetListDefinition(list); - _res = Py_BuildValue("O&", - ResObj_New, _rv); - return _res; -} - -static PyObject *List_GetListUserHandle(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Handle _rv; - ListHandle list; - if (!PyArg_ParseTuple(_args, "O&", - ListObj_Convert, &list)) - return NULL; - _rv = GetListUserHandle(list); - _res = Py_BuildValue("O&", - ResObj_New, _rv); - return _res; -} - -static PyObject *List_GetListDataHandle(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - DataHandle _rv; - ListHandle list; - if (!PyArg_ParseTuple(_args, "O&", - ListObj_Convert, &list)) - return NULL; - _rv = GetListDataHandle(list); - _res = Py_BuildValue("O&", - ResObj_New, _rv); - return _res; -} - -static PyObject *List_GetListFlags(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OptionBits _rv; - ListHandle list; - if (!PyArg_ParseTuple(_args, "O&", - ListObj_Convert, &list)) - return NULL; - _rv = GetListFlags(list); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *List_GetListSelectionFlags(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OptionBits _rv; - ListHandle list; - if (!PyArg_ParseTuple(_args, "O&", - ListObj_Convert, &list)) - return NULL; - _rv = GetListSelectionFlags(list); - _res = Py_BuildValue("l", - _rv); - return _res; -} - static PyObject *List_SetListViewBounds(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; @@ -1085,28 +1105,6 @@ static PyMethodDef List_methods[] = { PyDoc_STR("(Rect rView, Rect dataBounds, Point cellSize, ListDefSpec theSpec, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle outList)")}, {"LNew", (PyCFunction)List_LNew, 1, PyDoc_STR("(Rect rView, Rect dataBounds, Point cSize, short theProc, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle _rv)")}, - {"GetListPort", (PyCFunction)List_GetListPort, 1, - PyDoc_STR("(ListHandle list) -> (CGrafPtr _rv)")}, - {"GetListVerticalScrollBar", (PyCFunction)List_GetListVerticalScrollBar, 1, - PyDoc_STR("(ListHandle list) -> (ControlHandle _rv)")}, - {"GetListHorizontalScrollBar", (PyCFunction)List_GetListHorizontalScrollBar, 1, - PyDoc_STR("(ListHandle list) -> (ControlHandle _rv)")}, - {"GetListActive", (PyCFunction)List_GetListActive, 1, - PyDoc_STR("(ListHandle list) -> (Boolean _rv)")}, - {"GetListClickTime", (PyCFunction)List_GetListClickTime, 1, - PyDoc_STR("(ListHandle list) -> (SInt32 _rv)")}, - {"GetListRefCon", (PyCFunction)List_GetListRefCon, 1, - PyDoc_STR("(ListHandle list) -> (SInt32 _rv)")}, - {"GetListDefinition", (PyCFunction)List_GetListDefinition, 1, - PyDoc_STR("(ListHandle list) -> (Handle _rv)")}, - {"GetListUserHandle", (PyCFunction)List_GetListUserHandle, 1, - PyDoc_STR("(ListHandle list) -> (Handle _rv)")}, - {"GetListDataHandle", (PyCFunction)List_GetListDataHandle, 1, - PyDoc_STR("(ListHandle list) -> (DataHandle _rv)")}, - {"GetListFlags", (PyCFunction)List_GetListFlags, 1, - PyDoc_STR("(ListHandle list) -> (OptionBits _rv)")}, - {"GetListSelectionFlags", (PyCFunction)List_GetListSelectionFlags, 1, - PyDoc_STR("(ListHandle list) -> (OptionBits _rv)")}, {"SetListViewBounds", (PyCFunction)List_SetListViewBounds, 1, PyDoc_STR("(ListHandle list, Rect view) -> None")}, {"SetListPort", (PyCFunction)List_SetListPort, 1, diff --git a/Mac/Modules/list/listscan.py b/Mac/Modules/list/listscan.py index d835a68..66cb2ad 100644 --- a/Mac/Modules/list/listscan.py +++ b/Mac/Modules/list/listscan.py @@ -31,7 +31,7 @@ class MyScanner(Scanner): if arglist: t, n, m = arglist[-1] # This is non-functional today - if t == OBJECT and m == "InMode": + if t in ('ListHandle', 'ListRef') and m == "InMode": classname = "Method" listname = "methods" return classname, listname diff --git a/Mac/Modules/list/listsupport.py b/Mac/Modules/list/listsupport.py index 23a2a84..87ed702 100644 --- a/Mac/Modules/list/listsupport.py +++ b/Mac/Modules/list/listsupport.py @@ -137,41 +137,23 @@ class ListMethodGenerator(MethodGenerator): FunctionGenerator.parseArgumentList(self, args) self.argumentList.append(self.itself) -getattrHookCode = """{ - if ( strcmp(name, "listFlags") == 0 ) - return Py_BuildValue("l", (long)GetListFlags(self->ob_itself) & 0xff); - if ( strcmp(name, "selFlags") == 0 ) - return Py_BuildValue("l", (long)GetListSelectionFlags(self->ob_itself) & 0xff); - if ( strcmp(name, "cellSize") == 0 ) - return Py_BuildValue("O&", PyMac_BuildPoint, (*self->ob_itself)->cellSize); -}""" - -setattrCode = """ -static int -ListObj_setattr(ListObject *self, char *name, PyObject *value) -{ - long intval; - int err = 0; - - if ( value == NULL ) { - PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute"); - return -1; - } - if (strcmp(name, "listFlags") == 0 ) - err = PyArg_Parse(value, "B", &(*self->ob_itself)->listFlags); - else if (strcmp(name, "selFlags") == 0 ) - err = PyArg_Parse(value, "B", &(*self->ob_itself)->selFlags); - else if (strcmp(name, "cellSize") == 0 ) - err = PyArg_Parse(value, "O&", PyMac_GetPoint, &(*self->ob_itself)->cellSize); - else - PyErr_SetString(PyExc_AttributeError, "No such attribute"); - if (err) return 0; - else return -1; -} -""" - - -class MyObjectDefinition(GlobalObjectDefinition): +class MyObjectDefinition(PEP252Mixin, GlobalObjectDefinition): + getsetlist = [( + 'listFlags', + 'return Py_BuildValue("l", (long)GetListFlags(self->ob_itself) & 0xff);', + 'if (!PyArg_Parse(v, "B", &(*self->ob_itself)->listFlags)) return -1;', + None, + ), ( + 'selFlags', + 'return Py_BuildValue("l", (long)GetListSelectionFlags(self->ob_itself) & 0xff);', + 'if (!PyArg_Parse(v, "B", &(*self->ob_itself)->selFlags)) return -1;', + None, + ), ( + 'cellSize', + 'return Py_BuildValue("O&", PyMac_BuildPoint, (*self->ob_itself)->cellSize);', + 'if (!PyArg_Parse(v, "O&", PyMac_GetPoint, &(*self->ob_itself)->cellSize)) return -1;', + None + )] def outputStructMembers(self): ObjectDefinition.outputStructMembers(self) @@ -201,12 +183,6 @@ class MyObjectDefinition(GlobalObjectDefinition): Output("SetListRefCon(self->ob_itself, (long)0);") Output("if (self->ob_must_be_disposed && %s) LDispose(%s);", itselfname, itselfname) - def outputGetattrHook(self): - Output(getattrHookCode) - - def outputSetattr(self): - Output(setattrCode) - # From here on it's basically all boiler plate... finalstuff = finalstuff + """ |