ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
FileRunner.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "ui_FileRunner.h"
9 
10 #include "FileRunner.h"
11 #include "PythonInterpreter.h"
12 #include "Resources.h"
13 #include "WaitingSpinnerWidget.h"
14 
15 #include <QFileDialog>
16 #include <QResizeEvent>
17 #include <QStyle>
18 
19 FileRunner::FileRunner(PythonInterpreter *interp, QWidget *parent)
20  : QDialog(parent), m_interpreter(interp), m_busyWidget(nullptr), m_ui(new Ui::FileRunner)
21 
22 {
23  m_ui->setupUi(this);
24  m_ui->runFileBtn->setEnabled(false);
25  m_ui->runFileBtn->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowRight));
26  setWindowIcon(QIcon(RUNNER_ICON_PATH));
27  m_busyWidget = new WaitingSpinnerWidget(this);
28 
29  connect(m_ui->selectFileBtn, &QPushButton::clicked, this, &FileRunner::selectFile);
30  connect(m_ui->runFileBtn, &QPushButton::clicked, this, &FileRunner::runFile);
31  connect(
32  interp, &PythonInterpreter::executionStarted, this, &FileRunner::pythonExecutionStarted);
33  connect(interp, &PythonInterpreter::executionFinished, this, &FileRunner::pythonExecutionEnded);
34 }
35 
36 void FileRunner::selectFile()
37 {
38  m_filePath = QFileDialog::getOpenFileName(this,
39  QStringLiteral("Select Python Script"),
40  QString(),
41  QStringLiteral("Python Script (*.py)"));
42  m_ui->filePathLabel->setText(m_filePath);
43  m_ui->runFileBtn->setEnabled(!m_filePath.isEmpty());
44 }
45 
46 void FileRunner::runFile() const
47 {
48  if (!m_filePath.isEmpty() && m_interpreter)
49  {
50  const std::string path = m_filePath.toStdString();
51  m_interpreter->executeFile(path);
52  }
53 }
54 
55 void FileRunner::pythonExecutionStarted()
56 {
57  setEnabled(false);
58  m_busyWidget->start();
59 }
60 
61 void FileRunner::pythonExecutionEnded()
62 {
63  setEnabled(true);
64  m_busyWidget->stop();
65 }
66 
68 {
69  delete m_ui;
70 }
71 
72 void FileRunner::resizeEvent(QResizeEvent *event)
73 {
74  m_busyWidget->resize(event->size());
75  QDialog::resizeEvent(event);
76 }
MouseEvent event
#define RUNNER_ICON_PATH
Definition: Resources.h:18
void resizeEvent(QResizeEvent *event) override
Definition: FileRunner.cpp:72
~FileRunner() noexcept override
Definition: FileRunner.cpp:67
FileRunner(PythonInterpreter *interp, QWidget *parent=nullptr)
Definition: FileRunner.cpp:19
void executionFinished()
bool executeFile(const std::string &filePath)
Execution functions (and slots)
static const std::string path
Definition: PointCloud.cpp:59