diff --git a/src/App/Extension.cpp b/src/App/Extension.cpp index 0a150a9b40..c8e8af584f 100644 --- a/src/App/Extension.cpp +++ b/src/App/Extension.cpp @@ -69,6 +69,7 @@ using namespace App; Extension::~Extension() { if (!ExtensionPythonObject.is(Py::_None())) { + Base::PyGILStateLocker lock; // Remark: The API of Py::Object has been changed to set whether the wrapper owns the passed // Python object or not. In the constructor we forced the wrapper to own the object so we // need not to dec'ref the Python object any more. But we must still invalidate the Python diff --git a/src/App/Extension.pyi b/src/App/Extension.pyi index 2246d43946..0005862c31 100644 --- a/src/App/Extension.pyi +++ b/src/App/Extension.pyi @@ -1,3 +1,4 @@ +from typing import Final, Any from Base.PyObjectBase import PyObjectBase @@ -7,4 +8,6 @@ class Extension(PyObjectBase): Author: Stefan Troeger (stefantroeger@gmx.net) Licence: LGPL """ - ... + + ExtendedObject: Final[Any] = None + """Get extended container object""" diff --git a/src/App/ExtensionPyImp.cpp b/src/App/ExtensionPyImp.cpp index 23a1cf2b74..4b8afc4123 100644 --- a/src/App/ExtensionPyImp.cpp +++ b/src/App/ExtensionPyImp.cpp @@ -23,9 +23,9 @@ #include "PreCompiled.h" -#include "Application.h" +#include "ExtensionContainer.h" -// inclusion of the generated files (generated out of PropertyContainerPy.xml) +// inclusion of the generated files (generated out of ExtensionPy.pyi) #include #include @@ -37,6 +37,11 @@ std::string ExtensionPy::representation() const return {""}; } +Py::Object ExtensionPy::getExtendedObject() const +{ + return Py::Object(getExtensionPtr()->getExtendedContainer()->getPyObject(), true); +} + PyObject* ExtensionPy::getCustomAttributes(const char* /*attr*/) const { return nullptr; diff --git a/src/App/ExtensionPython.h b/src/App/ExtensionPython.h index a4d8e7428b..52c4ed3db4 100644 --- a/src/App/ExtensionPython.h +++ b/src/App/ExtensionPython.h @@ -63,12 +63,12 @@ using ExtensionPython = ExtensionPythonT; Base::PyGILStateLocker lock; \ Py::Object result; \ try { \ - Property* proxy = this->getExtendedContainer()->getPropertyByName("Proxy"); \ - if (proxy && proxy->is()) { \ - Py::Object feature = static_cast(proxy)->getValue(); \ - if (feature.hasAttr(std::string("function"))) { \ + App::Property* proxy = this->getExtendedContainer()->getPropertyByName("Proxy"); \ + if (proxy && proxy->is()) { \ + Py::Object feature = static_cast(proxy)->getValue(); \ + if (feature.hasAttr(std::string(#function))) { \ if (feature.hasAttr("__object__")) { \ - Py::Callable method(feature.getAttr(std::string("function"))); + Py::Callable method(feature.getAttr(std::string(#function))); #define EXTENSION_PROXY_SECOND(function) \ @@ -76,7 +76,7 @@ using ExtensionPython = ExtensionPythonT; } \ else \ { \ - Py::Callable method(feature.getAttr(std::string("function"))); + Py::Callable method(feature.getAttr(std::string(#function))); #define EXTENSION_PROXY_THIRD() \ result = method.apply(args); \ @@ -109,13 +109,13 @@ using ExtensionPython = ExtensionPythonT; EXTENSION_PROXY_THIRD() #define EXTENSION_PYTHON_OVERRIDE_VOID_NOARGS(function) \ - virtual void function() override { EXTENSION_PROXY_NOARGS(function) }; + virtual void function() override { EXTENSION_PROXY_NOARG(function) }; #define EXTENSION_PYTHON_OVERRIDE_OBJECT_NOARGS(function) \ virtual PyObject* function() override \ { \ - EXTENSION_PROXY_NOARGS(function) \ - return res.ptr(); \ + EXTENSION_PROXY_NOARG(function) \ + return result.ptr(); \ }; } // namespace App diff --git a/src/Mod/Test/Document.py b/src/Mod/Test/Document.py index efc93c62ee..75d207dcbb 100644 --- a/src/Mod/Test/Document.py +++ b/src/Mod/Test/Document.py @@ -431,7 +431,7 @@ class DocumentBasicCases(unittest.TestCase): # test if the method override works class SpecialGroup: - def allowObject(self, obj): + def allowObject(self, ext, obj): return False callback = SpecialGroup() @@ -444,7 +444,7 @@ class DocumentBasicCases(unittest.TestCase): grp2.addObject(obj) self.assertTrue(len(grp2.Group) == 0) except Exception: - self.assertTrue(True) + self.assertTrue(False) self.Doc.removeObject(grp.Name) self.Doc.removeObject(grp2.Name) @@ -721,7 +721,7 @@ class SaveRestoreSpecialGroup: obj.addExtension("App::GroupExtensionPython") obj.Proxy = self - def allowObject(self, obj): + def allowObject(self, ext, obj): return False