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
+24 -22
View File
@@ -63,9 +63,7 @@
#include "pipestate.inl"
CaptureContext::CaptureContext(QString paramFilename, QString remoteHost, uint32_t remoteIdent,
bool temp, PersistantConfig &cfg)
: m_Config(cfg)
CaptureContext::CaptureContext(PersistantConfig &cfg) : m_Config(cfg)
{
m_CaptureLoaded = false;
m_LoadInProgress = false;
@@ -90,25 +88,6 @@ CaptureContext::CaptureContext(QString paramFilename, QString remoteHost, uint32
m_Icon->addFile(QStringLiteral(":/logo.svg"), QSize(), QIcon::Normal, QIcon::Off);
m_MainWindow = new MainWindow(*this);
m_MainWindow->show();
if(remoteIdent != 0)
{
m_MainWindow->ShowLiveCapture(
new LiveCapture(*this, remoteHost, remoteHost, remoteIdent, m_MainWindow, m_MainWindow));
}
if(!paramFilename.isEmpty())
{
QFileInfo checkFile(paramFilename);
if(checkFile.exists() && checkFile.isFile())
{
m_MainWindow->LoadFromFilename(paramFilename, temp);
if(temp)
m_MainWindow->takeCaptureOwnership();
}
}
{
QDir dir(configFilePath("extensions"));
@@ -137,6 +116,29 @@ CaptureContext::~CaptureContext()
delete m_MainWindow;
}
void CaptureContext::Begin(QString paramFilename, QString remoteHost, uint32_t remoteIdent, bool temp)
{
m_MainWindow->show();
if(remoteIdent != 0)
{
m_MainWindow->ShowLiveCapture(
new LiveCapture(*this, remoteHost, remoteHost, remoteIdent, m_MainWindow, m_MainWindow));
}
if(!paramFilename.isEmpty())
{
QFileInfo checkFile(paramFilename);
if(checkFile.exists() && checkFile.isFile())
{
m_MainWindow->LoadFromFilename(paramFilename, temp);
if(temp)
m_MainWindow->takeCaptureOwnership();
}
}
}
bool CaptureContext::isRunning()
{
return m_MainWindow && m_MainWindow->isVisible();
+2 -2
View File
@@ -58,10 +58,10 @@ class CaptureContext : public ICaptureContext, IExtensionManager
Q_DECLARE_TR_FUNCTIONS(CaptureContext);
public:
CaptureContext(QString paramFilename, QString remoteHost, uint32_t remoteIdent, bool temp,
PersistantConfig &cfg);
CaptureContext(PersistantConfig &cfg);
~CaptureContext();
void Begin(QString paramFilename, QString remoteHost, uint32_t remoteIdent, bool temp);
bool isRunning();
rdcstr TempCaptureFilename(const rdcstr &appname) override;
+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();