diff --git a/libsrc/visualization/vsmesh.cpp b/libsrc/visualization/vsmesh.cpp index ed04a128..21a2f43e 100644 --- a/libsrc/visualization/vsmesh.cpp +++ b/libsrc/visualization/vsmesh.cpp @@ -3536,6 +3536,7 @@ namespace netgen #ifdef NG_PYTHON #include <../general/ngpython.hpp> +#include "../include/nginterface.h" DLL_HEADER void ExportMeshVis(py::module &m) { @@ -3577,6 +3578,32 @@ DLL_HEADER void ExportMeshVis(py::module &m) ([] () { return vsmesh.GetMesh(); })); + m.def ("_Redraw", + ([](bool blocking, double fr) + { + static auto last_time = std::chrono::system_clock::now()-std::chrono::seconds(10); + auto now = std::chrono::system_clock::now(); + double elapsed = std::chrono::duration(now-last_time).count(); + if (elapsed * fr > 1) + { + Ng_Redraw(blocking); + last_time = std::chrono::system_clock::now(); + return true; + } + return false; + }), + py::arg("blocking")=false, py::arg("fr") = 25, R"raw_string( +Redraw all + +Parameters: + +blocking : bool + input blocking + +fr : double + input framerate + +)raw_string"); } // BOOST_PYTHON_MODULE(libvisual) // { diff --git a/python/__init__.py b/python/__init__.py index e74d1a49..0981769c 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -11,3 +11,14 @@ del sys del os from . import libngpy + +def Redraw(*args, **kwargs): + if libngpy.meshvis._Redraw(*args, **kwargs): + try: + import netgen + import tkinter + cnt = 0 + while(netgen.gui.win.tk.dooneevent(tkinter._tkinter.DONT_WAIT) and cnt < 100): + cnt += 1 + except: + pass diff --git a/python/gui.py b/python/gui.py index d43c9473..7f317144 100644 --- a/python/gui.py +++ b/python/gui.py @@ -26,8 +26,7 @@ if not netgen.libngpy._meshing._netgen_executable_started: pass def Snapshot(w,h, filename=None): - import ngsolve - ngsolve.Redraw(blocking=True) + netgen.Redraw(blocking=True) import numpy image = netgen.libngpy.Snapshot(w, h) image = numpy.array(image, dtype=numpy.uint8).reshape(h, w, 3)