Allow qrenderdoc command line python scripts to call sys.exit()

* Previously we'd catch the sys.exit "exception" and print it then show the
  window.
This commit is contained in:
baldurk
2020-08-31 13:10:38 +01:00
parent d5f45f6476
commit b5a6796240
3 changed files with 60 additions and 41 deletions
+34 -17
View File
@@ -435,7 +435,7 @@ int main(int argc, char *argv[])
config.Save();
}
CaptureContext ctx(filename, remoteHost, remoteIdent, temp, config);
CaptureContext ctx(config);
if(replayHostIndex >= 0)
{
ctx.SetRemoteHost(replayHostIndex);
@@ -457,6 +457,8 @@ int main(int argc, char *argv[])
ANALYTIC_SET(Metadata.DaysUsed[QDateTime::currentDateTime().date().day()], true);
bool pythonExited = false;
if(!pyscripts.isEmpty())
{
PythonContextHandle py;
@@ -465,22 +467,29 @@ int main(int argc, char *argv[])
py.ctx().setGlobal("pyrenderdoc", (ICaptureContext *)&ctx);
QObject::connect(&py.ctx(), &PythonContext::exception,
[](const QString &type, const QString &value, int, QList<QString> frames) {
QObject::connect(
&py.ctx(), &PythonContext::exception,
[&pythonExited](const QString &type, const QString &value, int, QList<QString> frames) {
QString exString;
if(type == lit("SystemExit"))
{
pythonExited = true;
return;
}
if(!frames.isEmpty())
{
exString += tr("Traceback (most recent call last):\n");
for(const QString &f : frames)
exString += QFormatStr(" %1\n").arg(f);
}
QString exString;
exString += QFormatStr("%1: %2\n").arg(type).arg(value);
if(!frames.isEmpty())
{
exString += tr("Traceback (most recent call last):\n");
for(const QString &f : frames)
exString += QFormatStr(" %1\n").arg(f);
}
qCritical("%s", exString.toUtf8().data());
});
exString += QFormatStr("%1: %2\n").arg(type).arg(value);
qCritical("%s", exString.toUtf8().data());
});
QObject::connect(&py.ctx(), &PythonContext::textOutput,
[](bool isStdError, const QString &output) {
@@ -502,14 +511,22 @@ int main(int argc, char *argv[])
{
qWarning() << "Invalid python script" << f;
}
if(pythonExited)
break;
}
}
while(ctx.isRunning())
if(!pythonExited)
{
application.processEvents(QEventLoop::WaitForMoreEvents);
QCoreApplication::sendPostedEvents();
QCoreApplication::sendPostedEvents(NULL, QEvent::DeferredDelete);
ctx.Begin(filename, remoteHost, remoteIdent, temp);
while(ctx.isRunning())
{
application.processEvents(QEventLoop::WaitForMoreEvents);
QCoreApplication::sendPostedEvents();
QCoreApplication::sendPostedEvents(NULL, QEvent::DeferredDelete);
}
}
config.Save();