ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
PythonEditor.h
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 #pragma once
9 
10 // ##########################################################################
11 // # #
12 // # ACLOUDVIEWER PLUGIN: PythonRuntime #
13 // # #
14 // # This program is free software; you can redistribute it and/or modify #
15 // # it under the terms of the GNU General Public License as published by #
16 // # the Free Software Foundation; version 2 of the License. #
17 // # #
18 // # This program is distributed in the hope that it will be useful, #
19 // # but WITHOUT ANY WARRANTY; without even the implied warranty of #
20 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
21 // # GNU General Public License for more details. #
22 // # #
23 // # COPYRIGHT: Chris S Brown #
24 // # Thomas Montaigu #
25 // ##########################################################################
26 
27 #include <ui_PythonEditor.h>
28 
29 // Qt
30 #include "EditorSettings.h"
31 #include <CVLog.h>
32 #include <QMainWindow>
33 
34 class CodeEditor;
35 QT_BEGIN_NAMESPACE
36 class QAction;
37 class QMenu;
38 class QMdiArea;
39 class QMdiSubWindow;
40 class QFileSystemModel;
41 class QModelIndex;
42 QT_END_NAMESPACE
43 
45 class PythonInterpreter;
47 
48 #define MAX_RECENT_FILES 10
49 
50 class PythonEditor final : public QMainWindow, public Ui::PythonEditor
51 {
52  Q_OBJECT
53 
54  public:
55  static QString SettingsApplicationName();
56 
57  explicit PythonEditor(PythonInterpreter *interpreter);
58 
59  void changeEvent(QEvent *e) override;
67  bool openFile(const QString &fileName);
68 
69  protected:
70  void closeEvent(QCloseEvent *event) override;
71  Q_SIGNALS:
72  void executionCalled(const std::string &evalStatement, QListWidget *output);
73 
74  protected Q_SLOTS:
75  void newFile();
76  void promptForFileToOpen();
77  // Display a folder selection dialog & fills the
78  // content of the project view with the content of the selected folder
79  void promptForFolderToOpen();
80  void save();
81  void saveAs();
83  void openRecentFile();
84  bool eventFilter(QObject *obj, QEvent *e) override;
85  // Loads the double clicked item from the project view
86  // if its a file
87  void projectTreeDoubleClicked(const QModelIndex &index);
88 
89 #ifndef QT_NO_CLIPBOARD
90  void cut();
91  void copy();
92  void paste();
93 #endif
94  void comment();
95  void uncomment();
96  void indentMore();
97  void indentLess();
98  void updateWindowMenu();
99  void executionStarted();
100  void executionFinished();
102 
103  private:
104  static bool HasRecentFiles();
105 
106  // Initialization functions
107  void setupUi();
108  void createActions();
109  void updateMenus();
110 
111  void runExecute();
112  void readSettings();
113  void writeSettings();
114  bool loadFile(const QString &fileName);
115  void prependToRecentFiles(const QString &fileName);
116  void setRecentFilesVisible(bool visible);
117  CodeEditor *activeChildCodeEditor() const;
118  QMdiSubWindow *findChildCodeEditor(const QString &fileName) const;
119 
120  private: // Members
121  EditorSettings *m_settings{nullptr};
122 
123  QMdiArea *m_mdiArea{nullptr};
124 
125  QMenu *m_windowMenu{nullptr};
126 
127  QAction *m_recentFileActs[MAX_RECENT_FILES] = {nullptr};
128  QAction *m_recentFileSeparator{nullptr};
129  QAction *m_recentFileSubMenuAct{nullptr};
130  QAction *m_closeAct{nullptr};
131  QAction *m_closeAllAct{nullptr};
132  QAction *m_tileAct{nullptr};
133  QAction *m_cascadeAct{nullptr};
134  QAction *m_nextAct{nullptr};
135  QAction *m_previousAct{nullptr};
136  QAction *m_windowMenuSeparatorAct{nullptr};
137 };
PythonEditor::copy
void copy()
Definition: PythonEditor.cpp:279
CodeEditor::indentMore
void indentMore()
Definition: CodeEditor.cpp:358
PythonInterpreter::executionStarted
void executionStarted()
PythonEditor::executionCalled
void executionCalled(const std::string &evalStatement, QListWidget *output)
PythonEditor::updateRecentFileActions
void updateRecentFileActions()
Definition: PythonEditor.cpp:198
PythonEditor::SettingsApplicationName
static QString SettingsApplicationName()
Definition: PythonEditor.cpp:587
ProjectViewContextMenu
Definition: ProjectViewContextMenu.h:18
PythonEditor::changeEvent
void changeEvent(QEvent *e) override
Definition: PythonEditor.cpp:89
PythonEditor::cut
void cut()
Definition: PythonEditor.cpp:271
EditorSettings
Definition: EditorSettings.h:14
CodeEditor::loadFile
bool loadFile(const QString &fileName)
Definition: CodeEditor.cpp:183
CodeEditor::newFile
void newFile()
Definition: CodeEditor.cpp:172
PythonEditor::uncomment
void uncomment()
Definition: PythonEditor.cpp:303
PythonEditor::createChildCodeEditor
CodeEditor * createChildCodeEditor()
Definition: PythonEditor.cpp:523
CVLog.h
CodeEditor::comment
void comment()
Definition: CodeEditor.cpp:325
ecvMainAppInterface.h
CodeEditor::currentFile
QString currentFile() const
Definition: CodeEditor.h:40
PythonEditor::eventFilter
bool eventFilter(QObject *obj, QEvent *e) override
Definition: PythonEditor.cpp:226
CodeEditor.h
writeRecentFiles
static void writeRecentFiles(const QStringList &files, QSettings &settings)
Definition: PythonEditor.cpp:158
readRecentFiles
static QStringList readRecentFiles(QSettings &settings)
Definition: PythonEditor.cpp:145
EditorSettings.h
cloudViewer::utility::filesystem::Copy
bool Copy(const std::string &from, const std::string &to, bool include_parent_dir=false, const std::string &extname="")
Copy a file or directory.
Definition: FileSystem.cpp:249
result
core::Tensor result
Definition: VtkUtils.cpp:76
width
int width
Definition: FileIOFactory.cpp:142
CodeEditor::uncomment
void uncomment()
Definition: CodeEditor.cpp:339
height
int height
Definition: FileIOFactory.cpp:143
PythonEditor.h
PythonInterpreter
Definition: PythonInterpreter.h:32
ecvMainAppInterface
Main application interface (for plugins)
Definition: ecvMainAppInterface.h:24
event
MouseEvent event
Definition: BitmapWindowSystem.cpp:61
CodeEditor::userFriendlyCurrentFile
QString userFriendlyCurrentFile()
Definition: CodeEditor.cpp:247
PythonEditor::executionStarted
void executionStarted()
Definition: PythonEditor.cpp:325
PythonEditor::save
void save()
Definition: PythonEditor.cpp:252
RecentFilesKey
static QString RecentFilesKey()
Definition: PythonEditor.cpp:18
cloudViewer::t::geometry::path
static const std::string path
Definition: PointCloud.cpp:59
e
const double * e
Definition: essential_matrix_poly.h:10
Ui
Definition: sfEditDlg.h:16
PythonEditor::promptForFileToOpen
void promptForFileToOpen()
Definition: PythonEditor.cpp:69
PythonEditor::updateWindowMenu
void updateWindowMenu()
Definition: PythonEditor.cpp:483
CodeEditor::saveAs
bool saveAs()
Definition: CodeEditor.cpp:217
CodeEditor::indentLess
void indentLess()
Definition: CodeEditor.cpp:372
FileKey
static QString FileKey()
Definition: PythonEditor.cpp:23
PythonEditor::executionFinished
void executionFinished()
Definition: PythonEditor.cpp:334
PythonEditor::paste
void paste()
Definition: PythonEditor.cpp:287
PythonEditor::openFile
bool openFile(const QString &fileName)
Definition: PythonEditor.cpp:102
count
int count
Definition: FileIOFactory.cpp:132
PythonEditor
Definition: PythonEditor.h:50
CodeEditor
Definition: CodeEditor.h:23
PythonEditor::comment
void comment()
Definition: PythonEditor.cpp:296
PythonEditor::PythonEditor
PythonEditor(PythonInterpreter *interpreter)
Definition: PythonEditor.cpp:28
MAX_RECENT_FILES
#define MAX_RECENT_FILES
Definition: PythonEditor.h:48
PythonEditor::indentMore
void indentMore()
Definition: PythonEditor.cpp:310
PythonEditor::newFile
void newFile()
Definition: PythonEditor.cpp:61
PythonEditor::openRecentFile
void openRecentFile()
Definition: PythonEditor.cpp:218
PythonInterpreter.h
PythonInterpreter::executeCode
void executeCode(const std::string &code, QListWidget *output)
Definition: PythonInterpreter.cpp:144
PythonEditor::projectTreeDoubleClicked
void projectTreeDoubleClicked(const QModelIndex &index)
Definition: PythonEditor.cpp:117
PythonInterpreter::executionFinished
void executionFinished()
PythonEditor::promptForFolderToOpen
void promptForFolderToOpen()
Definition: PythonEditor.cpp:79
PythonEditor::indentLess
void indentLess()
Definition: PythonEditor.cpp:317
PythonEditor::saveAs
void saveAs()
Definition: PythonEditor.cpp:260
PythonEditor::closeEvent
void closeEvent(QCloseEvent *event) override
Definition: PythonEditor.cpp:45