From f9b6e2c33b387da6741fd4b3d1811739f91fc073 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Fri, 7 Mar 2025 13:19:01 -0500 Subject: [PATCH] [TD]add check for Gui up --- src/Mod/TechDraw/App/DrawUtil.cpp | 8 ++++++++ src/Mod/TechDraw/App/DrawUtil.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index e6e58c846c..60a7bd92d2 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -1887,6 +1887,14 @@ std::string DrawUtil::cleanFilespecBackslash(const std::string& filespec) return noBackslash; } +//! returns true if the Gui module and its event loop are active. +bool DrawUtil::isGuiUp() +{ + std::string pyCommand{"import FreeCAD\nguiState = FreeCAD.GuiUp"}; + std::string result{Base::Interpreter().runStringWithKey(pyCommand.c_str(), "guiState", "None")}; + return (result == "1"); +} + //============================ // various debugging routines. diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 3eec9bed80..9e4a9edcee 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -271,6 +271,7 @@ public: static std::string cleanFilespecBackslash(const std::string& filespec); + static bool isGuiUp(); //debugging routines static void dumpVertexes(const char* text, const TopoDS_Shape& s);