Gui: fixes #10617: Ctrl+C only stop python running in console not from macros

This commit handles the execution from the macro dialog
This commit is contained in:
wmayer
2023-09-09 14:02:57 +02:00
parent 67a0d077e1
commit ab3878ad97
4 changed files with 78 additions and 0 deletions

View File

@@ -23,12 +23,15 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QApplication>
#include <QKeyEvent>
#include <QTime>
#include <QGuiApplication>
#endif
#include "PythonTracing.h"
#include <App/Application.h>
#include <Base/Interpreter.h>
using namespace Gui;
@@ -113,6 +116,7 @@ void PythonTracing::setPythonTraceEnabled(bool enabled) const
Private::profilerDisabled = true;
}
Base::PyGILStateLocker lock;
PyEval_SetTrace(trace, nullptr);
}
@@ -159,3 +163,36 @@ PythonTracingLocker::~PythonTracingLocker()
{
trace.deactivate();
}
// ------------------------------------------------------------------------------------------------
PythonTracingWatcher::PythonTracingWatcher(QObject* parent)
: QObject(parent)
{
qApp->installEventFilter(this);
}
PythonTracingWatcher::~PythonTracingWatcher()
{
qApp->removeEventFilter(this);
}
bool PythonTracingWatcher::eventFilter(QObject* object, QEvent* event)
{
if (event && event->type() == QEvent::ShortcutOverride) {
auto kevent = static_cast<QKeyEvent*>(event);
if (kevent->key() == Qt::Key_C && kevent->modifiers() == Qt::ControlModifier) {
if (trace.interrupt()) {
return true;
}
}
}
return QObject::eventFilter(object, event);
}
PythonTracing& PythonTracingWatcher::getTrace()
{
trace.fetchFromSettings();
return trace;
}