Skip to content

Commit

Permalink
Merge pull request #4842 from 0penBrain/getSheetPy
Browse files Browse the repository at this point in the history
[Spreadsheet] Expose SpreadsheetView::getSheet to Python
  • Loading branch information
yorikvanhavre committed Jun 9, 2021
2 parents 77dd36d + 6e71362 commit 28a1300
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Mod/Spreadsheet/Gui/CMakeLists.txt
Expand Up @@ -8,6 +8,13 @@ include_directories(
${XercesC_INCLUDE_DIRS}
)

generate_from_xml(SpreadsheetViewPy)

# The XML files
set(SpreadsheetGui_XML_SRCS
SpreadsheetViewPy.xml
)

set(SpreadsheetGui_LIBS
Spreadsheet
FreeCADGui
Expand Down Expand Up @@ -54,6 +61,7 @@ endif()

SET(SpreadsheetGui_SRCS
${SpreadsheetGui_QRC_SRCS}
${SpreadsheetGui_XML_SRCS}
AppSpreadsheetGui.cpp
Command.cpp
LineEdit.h
Expand All @@ -63,6 +71,7 @@ SET(SpreadsheetGui_SRCS
Resources/Spreadsheet.qrc
SpreadsheetView.cpp
SpreadsheetView.h
SpreadsheetViewPyImp.cpp
SpreadsheetDelegate.h
SpreadsheetDelegate.cpp
SheetTableView.cpp
Expand Down
7 changes: 6 additions & 1 deletion src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp
Expand Up @@ -52,6 +52,7 @@
#include "qtcolorpicker.h"

#include "SpreadsheetView.h"
#include "SpreadsheetViewPy.h"
#include "SpreadsheetDelegate.h"
#include "ui_Sheet.h"

Expand Down Expand Up @@ -444,7 +445,11 @@ QModelIndex SheetView::currentIndex() const

PyObject *SheetView::getPyObject()
{
return Gui::MDIView::getPyObject();
if (!pythonObject)
pythonObject = new SpreadsheetViewPy(this);

Py_INCREF(pythonObject);
return pythonObject;
}

void SheetView::deleteSelf()
Expand Down
23 changes: 23 additions & 0 deletions src/Mod/Spreadsheet/Gui/SpreadsheetViewPy.xml
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="PyObjectBase"
Name="SpreadsheetViewPy"
Twin="SheetView"
TwinPointer="SheetView"
Include="Mod/Spreadsheet/Gui/SpreadsheetView.h"
Namespace="SpreadsheetGui"
FatherInclude="Base/PyObjectBase.h"
FatherNamespace="Base">
<Documentation>
<Author Licence="LGPL" Name="openBrain" EMail="" />
<UserDocu>SpreadsheetView object</UserDocu>
</Documentation>
<Methode Name="getSheet">
<Documentation>
<UserDocu>returns the sheet being displayed</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>
31 changes: 31 additions & 0 deletions src/Mod/Spreadsheet/Gui/SpreadsheetViewPyImp.cpp
@@ -0,0 +1,31 @@
#include "PreCompiled.h"

#include "SpreadsheetViewPy.h"
#include "SpreadsheetViewPy.cpp"

#include <Mod/Spreadsheet/App/SheetPy.h>

using namespace SpreadsheetGui;

PyObject* SpreadsheetViewPy::getSheet(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
return new Spreadsheet::SheetPy(getSheetViewPtr()->getSheet());
}

// returns a string which represents the object e.g. when printed in python
std::string SpreadsheetViewPy::representation(void) const
{
return std::string("<SheetView object>");
}

PyObject *SpreadsheetViewPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}

int SpreadsheetViewPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

0 comments on commit 28a1300

Please sign in to comment.