]> granicus.if.org Git - python/commitdiff
added acces to the cellSize field, rewrote setattr code
authorJust van Rossum <just@letterror.com>
Mon, 5 Nov 2001 11:12:12 +0000 (11:12 +0000)
committerJust van Rossum <just@letterror.com>
Mon, 5 Nov 2001 11:12:12 +0000 (11:12 +0000)
Mac/Modules/list/_Listmodule.c
Mac/Modules/list/listsupport.py

index d2df406a4d744fca838eb8b9d38ad9ea22b6db1f..d0b19bd65750b3fdb5aafa657ef2656a23547bbc 100644 (file)
@@ -607,11 +607,12 @@ PyMethodChain ListObj_chain = { ListObj_methods, NULL };
 static PyObject *ListObj_getattr(ListObject *self, char *name)
 {
        {
-               /* XXXX Should we HLock() here?? */
                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);
 }
@@ -620,19 +621,22 @@ static int
 ListObj_setattr(ListObject *self, char *name, PyObject *value)
 {
        long intval;
-               
-       if ( value == NULL || !PyInt_Check(value) )
+       int err = 0;
+       
+       if ( value == NULL ) {
+               PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
                return -1;
-       intval = PyInt_AsLong(value);
-       if (strcmp(name, "listFlags") == 0 ) {
-               SetListFlags(self->ob_itself, intval);
-               return 0;
-       }
-       if (strcmp(name, "selFlags") == 0 ) {
-               SetListSelectionFlags(self->ob_itself, intval);
-               return 0;
        }
-       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;
 }
 
 
index 78ab49405b35d173cf13b97fcf8d4c8a4189741b..1d0223fc3fe6d69d64ceb7eb93a1aec83d0d92cc 100644 (file)
@@ -137,11 +137,12 @@ class ListMethodGenerator(MethodGenerator):
                self.argumentList.append(self.itself)
 
 getattrHookCode = """{
-       /* XXXX Should we HLock() here?? */
        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 = """
@@ -149,19 +150,22 @@ static int
 ListObj_setattr(ListObject *self, char *name, PyObject *value)
 {
        long intval;
-               
-       if ( value == NULL || !PyInt_Check(value) )
+       int err = 0;
+       
+       if ( value == NULL ) {
+               PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
                return -1;
-       intval = PyInt_AsLong(value);
-       if (strcmp(name, "listFlags") == 0 ) {
-               SetListFlags(self->ob_itself, intval);
-               return 0;
-       }
-       if (strcmp(name, "selFlags") == 0 ) {
-               SetListSelectionFlags(self->ob_itself, intval);
-               return 0;
        }
-       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;
 }
 """