From 765e164b0b8157b4220c8fab9eeb941e194528ff Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Fri, 28 Apr 2017 15:03:47 -0300 Subject: [PATCH] Gui: implemented isShow() for python viewproviders --- src/Gui/ViewProviderPythonFeature.cpp | 28 +++++++++++++++++++++++++++ src/Gui/ViewProviderPythonFeature.h | 8 ++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Gui/ViewProviderPythonFeature.cpp b/src/Gui/ViewProviderPythonFeature.cpp index d483c6e20c..18540b4655 100644 --- a/src/Gui/ViewProviderPythonFeature.cpp +++ b/src/Gui/ViewProviderPythonFeature.cpp @@ -1005,6 +1005,34 @@ ViewProviderPythonFeatureImp::dropObject(App::DocumentObject* obj) return Rejected; } +bool ViewProviderPythonFeatureImp::isShow() const +{ + // Run the onChanged method of the proxy object. + Base::PyGILStateLocker lock; + try { + App::Property* proxy = object->getPropertyByName("Proxy"); + if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) { + Py::Object vp = static_cast(proxy)->getValue(); + if (vp.hasAttr(std::string("isShow"))) { + Py::Callable method(vp.getAttr(std::string("isShow"))); + Py::Tuple args; + Py::Boolean ok(method.apply(args)); + return static_cast(ok) ? true : false; + } + else { + return false; + } + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } + + return false; +} + + // --------------------------------------------------------- namespace Gui { diff --git a/src/Gui/ViewProviderPythonFeature.h b/src/Gui/ViewProviderPythonFeature.h index 03b93d129a..0428b62242 100644 --- a/src/Gui/ViewProviderPythonFeature.h +++ b/src/Gui/ViewProviderPythonFeature.h @@ -72,6 +72,8 @@ public: /** @name Display methods */ //@{ + /// Returns true if the icon must always appear enabled in the tree view + virtual bool isShow() const; /// get the default display mode const char* getDefaultDisplayMode() const; /// returns a list of all possible modes @@ -265,6 +267,12 @@ public: /** @name Display methods */ //@{ + /// Returns true if the icon must always appear enabled in the tree view + virtual bool isShow() const { + bool ok = imp->isShow(); + if (ok) return ok; + return ViewProviderT::isShow(); + } /// get the default display mode virtual const char* getDefaultDisplayMode() const { return imp->getDefaultDisplayMode();