Expose the selected cells to Python

This commit is contained in:
Jose Luis Cercos-Pita
2021-11-12 14:39:30 +01:00
committed by Chris Hennes
parent 96512c1e01
commit 16bbe12336
6 changed files with 124 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
#include "PreCompiled.h"
#include "ViewProviderSpreadsheetPy.h"
#include "ViewProviderSpreadsheetPy.cpp"
#include "SpreadsheetView.h"
using namespace SpreadsheetGui;
#if PY_MAJOR_VERSION >= 2
#define PyString_FromString PyUnicode_FromString
#endif
// returns a string which represents the object e.g. when printed in python
std::string ViewProviderSpreadsheetPy::representation(void) const
{
return std::string("<ViewProviderSpreadsheet object>");
}
PyObject* ViewProviderSpreadsheetPy::selectedRanges(PyObject* /*obj*/)
{
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView *sheetView = vp->getView();
std::vector<App::Range> ranges = sheetView->selectedRanges();
PyObject *out = PyList_New(0);
std::vector<App::Range>::const_iterator i = ranges.begin();
for (; i != ranges.end(); ++i)
{
PyObject *py_str = PyString_FromString(i->rangeString().c_str());
PyList_Append(out, py_str);
}
return out;
}
PyObject* ViewProviderSpreadsheetPy::selectedCells(PyObject* /*obj*/)
{
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView *sheetView = vp->getView();
QModelIndexList cells = sheetView->selectedIndexes();
PyObject *out = PyList_New(0);
for (auto it : cells) {
PyObject *py_str = PyString_FromString(
App::CellAddress(it.row(), it.column()).toString().c_str());
PyList_Append(out, py_str);
}
return out;
}
PyObject *ViewProviderSpreadsheetPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int ViewProviderSpreadsheetPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}