ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
PythonPlugin.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 #include "PythonConfig.h"
11 #include "PythonInterpreter.h"
12 #include "PythonPluginManager.h"
13 #include "ecvStdPluginInterface.h"
14 
15 #include <iostream>
16 #include <map>
17 #include <vector>
18 
19 class QListWidget;
20 class PythonEditor;
21 class PythonRepl;
22 class FileRunner;
23 class PackageManager;
26 
28 class PythonPlugin final : public QObject, public ccStdPluginInterface
29 {
30  Q_OBJECT
32 
33  Q_PLUGIN_METADATA(IID "ecvcorp.cloudviewer.plugin.PythonRuntime" FILE "../info.json")
34 
35  public:
36  explicit PythonPlugin(QObject *parent = nullptr);
37 
38  QList<QAction *> getActions() override;
39 
42  void registerCommands(ccCommandLineInterface *cmd) override;
43 
44  void setMainAppInterface(ecvMainAppInterface *app) override;
45 
46  void stop() override;
47 
48  PythonPlugin(const PythonPlugin &) = delete;
49  PythonPlugin(PythonPlugin &&) = delete;
50  PythonPlugin &operator=(const PythonPlugin &) = delete;
52  ~PythonPlugin() noexcept override;
53 
54  private:
55  void finalizeInterpreter();
56  void showRepl();
57  void showEditor() const;
58  void showAboutDialog() const;
59  void showFileRunner() const;
60  void showPackageManager();
61  void showPythonActionLauncher() const;
62  void showSettings() const;
63  static void showDocumentation();
64 
65  // Script list function
66  void addScriptAction();
67  void addScript(QString path);
68  void executeScript(QString path);
69  void removeScript(QString name, QAction *self);
70 
71  void populatePluginSubMenu();
72 
73  void handlePluginActionClicked(bool checked);
74  void handlePythonExecutionStarted();
75  void handlePythonExecutionFinished();
76 
77  PythonConfig m_config{};
78  PythonInterpreter m_interp;
79  PythonPluginManager m_pluginManager;
80 
81  PythonRuntimeSettings *m_settings{nullptr};
82  PythonRepl *m_repl{nullptr};
83  PythonEditor *m_editor{nullptr};
84  FileRunner *m_fileRunner{nullptr};
85  PackageManager *m_packageManager{nullptr};
86  PythonActionLauncher *m_actionLauncher{nullptr};
87 
89  QAction *m_showEditor{nullptr};
90  QAction *m_showRepl{nullptr};
91  QAction *m_showDoc{nullptr};
92  QAction *m_showFileRunner{nullptr};
93  QAction *m_showAboutDialog{nullptr};
94  QAction *m_showPackageManager{nullptr};
95  QAction *m_showActionLauncher{nullptr};
96  QAction *m_showSettings{nullptr};
97 
99  QMenu *m_drawScriptRegister{nullptr};
100  QMenu *m_pluginsMenu{nullptr};
101 
103  std::map<const QAction *, const Runtime::RegisteredPlugin::Action *> m_pluginActions;
104 
106  QAction *m_addScript{nullptr};
107  QMenu *m_removeScript{nullptr};
108  std::map<QString, QAction *> m_scriptList;
109  QStringList m_savedPath;
110  QString m_saveFilePath;
111 };
std::string name
"Entry point" of the plugin
Definition: PythonPlugin.h:29
void setMainAppInterface(ecvMainAppInterface *app) override
Sets application entry point.
QList< QAction * > getActions() override
Get a list of actions for this plugin.
void stop() override
Stops the plugin.
PythonPlugin(QObject *parent=nullptr)
PythonPlugin & operator=(const PythonPlugin &)=delete
void registerCommands(ccCommandLineInterface *cmd) override
~PythonPlugin() noexcept override
PythonPlugin(PythonPlugin &&)=delete
PythonPlugin(const PythonPlugin &)=delete
PythonPlugin & operator=(PythonPlugin &&)=delete
Homemade REPL (Read Print Eval Loop)
Definition: PythonRepl.h:59
Command line interface.
Standard ECV plugin interface.
Standard ECV plugin interface.
Main application interface (for plugins)
static const std::string path
Definition: PointCloud.cpp:59