Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
Cantor
Commits
54957b47
Commit
54957b47
authored
Mar 21, 2015
by
Minh Ngo
Browse files
Python 3 backend commands are running now asynch-
ronously.
BUG: 345376
parent
fcbfbd27
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/backends/python/pythonsession.cpp
View file @
54957b47
...
...
@@ -172,11 +172,10 @@ void PythonSession::runExpression(PythonExpression* expr)
}
if
(
command
.
contains
(
QLatin1String
(
"import "
))){
if
(
identifyKeywords
(
command
.
simplified
())){
continue
;
}
else
{
readOutput
(
expr
,
command
.
simplified
());
read
Expression
Output
(
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
::
read
Output
(
PythonExpression
*
expr
,
const
QString
&
commandProcessing
)
void
PythonSession
::
update
Output
()
{
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
;
...
...
src/backends/python/pythonsession.h
View file @
54957b47
...
...
@@ -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:
...
...
src/backends/python3/python3session.cpp
View file @
54957b47
...
...
@@ -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"
));
...
...
src/backends/python3/python3session.h
View file @
54957b47
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment