Changeset View
Changeset View
Standalone View
Standalone View
src/backends/maxima/maximasession.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | //maybe this is caused by some behaviour if the Prompt is split into multiple "readStdout" calls | 44 | //maybe this is caused by some behaviour if the Prompt is split into multiple "readStdout" calls | ||
45 | //the Expressions are encapsulated in () to allow capturing for the text | 45 | //the Expressions are encapsulated in () to allow capturing for the text | ||
46 | const QRegExp MaximaSession::MaximaOutputPrompt=QRegExp(QLatin1String("(\\(\\s*%\\s*o\\s*[0-9\\s]*\\))")); //Text, maxima outputs, before any output | 46 | const QRegExp MaximaSession::MaximaOutputPrompt=QRegExp(QLatin1String("(\\(\\s*%\\s*o\\s*[0-9\\s]*\\))")); //Text, maxima outputs, before any output | ||
47 | const QRegExp MaximaSession::MaximaInputPrompt = QRegExp(QLatin1String("(\\(\\s*%\\s*i\\s*[0-9\\s]*\\))")); | 47 | const QRegExp MaximaSession::MaximaInputPrompt = QRegExp(QLatin1String("(\\(\\s*%\\s*i\\s*[0-9\\s]*\\))")); | ||
48 | 48 | | |||
49 | 49 | | |||
50 | MaximaSession::MaximaSession( Cantor::Backend* backend ) : Session(backend), | 50 | MaximaSession::MaximaSession( Cantor::Backend* backend ) : Session(backend), | ||
51 | m_process(nullptr), | 51 | m_process(nullptr), | ||
52 | m_variableModel(new MaximaVariableModel(this)), | | |||
53 | m_justRestarted(false) | 52 | m_justRestarted(false) | ||
54 | { | 53 | { | ||
54 | setVariableModel(new MaximaVariableModel(this)); | ||||
55 | } | 55 | } | ||
56 | 56 | | |||
57 | void MaximaSession::login() | 57 | void MaximaSession::login() | ||
58 | { | 58 | { | ||
59 | qDebug()<<"login"; | 59 | qDebug()<<"login"; | ||
60 | 60 | | |||
61 | if (m_process) | 61 | if (m_process) | ||
62 | return; //TODO: why do we call login() again?!? | 62 | return; //TODO: why do we call login() again?!? | ||
Show All 21 Lines | |||||
84 | connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdOut())); | 84 | connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdOut())); | ||
85 | connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStdErr())); | 85 | connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStdErr())); | ||
86 | connect(m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(reportProcessError(QProcess::ProcessError))); | 86 | connect(m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(reportProcessError(QProcess::ProcessError))); | ||
87 | 87 | | |||
88 | if(!MaximaSettings::self()->autorunScripts().isEmpty()){ | 88 | if(!MaximaSettings::self()->autorunScripts().isEmpty()){ | ||
89 | QString autorunScripts = MaximaSettings::self()->autorunScripts().join(QLatin1String(";")); | 89 | QString autorunScripts = MaximaSettings::self()->autorunScripts().join(QLatin1String(";")); | ||
90 | autorunScripts.append(QLatin1String(";kill(labels)")); // Reset labels after running autorun scripts | 90 | autorunScripts.append(QLatin1String(";kill(labels)")); // Reset labels after running autorun scripts | ||
91 | evaluateExpression(autorunScripts, MaximaExpression::DeleteOnFinish, true); | 91 | evaluateExpression(autorunScripts, MaximaExpression::DeleteOnFinish, true); | ||
92 | updateVariables(); | ||||
92 | } | 93 | } | ||
93 | 94 | | |||
94 | changeStatus(Session::Done); | 95 | changeStatus(Session::Done); | ||
95 | emit loginDone(); | 96 | emit loginDone(); | ||
96 | qDebug()<<"login done"; | 97 | qDebug()<<"login done"; | ||
97 | } | 98 | } | ||
98 | 99 | | |||
99 | void MaximaSession::logout() | 100 | void MaximaSession::logout() | ||
Show All 17 Lines | 109 | // if(status()==Cantor::Session::Running) | |||
117 | { | 118 | { | ||
118 | m_process->kill(); | 119 | m_process->kill(); | ||
119 | qDebug()<<"maxima still running, process kill enforced"; | 120 | qDebug()<<"maxima still running, process kill enforced"; | ||
120 | } | 121 | } | ||
121 | 122 | | |||
122 | expressionQueue().clear(); | 123 | expressionQueue().clear(); | ||
123 | delete m_process; | 124 | delete m_process; | ||
124 | m_process = nullptr; | 125 | m_process = nullptr; | ||
125 | m_variableModel->clear(); | 126 | variableModel()->clearVariables(); | ||
127 | variableModel()->clearFunctions(); | ||||
asemke: why this cast? | |||||
126 | 128 | | |||
127 | changeStatus(Status::Disable); | 129 | changeStatus(Status::Disable); | ||
128 | 130 | | |||
129 | qDebug()<<"logout done"; | 131 | qDebug()<<"logout done"; | ||
130 | } | 132 | } | ||
131 | 133 | | |||
132 | Cantor::Expression* MaximaSession::evaluateExpression(const QString& cmd, Cantor::Expression::FinishingBehavior behave, bool internal) | 134 | Cantor::Expression* MaximaSession::evaluateExpression(const QString& cmd, Cantor::Expression::FinishingBehavior behave, bool internal) | ||
133 | { | 135 | { | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 189 | { | |||
189 | emit error(i18n("Failed to start Maxima")); | 191 | emit error(i18n("Failed to start Maxima")); | ||
190 | } | 192 | } | ||
191 | } | 193 | } | ||
192 | 194 | | |||
193 | void MaximaSession::currentExpressionChangedStatus(Cantor::Expression::Status status) | 195 | void MaximaSession::currentExpressionChangedStatus(Cantor::Expression::Status status) | ||
194 | { | 196 | { | ||
195 | Cantor::Expression* expression = expressionQueue().first(); | 197 | Cantor::Expression* expression = expressionQueue().first(); | ||
196 | const QString& cmd = expression->command(); | 198 | const QString& cmd = expression->command(); | ||
197 | bool isInternal = expression->isInternal(); | | |||
198 | qDebug() << "expression status changed: command = " << expression->command() << ", status = " << status; | 199 | qDebug() << "expression status changed: command = " << expression->command() << ", status = " << status; | ||
199 | 200 | | |||
200 | if(status!=Cantor::Expression::Computing) //The session is ready for the next command | 201 | switch (status) | ||
201 | { | 202 | { | ||
203 | case Cantor::Expression::Done: | ||||
204 | case Cantor::Expression::Error: | ||||
202 | qDebug()<<"################################## EXPRESSION END ###############################################"; | 205 | qDebug()<<"################################## EXPRESSION END ###############################################"; | ||
203 | disconnect(expression, SIGNAL(statusChanged(Cantor::Expression::Status)), | 206 | disconnect(expression, SIGNAL(statusChanged(Cantor::Expression::Status)), | ||
204 | this, SLOT(currentExpressionChangedStatus(Cantor::Expression::Status))); | 207 | this, SLOT(currentExpressionChangedStatus(Cantor::Expression::Status))); | ||
205 | 208 | | |||
206 | expressionQueue().removeFirst(); | 209 | finishFirstExpression(); | ||
207 | if(expressionQueue().isEmpty()) | 210 | break; | ||
208 | { | | |||
209 | //if we are done with all the commands in the queue, | | |||
210 | //use the opportunity to update the variablemodel (if the last command wasn't already an update, as infinite loops aren't fun) | | |||
211 | 211 | | |||
212 | if(!isInternal || !m_variableModel->isUpdateCommand(cmd)) | 212 | default: | ||
213 | m_variableModel->update(); | 213 | break; | ||
214 | else | | |||
215 | changeStatus(Cantor::Session::Done); | | |||
216 | }else | | |||
217 | { | | |||
218 | runFirstExpression(); | | |||
219 | } | | |||
220 | } | 214 | } | ||
221 | } | 215 | } | ||
222 | 216 | | |||
223 | void MaximaSession::runFirstExpression() | 217 | void MaximaSession::runFirstExpression() | ||
224 | { | 218 | { | ||
225 | qDebug()<<"running next expression"; | 219 | qDebug()<<"running next expression"; | ||
226 | if (!m_process) | 220 | if (!m_process) | ||
227 | return; | 221 | return; | ||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | 319 | { | |||
326 | return new MaximaSyntaxHelpObject(command, this); | 320 | return new MaximaSyntaxHelpObject(command, this); | ||
327 | } | 321 | } | ||
328 | 322 | | |||
329 | QSyntaxHighlighter* MaximaSession::syntaxHighlighter(QObject* parent) | 323 | QSyntaxHighlighter* MaximaSession::syntaxHighlighter(QObject* parent) | ||
330 | { | 324 | { | ||
331 | return new MaximaHighlighter(parent, this); | 325 | return new MaximaHighlighter(parent, this); | ||
332 | } | 326 | } | ||
333 | 327 | | |||
334 | QAbstractItemModel* MaximaSession::variableModel() | | |||
335 | { | | |||
336 | return m_variableModel; | | |||
337 | } | | |||
338 | | ||||
339 | void MaximaSession::write(const QString& exp) { | 328 | void MaximaSession::write(const QString& exp) { | ||
340 | qDebug()<<"################################## EXPRESSION START ###############################################"; | 329 | qDebug()<<"################################## EXPRESSION START ###############################################"; | ||
341 | qDebug()<<"sending expression to maxima process: " << exp; | 330 | qDebug()<<"sending expression to maxima process: " << exp; | ||
342 | m_process->write(exp.toUtf8()); | 331 | m_process->write(exp.toUtf8()); | ||
343 | } | 332 | } |
why this cast?