The Python interface enables OpenFlipper to export plugin functions to the integrated python interpreter of OpenFlipper. Only a few steps are required to export functions in a plugin.
- Tell cmake, that your plugin supports the Python Interface. In your CMakeLists.txt add the Keyword PYTHONINTERFACE. E.g. :
include (plugin)
openflipper_plugin (PYTHONINTERFACE )
- Add the corresponding includes and calls to your plugin header:
- Add a subdirectory called PythonInterface to your plugin directory
- In this directory create a file called Python.cc with contents similar to the following Code:
#include <pybind11/include/pybind11/pybind11.h>
#include <pybind11/include/pybind11/embed.h>
#include <YourPlugin.hh>
#include <OpenFlipper/BasePlugin/PythonFunctions.hh>
PYBIND11_EMBEDDED_MODULE(YourPlugin, m) {
QObject* pluginPointer = getPluginPointer("Your");
py::class_< YourPlugin,std::unique_ptr<YourPlugin, py::nodelete> > plugin(m, "Your");
plugin.def(py::init([&pluginPointer]() { return qobject_cast<YourPlugin*>(pluginPointer); }));
plugin.def("viewAll", static_cast<void (YourPlugin::*)()>(&YourPlugin::viewAll),"Change View in all viewers to view whole scene");
plugin.def(
"viewAll",
static_cast<void (
ViewControlPlugin::*)(
int)
>(&YourPlugin::viewAll),
"Change View in given viewer to view whole scene",py::arg(
"Id of the viewer which should be switched") );
}