From c238be2857677590e57df61f24c92daf5cb9aed7 Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Sun, 29 Jun 2025 08:53:08 +0200 Subject: [PATCH] Gui: add WaitCursor API --- src/Gui/ApplicationPy.cpp | 26 ++++++++++++++++++++++++++ src/Gui/ApplicationPy.h | 3 +++ src/Gui/WaitCursor.cpp | 13 +++++++++++++ src/Gui/WaitCursor.h | 13 +++++++++++++ 4 files changed, 55 insertions(+) diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index 4315e4f6c1..a71de70459 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -430,6 +430,12 @@ PyMethodDef ApplicationPy::Methods[] = { "Remove all children from a group node.\n" "\n" "node : object"}, + {"suspendWaitCursor", (PyCFunction) ApplicationPy::sSuspendWaitCursor, METH_VARARGS, + "suspendWaitCursor() -> None\n\n" + "Temporarily suspends the application's wait cursor and event filter."}, + {"resumeWaitCursor", (PyCFunction) ApplicationPy::sResumeWaitCursor, METH_VARARGS, + "resumeWaitCursor() -> None\n\n" + "Resumes the application's wait cursor and event filter."}, {nullptr, nullptr, 0, nullptr} /* Sentinel */ }; @@ -1813,3 +1819,23 @@ PyObject* ApplicationPy::sSetUserEditMode(PyObject * /*self*/, PyObject *args) return Py::new_reference_to(Py::Boolean(ok)); } + +PyObject* ApplicationPy::sSuspendWaitCursor(PyObject * /*self*/, PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) { + return nullptr; + } + + WaitCursor::suspend(); + Py_RETURN_NONE; +} + +PyObject* ApplicationPy::sResumeWaitCursor(PyObject * /*self*/, PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) { + return nullptr; + } + + WaitCursor::resume(); + Py_RETURN_NONE; +} diff --git a/src/Gui/ApplicationPy.h b/src/Gui/ApplicationPy.h index 362cfcf88b..e12bf388d4 100644 --- a/src/Gui/ApplicationPy.h +++ b/src/Gui/ApplicationPy.h @@ -111,6 +111,9 @@ public: static PyObject* sGetUserEditMode (PyObject *self,PyObject *args); static PyObject* sSetUserEditMode (PyObject *self,PyObject *args); + static PyObject* sSuspendWaitCursor (PyObject *self, PyObject *args); + static PyObject* sResumeWaitCursor (PyObject *self, PyObject *args); + static PyMethodDef Methods[]; // clang-format on }; diff --git a/src/Gui/WaitCursor.cpp b/src/Gui/WaitCursor.cpp index 3d548b43b8..61000bb4de 100644 --- a/src/Gui/WaitCursor.cpp +++ b/src/Gui/WaitCursor.cpp @@ -189,3 +189,16 @@ void WaitCursor::setIgnoreEvents(FilterEventsFlags flags) { WaitCursorP::getInstance()->setIgnoreEvents(flags); } + +void WaitCursor::suspend() +{ + // Calling setBusy(false) will restore the cursor and remove the event filter. + WaitCursorP::getInstance()->setBusy(false); +} + +void WaitCursor::resume() +{ + // Calling setBusy(true) will set the wait cursor and reinstall the event filter. + // The WaitCursorP's internal state `isOn` correctly handles this call. + WaitCursorP::getInstance()->setBusy(true); +} \ No newline at end of file diff --git a/src/Gui/WaitCursor.h b/src/Gui/WaitCursor.h index 6031b55a36..6b6505accf 100644 --- a/src/Gui/WaitCursor.h +++ b/src/Gui/WaitCursor.h @@ -75,6 +75,19 @@ public: FilterEventsFlags ignoreEvents() const; void setIgnoreEvents(FilterEventsFlags flags = AllEvents); + /** + * @brief Suspends the wait cursor state by restoring the normal cursor + * and removing the event filter. To be used before showing an interactive + * dialog during a long operation. + */ + static void suspend(); + + /** + * @brief Resumes the wait cursor state by setting the wait cursor + * and reinstalling the event filter, if a WaitCursor is active. + */ + static void resume(); + private: FilterEventsFlags filter; static int instances;