Commit 54957b47 authored by Minh Ngo's avatar Minh Ngo
Browse files

Python 3 backend commands are running now asynch-

ronously.

BUG: 345376
parent fcbfbd27
......@@ -172,11 +172,10 @@ void PythonSession::runExpression(PythonExpression* expr)
}
if(command.contains(QLatin1String("import "))){
if(identifyKeywords(command.simplified())){
continue;
} else {
readOutput(expr, command.simplified());
readExpressionOutput(command.simplified());
return;
}
}
......@@ -226,7 +225,13 @@ void PythonSession::runExpression(PythonExpression* expr)
}
readOutput(expr, commandProcessing);
readExpressionOutput(commandProcessing);
}
// Is called asynchronously in the Python3 plugin
void PythonSession::readExpressionOutput(const QString& commandProcessing)
{
readOutput(commandProcessing);
}
void PythonSession::runClassOutputPython() const
......@@ -348,21 +353,14 @@ void PythonSession::expressionFinished()
qDebug() << "size: " << m_runningExpressions.size();
}
void PythonSession::readOutput(PythonExpression* expr, const QString& commandProcessing)
void PythonSession::updateOutput()
{
qDebug() << "readOutput";
getPythonCommandOutput(commandProcessing);
if(m_error.isEmpty()){
expr->parseOutput(m_output);
m_currentExpression->parseOutput(m_output);
qDebug() << "output: " << m_output;
} else {
expr->parseError(m_error);
m_currentExpression->parseError(m_error);
qDebug() << "error: " << m_error;
}
......@@ -372,6 +370,15 @@ void PythonSession::readOutput(PythonExpression* expr, const QString& commandPro
changeStatus(Cantor::Session::Done);
}
void PythonSession::readOutput(const QString& commandProcessing)
{
qDebug() << "readOutput";
getPythonCommandOutput(commandProcessing);
updateOutput();
}
void PythonSession::plotFileChanged(const QString& filename)
{
qDebug() << "plotFileChanged filename:" << filename;
......
......@@ -56,22 +56,20 @@ class CANTOR_EXPORT PythonSession : public Cantor::Session
virtual bool integratePlots() const = 0;
virtual QStringList autorunScripts() const = 0;
public Q_SLOTS:
void readOutput(PythonExpression* expr, const QString& commandProcessing);
void plotFileChanged(const QString& filename);
private:
KDirWatch* m_watch;
QStringList m_listPlotName;
QString m_output;
QString m_error;
Cantor::DefaultVariableModel* m_variableModel;
QList<PythonExpression*> m_runningExpressions;
PythonExpression* m_currentExpression;
protected:
QString m_output;
QString m_error;
private:
void listVariables();
void runClassOutputPython() const;
void getPythonCommandOutput(const QString& commandProcessing);
......@@ -83,7 +81,15 @@ class CANTOR_EXPORT PythonSession : public Cantor::Session
virtual QString getOutput() const = 0;
virtual QString getError() const = 0;
virtual void readExpressionOutput(const QString& commandProcessing);
protected:
void runClassOutputPython() const;
void updateOutput();
private Q_SLOTS:
void readOutput(const QString& commandProcessing);
void plotFileChanged(const QString& filename);
void expressionFinished();
Q_SIGNALS:
......
......@@ -20,6 +20,7 @@
#include "python3session.h"
#include "settings.h"
#include "../python/pythonexpression.h"
#include <QDebug>
#include <QDBusConnection>
......@@ -101,6 +102,28 @@ void Python3Session::runPythonCommand(const QString& command) const
m_pIface->call(QString::fromAscii("runPythonCommand"), command);
}
void Python3Session::runPythonCommandAsync(const QString& command)
{
m_pIface->callWithCallback(QString::fromAscii("runPythonCommand"), {command},
(Python3Session*)this,
SLOT(onResultReady()));
}
void Python3Session::readExpressionOutput(const QString& commandProcessing)
{
runClassOutputPython();
runPythonCommandAsync(commandProcessing);
changeStatus(Cantor::Session::Running);
}
void Python3Session::onResultReady()
{
m_output = getOutput();
m_error = getError();
updateOutput();
}
QString Python3Session::getOutput() const
{
const QDBusReply<QString>& reply = m_pIface->call(QString::fromAscii("getOutput"));
......
......@@ -27,6 +27,7 @@ class QDBusInterface;
class KProcess;
class Python3Session : public PythonSession
{
Q_OBJECT
public:
Python3Session(Cantor::Backend* backend);
......@@ -39,12 +40,21 @@ class Python3Session : public PythonSession
private:
void runPythonCommand(const QString& command) const;
void runPythonCommandAsync(const QString& command);
void readExpressionOutput(const QString& commandProcessing);
QString getOutput() const;
QString getError() const;
private Q_SLOTS:
void onResultReady();
private:
QDBusInterface* m_pIface;
KProcess* m_pProcess;
Q_SIGNALS:
void updateHighlighter();
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment