I am looking for help from a developer to do this : Baiju M
static PyObject * pygtk_tree_model_row_slice(PyGtkTreeModelRow *self, gint low, gint high) { gint n_columns; GValue value = { 0, }; PyObject *ret; gint i; printf("Before %d %d\n", low, high); n_columns = gtk_tree_model_get_n_columns(self->model); if (low < 0) low = 0; else if (low > n_columns) low = n_columns; if (high < 0) high = 0; if (high < low) high = low; else if (high > n_columns) high = n_columns; ret = PyList_New(0); printf("After %d %d %d\n", low, high, n_columns); for (i = low; i < high; i++) { printf("%d\n", i); PyObject *o; gtk_tree_model_get_value(self->model, &self->iter, i, &value); o = pyg_value_as_pyobject(&value, TRUE); PyList_Append(ret, o); g_value_unset(&value); /*FIXME: Is Py_DECREF required? Py_DECREF(o); */ } return ret; }
But when 'low' and 'high' is giving as negative, its getting as 1 (one)
Here is a test :
>>> import pygtk >>> pygtk.require('2.0') >>> import gtk >>> a = gtk.ListStore(int, int, int) >>> a.append((0,1,2)) <GtkTreeIter at 0x825a560> >>> a[0][-2:3] Before 1 3 After 1 3 3 1 2 [1, 2] >>>
Here is the diff against 2.6.2 :
--- gtk-types.c.orig 2005-07-24 17:49:30.000000000 +0530 +++ gtk-types.c 2005-07-24 18:38:22.000000000 +0530 @@ -888,6 +888,42 @@ return ret; } +static PyObject * +pygtk_tree_model_row_slice(PyGtkTreeModelRow *self, gint low, gint high) +{ + gint n_columns; + GValue value = { 0, }; + PyObject *ret; + gint i; + + printf("Before %d %d\n", low, high); + n_columns = gtk_tree_model_get_n_columns(self->model); + if (low < 0) + low = 0; + else if (low > n_columns) + low = n_columns; + if (high < 0) + high = 0; + if (high < low) + high = low; + else if (high > n_columns) + high = n_columns; + ret = PyList_New(0); + printf("After %d %d %d\n", low, high, n_columns); + for (i = low; i < high; i++) { + printf("%d\n", i); + PyObject *o; + gtk_tree_model_get_value(self->model, &self->iter, i, &value); + o = pyg_value_as_pyobject(&value, TRUE); + PyList_Append(ret, o); + g_value_unset(&value); + /*FIXME: Is Py_DECREF required? + Py_DECREF(o); + */ + } + return ret; +} + static int pygtk_tree_model_row_setitem(PyGtkTreeModelRow *self, gint column, PyObject *pyvalue) @@ -925,13 +961,13 @@ } static PySequenceMethods pygtk_tree_model_row_seqmethods = { - (inquiry)pygtk_tree_model_row_length, - (binaryfunc)0, - (intargfunc)0, - (intargfunc)pygtk_tree_model_row_getitem, - (intintargfunc)0, - (intobjargproc)pygtk_tree_model_row_setitem, - (intintobjargproc)0 + (inquiry)pygtk_tree_model_row_length,/*sq_length*/ + (binaryfunc)0,/*sq_concat*/ + (intargfunc)0,/*sq_repeat*/ + (intargfunc)pygtk_tree_model_row_getitem,/*sq_item*/ + (intintargfunc)pygtk_tree_model_row_slice,/*sq_slice*/ + (intobjargproc)pygtk_tree_model_row_setitem,/*sq_ass_item*/ + (intintobjargproc)0/*sq_ass_slice*/ }; static PyObject *