itom
Loading...
Searching...
No Matches
pyCodeFormatter.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2023, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21
22*********************************************************************** */
23
24#pragma once
25
26#include <qobject.h>
27#include <qprocess.h>
28#include <qstring.h>
29#include <qsharedpointer.h>
30#include <qprogressdialog.h>
31#include <qtemporarydir.h>
32
33#include "common/retVal.h"
34
35namespace ito
36{
37
38 class PyCodeFormatter : public QObject
39 {
40 Q_OBJECT
41 public:
42 PyCodeFormatter(QObject *parent = nullptr);
44
45 ito::RetVal startSortingAndFormatting(const QString &importSortingCmd, const QString &formattingCmd, const QString &code, QWidget *dialogParent = nullptr);
46
47 private:
48 QProcess m_processFormatter;
49 QProcess m_processImportSort;
50 QString m_currentCode;
51 QString m_currentError;
52 QSharedPointer<QProgressDialog> m_progressDialog;
53 bool m_isCancelling;
54 const QString m_importSortTempFileName;
55 QTemporaryDir m_importSortTempDir;
56 QString m_pythonExePath;
57 QString m_formattingCmd;
58
59 ito::RetVal getPythonPath(QString &path) const;
60 ito::RetVal startImportsSorting(const QString& importSortingCmd, const QString& code);
61 ito::RetVal startCodeFormatting(const QString &formattingCmd, const QString &code);
62
63
64 private slots:
65 void formatterErrorOccurred(QProcess::ProcessError error);
66 void formatterFinished(int exitCode, QProcess::ExitStatus exitStatus);
67 void formatterReadyReadStandardError();
68 void formatterReadyReadStandardOutput();
69 void formatterStarted();
70
71 void importSortErrorOccurred(QProcess::ProcessError error);
72 void importSortFinished(int exitCode, QProcess::ExitStatus exitStatus);
73 void importSortReadyReadStandardError();
74 void importSortStarted();
75
76 void cancelRequested();
77
78 signals:
79 void formattingDone(bool success, QString code);
80
81 };
82
83}; // end namespace ito
Definition pyCodeFormatter.h:39
Class for managing status values (like errors or warning)
Definition retVal.h:54
Definition apiFunctionsGraph.cpp:40