File indexing completed on 2024-05-26 11:22:10

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2012 Filipe Saraiva <filipe@kde.org>
0004     SPDX-FileCopyrightText: 2015 Minh Ngo <minh@fedoraproject.org>
0005 */
0006 
0007 #ifndef _PYTHONSESSION_H
0008 #define _PYTHONSESSION_H
0009 
0010 #include "session.h"
0011 #include <QStringList>
0012 #include <QProcess>
0013 
0014 class PythonSession : public Cantor::Session
0015 {
0016   Q_OBJECT
0017   public:
0018     PythonSession(Cantor::Backend*);
0019     ~PythonSession() override;
0020 
0021     void login() override;
0022     void logout() override;
0023 
0024     void interrupt() override;
0025 
0026     Cantor::Expression* evaluateExpression(const QString& command, Cantor::Expression::FinishingBehavior behave = Cantor::Expression::FinishingBehavior::DoNotDelete, bool internal = false) override;
0027     Cantor::CompletionObject* completionFor(const QString& command, int index=-1) override;
0028     QSyntaxHighlighter* syntaxHighlighter(QObject* parent) override;
0029     void setWorksheetPath(const QString&) override;
0030 
0031     QString plotFilePrefixPath();
0032     int& plotFileCounter();
0033 
0034   private:
0035     QProcess* m_process{nullptr};
0036     QString m_worksheetPath;
0037     QString m_output;
0038     QString m_plotFilePrefixPath;
0039     int m_plotFileCounter{0};
0040 
0041   private Q_SLOT:
0042     void readOutput();
0043     void reportServerProcessError(QProcess::ProcessError);
0044 
0045   private:
0046     void runFirstExpression() override;
0047     void updateGraphicPackagesFromSettings();
0048     QString graphicPackageErrorMessage(QString packageId) const override;
0049 
0050     void sendCommand(const QString& command, const QStringList arguments = QStringList()) const;
0051 };
0052 
0053 #endif /* _PYTHONSESSION_H */