App: fix Link appLinkExecute

Call hasAttr() first before getAttr().
This commit is contained in:
Zheng, Lei
2020-02-22 16:21:15 +08:00
committed by Yorik van Havre
parent 64cc58e359
commit 27eb8bebeb

View File

@@ -207,22 +207,24 @@ App::DocumentObjectExecReturn *LinkBaseExtension::extensionExecute(void) {
const char *method = getLinkExecuteValue();
if(!method || !method[0])
method = "appLinkExecute";
Py::Object attr = proxyValue.getAttr(method);
if(attr.ptr() && attr.isCallable()) {
Py::Tuple args(4);
args.setItem(0, Py::asObject(linked->getPyObject()));
args.setItem(1, Py::asObject(container->getPyObject()));
if(!_getElementCountValue()) {
Py::Callable(attr).apply(args);
} else {
const auto &elements = _getElementListValue();
for(int i=0; i<_getElementCountValue(); ++i) {
args.setItem(2, Py::Int(i));
if(i < (int)elements.size())
args.setItem(3, Py::asObject(elements[i]->getPyObject()));
else
args.setItem(3, Py::Object());
if(proxyValue.hasAttr(method)) {
Py::Object attr = proxyValue.getAttr(method);
if(attr.ptr() && attr.isCallable()) {
Py::Tuple args(4);
args.setItem(0, Py::asObject(linked->getPyObject()));
args.setItem(1, Py::asObject(container->getPyObject()));
if(!_getElementCountValue()) {
Py::Callable(attr).apply(args);
} else {
const auto &elements = _getElementListValue();
for(int i=0; i<_getElementCountValue(); ++i) {
args.setItem(2, Py::Int(i));
if(i < (int)elements.size())
args.setItem(3, Py::asObject(elements[i]->getPyObject()));
else
args.setItem(3, Py::Object());
Py::Callable(attr).apply(args);
}
}
}
}