From 5b44d3c46b9b1d2152ba258bf0b3dc9e2c2f4331 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 9 Apr 2019 16:52:08 -0300 Subject: [PATCH] Gui: Added Gui.doc.view.viewer.setBackgroundColor() py method --- src/Gui/View3DViewerPy.cpp | 24 ++++++++++++++++++++++++ src/Gui/View3DViewerPy.h | 1 + 2 files changed, 25 insertions(+) diff --git a/src/Gui/View3DViewerPy.cpp b/src/Gui/View3DViewerPy.cpp index 472d2fd68d..4917233844 100644 --- a/src/Gui/View3DViewerPy.cpp +++ b/src/Gui/View3DViewerPy.cpp @@ -75,6 +75,8 @@ void View3DInventorViewerPy::init_type() "getPickRadius(): returns radius of confusion in pixels for picking objects on screen (selection)."); add_varargs_method("setPickRadius", &View3DInventorViewerPy::setPickRadius, "setPickRadius(new_radius): sets radius of confusion in pixels for picking objects on screen (selection)."); + add_varargs_method("setBackgroundColor", &View3DInventorViewerPy::setBackgroundColor, + "setBackgroundColor(r,g,b): sets the background color of the current viewer."); add_varargs_method("setRedirectToSceneGraph", &View3DInventorViewerPy::setRedirectToSceneGraph, "setRedirectToSceneGraph(bool): enables or disables to redirect events directly to the scene graph."); add_varargs_method("isRedirectedToSceneGraph", &View3DInventorViewerPy::isRedirectedToSceneGraph, @@ -363,6 +365,28 @@ Py::Object View3DInventorViewerPy::setPickRadius(const Py::Tuple& args) } } +Py::Object View3DInventorViewerPy::setBackgroundColor(const Py::Tuple& args) +{ + float r,g,b = 0.0; + if (!PyArg_ParseTuple(args.ptr(), "fff", &r, &g, &b)) { + throw Py::Exception(); + } + try { + SbColor col(r,g,b); + _viewer->setGradientBackgroundColor(col,col); + return Py::None(); + } + catch (const Base::Exception& e) { + throw Py::RuntimeError(e.what()); + } + catch (const std::exception& e) { + throw Py::RuntimeError(e.what()); + } + catch(...) { + throw Py::RuntimeError("Unknown C++ exception"); + } +} + Py::Object View3DInventorViewerPy::setRedirectToSceneGraph(const Py::Tuple& args) { PyObject* m=Py_False; diff --git a/src/Gui/View3DViewerPy.h b/src/Gui/View3DViewerPy.h index aa09adba0a..87389e1ef1 100644 --- a/src/Gui/View3DViewerPy.h +++ b/src/Gui/View3DViewerPy.h @@ -65,6 +65,7 @@ public: Py::Object getPickRadius(const Py::Tuple& args); Py::Object setPickRadius(const Py::Tuple& args); + Py::Object setBackgroundColor(const Py::Tuple& args); Py::Object setRedirectToSceneGraph(const Py::Tuple& args); Py::Object isRedirectedToSceneGraph(const Py::Tuple& args);