Changeset View
Changeset View
Standalone View
Standalone View
src/backends/maxima/maximasession.cpp
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
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)), | 52 | m_variableModel(new MaximaVariableModel(this)), | ||
53 | m_justRestarted(false) | 53 | m_justRestarted(false), | ||
54 | m_needUpdate(false) | ||||
54 | { | 55 | { | ||
55 | } | 56 | } | ||
56 | 57 | | |||
57 | void MaximaSession::login() | 58 | void MaximaSession::login() | ||
58 | { | 59 | { | ||
59 | qDebug()<<"login"; | 60 | qDebug()<<"login"; | ||
60 | 61 | | |||
61 | if (m_process) | 62 | if (m_process) | ||
Show All 22 Lines | |||||
84 | connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdOut())); | 85 | connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdOut())); | ||
85 | connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStdErr())); | 86 | connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStdErr())); | ||
86 | connect(m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(reportProcessError(QProcess::ProcessError))); | 87 | connect(m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(reportProcessError(QProcess::ProcessError))); | ||
87 | 88 | | |||
88 | if(!MaximaSettings::self()->autorunScripts().isEmpty()){ | 89 | if(!MaximaSettings::self()->autorunScripts().isEmpty()){ | ||
89 | QString autorunScripts = MaximaSettings::self()->autorunScripts().join(QLatin1String(";")); | 90 | QString autorunScripts = MaximaSettings::self()->autorunScripts().join(QLatin1String(";")); | ||
90 | autorunScripts.append(QLatin1String(";kill(labels)")); // Reset labels after running autorun scripts | 91 | autorunScripts.append(QLatin1String(";kill(labels)")); // Reset labels after running autorun scripts | ||
91 | evaluateExpression(autorunScripts, MaximaExpression::DeleteOnFinish, true); | 92 | evaluateExpression(autorunScripts, MaximaExpression::DeleteOnFinish, true); | ||
93 | m_needUpdate = true; | ||||
92 | } | 94 | } | ||
93 | 95 | | |||
94 | changeStatus(Session::Done); | 96 | changeStatus(Session::Done); | ||
95 | emit loginDone(); | 97 | emit loginDone(); | ||
96 | qDebug()<<"login done"; | 98 | qDebug()<<"login done"; | ||
97 | } | 99 | } | ||
98 | 100 | | |||
99 | void MaximaSession::logout() | 101 | void MaximaSession::logout() | ||
Show All 17 Lines | 110 | // if(status()==Cantor::Session::Running) | |||
117 | { | 119 | { | ||
118 | m_process->kill(); | 120 | m_process->kill(); | ||
119 | qDebug()<<"maxima still running, process kill enforced"; | 121 | qDebug()<<"maxima still running, process kill enforced"; | ||
120 | } | 122 | } | ||
121 | 123 | | |||
122 | expressionQueue().clear(); | 124 | expressionQueue().clear(); | ||
123 | delete m_process; | 125 | delete m_process; | ||
124 | m_process = nullptr; | 126 | m_process = nullptr; | ||
125 | m_variableModel->clear(); | 127 | m_variableModel->clearVariables(); | ||
128 | m_variableModel->clearFunctions(); | ||||
asemke: why this cast? | |||||
126 | 129 | | |||
127 | changeStatus(Status::Disable); | 130 | changeStatus(Status::Disable); | ||
128 | 131 | | |||
129 | qDebug()<<"logout done"; | 132 | qDebug()<<"logout done"; | ||
130 | } | 133 | } | ||
131 | 134 | | |||
132 | Cantor::Expression* MaximaSession::evaluateExpression(const QString& cmd, Cantor::Expression::FinishingBehavior behave, bool internal) | 135 | Cantor::Expression* MaximaSession::evaluateExpression(const QString& cmd, Cantor::Expression::FinishingBehavior behave, bool internal) | ||
133 | { | 136 | { | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 190 | { | |||
189 | emit error(i18n("Failed to start Maxima")); | 192 | emit error(i18n("Failed to start Maxima")); | ||
190 | } | 193 | } | ||
191 | } | 194 | } | ||
192 | 195 | | |||
193 | void MaximaSession::currentExpressionChangedStatus(Cantor::Expression::Status status) | 196 | void MaximaSession::currentExpressionChangedStatus(Cantor::Expression::Status status) | ||
194 | { | 197 | { | ||
195 | Cantor::Expression* expression = expressionQueue().first(); | 198 | Cantor::Expression* expression = expressionQueue().first(); | ||
196 | const QString& cmd = expression->command(); | 199 | const QString& cmd = expression->command(); | ||
197 | bool isInternal = expression->isInternal(); | 200 | m_needUpdate |= !expression->isInternal(); | ||
198 | qDebug() << "expression status changed: command = " << expression->command() << ", status = " << status; | 201 | qDebug() << "expression status changed: command = " << expression->command() << ", status = " << status; | ||
199 | 202 | | |||
200 | if(status!=Cantor::Expression::Computing) //The session is ready for the next command | 203 | if(status!=Cantor::Expression::Computing) //The session is ready for the next command | ||
201 | { | 204 | { | ||
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 | expressionQueue().removeFirst(); | ||
207 | if(expressionQueue().isEmpty()) | 210 | if(expressionQueue().isEmpty()) | ||
208 | { | 211 | { | ||
209 | //if we are done with all the commands in the queue, | 212 | if(m_needUpdate) | ||
210 | //use the opportunity to update the variablemodel (if the last command wasn't already an update, as infinite loops aren't fun) | 213 | { | ||
211 | | ||||
212 | if(!isInternal || !m_variableModel->isUpdateCommand(cmd)) | | |||
213 | m_variableModel->update(); | 214 | m_variableModel->update(); | ||
215 | m_needUpdate = false; | ||||
216 | } | ||||
214 | else | 217 | else | ||
215 | changeStatus(Cantor::Session::Done); | 218 | changeStatus(Cantor::Session::Done); | ||
216 | }else | 219 | }else | ||
217 | { | 220 | { | ||
218 | runFirstExpression(); | 221 | runFirstExpression(); | ||
219 | } | 222 | } | ||
220 | } | 223 | } | ||
221 | } | 224 | } | ||
▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines |
why this cast?