diff --git a/wxPython/src/grid.i b/wxPython/src/grid.i index ed7a4e4e8a..783197903f 100644 --- a/wxPython/src/grid.i +++ b/wxPython/src/grid.i @@ -1403,8 +1403,17 @@ public: return *self != other; } } - %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())" - %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())" + %pragma(python) addtoclass = " + def __str__(self): return str(self.asTuple()) + def __repr__(self): return str(self.asTuple()) + def __len__(self): return len(self.asTuple()) + def __getitem__(self, index): return self.asTuple()[index] + def __setitem__(self, index, val): + if index == 0: self.SetRow(val) + elif index == 1: self.SetCol(val) + else: raise IndexError + " + }; // Typemap to allow conversion of sequence objects to wxGridCellCoords... @@ -1440,6 +1449,32 @@ bool wxGridCellCoords_helper(PyObject* source, wxGridCellCoords** obj) { } %} + + +// Typemap to convert an array of cells coords to a list of tuples... +%typemap(python, out) wxGridCellCoordsArray& { + $target = wxGridCellCoordsArray_helper($source); +} + + +// ...and the helper function for the above typemap. +%{ +PyObject* wxGridCellCoordsArray_helper(const wxGridCellCoordsArray* source) +{ + PyObject* list = PyList_New(0); + size_t idx; + for (idx = 0; idx < source->GetCount(); idx += 1) { + wxGridCellCoords& coord = source->Item(idx); + PyObject* tup = PyTuple_New(2); + PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(coord.GetRow())); + PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(coord.GetCol())); + PyList_Append(list, tup); + Py_DECREF(tup); + } + return list; +} +%} + //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // The grid itself @@ -1763,12 +1798,11 @@ public: bool IsInSelection( int row, int col ); // TODO: ??? bool IsInSelection( const wxGridCellCoords& coords ) -// TODO: These need typemaps -// wxGridCellCoordsArray GetSelectedCells() const; -// wxGridCellCoordsArray GetSelectionBlockTopLeft() const; -// wxGridCellCoordsArray GetSelectionBlockBottomRight() const; -// wxArrayInt GetSelectedRows() const; -// wxArrayInt GetSelectedCols() const; + wxGridCellCoordsArray& GetSelectedCells() const; + wxGridCellCoordsArray& GetSelectionBlockTopLeft() const; + wxGridCellCoordsArray& GetSelectionBlockBottomRight() const; + wxArrayInt& GetSelectedRows() const; + wxArrayInt& GetSelectedCols() const; // This function returns the rectangle that encloses the block of cells diff --git a/wxPython/src/my_typemaps.i b/wxPython/src/my_typemaps.i index 7f5ccb9443..a21ee3079f 100644 --- a/wxPython/src/my_typemaps.i +++ b/wxPython/src/my_typemaps.i @@ -308,6 +308,18 @@ $function } +// Typemap to convert an array of ints to a list +%typemap(python, out) wxArrayInt& { + $target = PyList_New(0); + size_t idx; + for (idx = 0; idx < $source->GetCount(); idx += 1) { + PyObject* val = PyInt_FromLong($source->Item(idx)); + PyList_Append($target, val); + Py_DECREF(val); + } +} + + //--------------------------------------------------------------------------- // Map T_OUTPUTs for floats to return ints.