10 #include <pybind11/embed.h>
11 #include <pybind11/pybind11.h>
13 #include <QCoreApplication>
15 #include <QtConcurrent>
26 using namespace pybind11::literals;
45 virtual std::vector<Runtime::RegisteredPlugin::Action>
getActions() = 0;
54 std::vector<Runtime::RegisteredPlugin::Action>
getActions()
override
56 PYBIND11_OVERLOAD_PURE(std::vector<Runtime::RegisteredPlugin::Action>,
119 py::enum_<Qt::GlobalColor>(m,
"GlobalColor");
121 py::class_<QColor>(m,
"QColor");
123 py::class_<QListWidget, std::unique_ptr<QListWidget, py::nodelete>>(m,
"QListWidget");
125 py::class_<ccConsoleOutput>(m,
"ccConsoleOutput")
127 .def(py::init<const char *>(),
"prefix"_a)
132 py::class_<ListWidgetConsole>(m,
"ListWidgetConsole")
133 .def(py::init<QListWidget *, Qt::GlobalColor>())
134 .def(py::init<QListWidget *, QColor>())
135 .def(py::init<QListWidget *>())
146 py::class_<ecvMainAppInterface>(m,
"ecvMainAppInterface");
151 py::class_<Runtime::PythonPluginInterface, Runtime::PythonPluginTrampoline>(
152 m,
"PythonPluginInterface", R
"doc(
153 The base class for Python plugins.
155 Every plugin must inherit from this.
161 class MyPlugin(pycc.PythonPluginInterface):
169 This method. must be implemented
171 The method shall return the list of actions the plugin can perform.
172 Actions will get added to the context menu of the plugin.
174 The returned actions must be of type :class:`pycc.Action`.
177 It is not mandatory to implement this method.
179 When implemented, it shall return the icon that shall be used for the
182 see :class:`pycc.Action`.
185 py::class_<Runtime::RegisteredPlugin::Action>(m, "Action", R
"doc(
186 Represent an action of a plugin.
191 The name of the action
193 method of the plugin that performs the action
194 icon: optional, either bytes, or tuple[bytes, str] or str default to None
196 - If the type is bytes, then they shall the bytes of the icon itself.
197 - If the types is Tuple[bytes, str], then bytes shall be the bytes of the icon
198 itself and str the format, e.g. (some_bytes, "PNG")
199 - If str then it shall be the path to a file.
201 .def(py::init<QString, py::object, py::object>(),
204 "icon"_a = py::none());
206 m.def(
"ProcessEvents", []() { QCoreApplication::processEvents(); });
210 [](py::object callable, py::args args, py::kwargs kwargs)
214 QFutureWatcher<py::object> watcher;
215 QObject::connect(&watcher, &decltype(watcher)::finished, &loop, &decltype(loop)::quit);
216 QFuture<py::object> future =
217 QtConcurrent::run(
call_fn, stateReleaser.state, callable, args, kwargs);
218 watcher.setFuture(future);
221 return future.result();
226 [](py::object thread)
228 py::object isAliveMethod = thread.attr(
"is_alive");
229 thread.attr(
"start")();
230 while (isAliveMethod())
232 QCoreApplication::processEvents();
246 return py::cast(guiInstance);
253 py::return_value_policy::reference);
void define_ccGUIPythonInstance(py::module &)
void define_ccCommandLine(py::module &)
PYBIND11_EMBEDDED_MODULE(ccinternals, m)
py::object call_fn(PyThreadState *main_state, py::object callable, py::args args, py::kwargs kwargs)
Interface that 'class-style' PythonPlugin must implement to be loaded.
virtual py::object getIcon()
virtual ~PythonPluginInterface()=default
virtual std::vector< Runtime::RegisteredPlugin::Action > getActions()=0
std::vector< Runtime::RegisteredPlugin::Action > getActions() override
py::object getIcon() override
void write(const char *messagePart)
Main application interface (for plugins)
void setMainAppInterfaceInstance(ecvMainAppInterface *appInterface) noexcept(false)
void unsetMainAppInterfaceInstance() noexcept
Unsets the app interface pointer.
void setCmdLineInterfaceInstance(ccCommandLineInterface *cmdLine) noexcept
ccGuiPythonInstance * GetInstance() noexcept
ccCommandLineInterface * GetCmdLineInstance() noexcept
void unsetCmdLineInterfaceInstance() noexcept
Unsets the pointer to the cmdline app interface.
static ccGuiPythonInstance * s_pythonInstance
static ccCommandLineInterface * s_cmdLineInstance