Commit e950de59 authored by Jan Möbius's avatar Jan Möbius

Automaticcally create instance of all plugins available to python interface

parent a9350f69
......@@ -95,7 +95,7 @@ class PythonInterface {
namespace py = pybind11;
PYBIND11_EMBEDDED_MODULE(yourPlugin, m) { // yourPlugin will will be the module name in Python ( ... import yourPlugin )
PYBIND11_EMBEDDED_MODULE(YourPlugin, m) { // yourPlugin will will be the module name in Python ( ... import yourPlugin )
QObject* pluginPointer = getPluginPointer("Your"); // This will retrieve your plugin instance pointer. The name is the plugin name set via the name() function.
......
......@@ -219,7 +219,22 @@ void PythonInterpreter::resetInterpreter()
bool PythonInterpreter::runScript(QString _script) {
#ifdef PYTHON_DEBUG
std::cerr << "runScript" << std::endl;
#endif
//============================================================
// Prepend module instance getter to the script
//============================================================
_script.prepend("core = openflipper.Core()\n");
QStringList pythonPlugins = getPythonPlugins();
for ( int i = 0 ; i < pythonPlugins.size() ; ++i ) {
QString import = pythonPlugins[i].toLower() + " = " + pythonPlugins[i] + "." + pythonPlugins[i] + "()\n";
_script.prepend(import);
}
// init
try
......@@ -309,7 +324,7 @@ PYBIND11_EMBEDDED_MODULE(openflipper, m) {
// Export our core. Make sure that the c++ worlds core objet is not deleted if
// the python side gets deleted!!
py::class_<Core,std::unique_ptr<Core, py::nodelete>> core(m, "core");
py::class_<Core,std::unique_ptr<Core, py::nodelete>> core(m, "Core");
// On the c++ side we will just return the existing core instance
// and prevent the system to recreate a new core as we need
......
......@@ -83,12 +83,15 @@ PythonWidget::PythonWidget(QWidget *parent )
#ifdef PYTHON_ENABLED
pythonInfo->setAlignment(Qt::AlignLeft);
pythonInfo->append("Plugins with Python support ( The plugin modules will be imported with their name shown below.):\n");
pythonInfo->append("Each module is automatically loaded by the core with the name given below.");
pythonInfo->append("An instance for each plugin is automatically generated with a lower case name of the module (E.g. the plugin Move will provide an instance move).\n");
pythonInfo->append("Available plugins with Python support:\n");
QStringList pythonPlugins = getPythonPlugins();
for ( int i = 0 ; i < pythonPlugins.size() ; ++i ) {
pythonInfo->append(" " + pythonPlugins[i] );
pythonInfo->append("Module " + pythonPlugins[i] + "\t\t providing instance " + pythonPlugins[i].toLower());
}
PythonInterpreter* interpreter = PythonInterpreter::getInstance();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment