Gui: add WaitCursor API
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user