ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Runtime.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 <pybind11/pytypes.h>
13 
14 #include "../../wrapper/pycc/src/casters.h"
15 
16 namespace py = pybind11;
17 
18 namespace Runtime
19 {
20 
22 {
23  struct Action
24  {
25  Action() = delete;
26  Action(QString name, pybind11::object target, pybind11::object icon = pybind11::none())
27  : name(std::move(name)), target(std::move(target)), icon(std::move(icon))
28  {
29  }
30 
32  QString name{};
34  pybind11::object target{};
36  pybind11::object icon{};
37  };
38 
40  static RegisteredPlugin InstanciatePlugin(pybind11::object class_type,
41  const QString &name) noexcept(false)
42  {
43  pybind11::object instance = class_type();
44  py::list pyActions = instance.attr("getActions")();
45  std::vector<Action> actions;
46  actions.reserve(pyActions.size());
47 
48  for (const py::handle &handle : pyActions)
49  {
50  actions.push_back(handle.cast<Runtime::RegisteredPlugin::Action>());
51  }
52 
53  const pybind11::object mainIcon = instance.attr("getIcon")();
54 
55  return {name, instance, actions, mainIcon};
56  }
57 
60  static RegisteredPlugin InstanciatePlugin(pybind11::object class_type) noexcept(false)
61  {
62  QString name = class_type.attr("__name__").cast<QString>();
63  return InstanciatePlugin(class_type, name);
64  }
65 
66  QString name;
67  pybind11::object instance;
68  std::vector<Action> actions;
69  pybind11::object mainIcon;
70 };
71 
74 void setMainAppInterfaceInstance(ecvMainAppInterface *appInterface) noexcept(false);
76 void unsetMainAppInterfaceInstance() noexcept;
77 
82 void unsetCmdLineInterfaceInstance() noexcept;
83 
84 } // namespace Runtime
Runtime::PythonPluginTrampoline::getActions
std::vector< Runtime::RegisteredPlugin::Action > getActions() override
Definition: Runtime.cpp:54
Runtime.h
Runtime::GetCmdLineInstance
ccCommandLineInterface * GetCmdLineInstance() noexcept
Definition: Runtime.cpp:77
ListWidgetConsole::flush
void flush() const
Definition: Consoles.h:145
PYBIND11_EMBEDDED_MODULE
PYBIND11_EMBEDDED_MODULE(ccinternals, m)
Definition: Runtime.cpp:117
call_fn
py::object call_fn(PyThreadState *main_state, py::object callable, py::args args, py::kwargs kwargs)
Definition: Threading.h:79
Runtime::RegisteredPlugin::mainIcon
pybind11::object mainIcon
Definition: Runtime.h:69
Runtime::PythonPluginTrampoline::getIcon
py::object getIcon() override
Definition: Runtime.cpp:61
Runtime::PythonPluginTrampoline::PythonPluginTrampoline
PythonPluginTrampoline()
Definition: Runtime.cpp:52
Runtime::RegisteredPlugin::instance
pybind11::object instance
Definition: Runtime.h:67
Runtime::GetInstance
ccGuiPythonInstance * GetInstance() noexcept
Definition: Runtime.cpp:72
ecvMainAppInterface.h
ecvCommandLineInterface.h
ccConsoleOutput::flush
void flush() const
Definition: Consoles.h:99
Runtime::unsetMainAppInterfaceInstance
void unsetMainAppInterfaceInstance() noexcept
Unsets the app interface pointer.
Definition: Runtime.cpp:90
Runtime::setMainAppInterfaceInstance
void setMainAppInterfaceInstance(ecvMainAppInterface *appInterface) noexcept(false)
Definition: Runtime.cpp:82
ecvMainAppInterface
Main application interface (for plugins)
Definition: ecvMainAppInterface.h:24
ccGuiPythonInstance
Definition: ccGuiPythonInstance.h:26
Runtime::RegisteredPlugin::Action::name
QString name
Name to be displayed in the UI.
Definition: Runtime.h:32
Runtime::PythonPluginInterface::getIcon
virtual py::object getIcon()
Definition: Runtime.cpp:37
define_ccGUIPythonInstance
void define_ccGUIPythonInstance(py::module &)
Definition: ccGuiPythonInstance.cpp:201
ListWidgetConsole::write
void write(const char *messagePart)
Definition: Consoles.h:129
Threading.h
Runtime::PythonPluginInterface
Interface that 'class-style' PythonPlugin must implement to be loaded.
Definition: Runtime.cpp:32
Runtime::RegisteredPlugin::InstanciatePlugin
static RegisteredPlugin InstanciatePlugin(pybind11::object class_type) noexcept(false)
Definition: Runtime.h:60
ListWidgetConsole::isatty
bool isatty() const
Definition: Consoles.h:140
PyThreadStateReleaser
Definition: Threading.h:37
ccCommandLineInterface
Command line interface.
Definition: ecvCommandLineInterface.h:112
Runtime::s_pythonInstance
static ccGuiPythonInstance * s_pythonInstance
Definition: Runtime.cpp:68
Runtime::RegisteredPlugin::Action::icon
pybind11::object icon
Optional path or (bytes, str) where str is the format.
Definition: Runtime.h:36
Runtime::unsetCmdLineInterfaceInstance
void unsetCmdLineInterfaceInstance() noexcept
Unsets the pointer to the cmdline app interface.
Definition: Runtime.cpp:107
Runtime::s_cmdLineInstance
static ccCommandLineInterface * s_cmdLineInstance
Definition: Runtime.cpp:70
ccConsoleOutput::write
void write(const char *messagePart)
Definition: Consoles.h:82
Runtime::PythonPluginInterface::getActions
virtual std::vector< Runtime::RegisteredPlugin::Action > getActions()=0
Runtime::RegisteredPlugin::Action::Action
Action()=delete
Runtime::RegisteredPlugin::InstanciatePlugin
static RegisteredPlugin InstanciatePlugin(pybind11::object class_type, const QString &name) noexcept(false)
Instanciate a plugin with a known name.
Definition: Runtime.h:40
std
Definition: Eigen.h:85
ccGuiPythonInstance.h
Runtime::RegisteredPlugin::Action::target
pybind11::object target
The target python function (or method)
Definition: Runtime.h:34
Runtime::RegisteredPlugin::name
QString name
Definition: Runtime.h:66
Runtime::RegisteredPlugin::Action
Definition: Runtime.h:23
pybind11
Definition: ccGuiPythonInstance.h:15
Runtime::PythonPluginTrampoline
Definition: Runtime.cpp:49
Utils::module
static double module(T *vector)
Definition: utils.h:105
Runtime::RegisteredPlugin::Action::Action
Action(QString name, pybind11::object target, pybind11::object icon=pybind11::none())
Definition: Runtime.h:26
ccConsoleOutput::isatty
bool isatty() const
Definition: Consoles.h:94
Runtime::setCmdLineInterfaceInstance
void setCmdLineInterfaceInstance(ccCommandLineInterface *cmdLine) noexcept
Definition: Runtime.cpp:99
Runtime
Definition: Runtime.cpp:28
define_ccCommandLine
void define_ccCommandLine(py::module &)
Definition: ccCommandLine.cpp:23
Runtime::RegisteredPlugin
Definition: Runtime.h:21
Consoles.h
Runtime::RegisteredPlugin::actions
std::vector< Action > actions
Definition: Runtime.h:68