diff --git a/PythonInterpreter/PyLogHook.h b/PythonInterpreter/PyLogHook.h index 2574c01ad8da204346e6f38479a9b5b5221626fd..f3416d0fa49527a59fea7b6c52b24cf761f86b2f 100644 --- a/PythonInterpreter/PyLogHook.h +++ b/PythonInterpreter/PyLogHook.h @@ -1,6 +1,6 @@ //MIT License // -//Copyright(c) 2017 Matthias Möller +//Copyright(c) 2017 Matthias M�ller //https://github.com/TinyTinni/PyLogHook // //Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/PythonInterpreter/PythonInterpreter.cc b/PythonInterpreter/PythonInterpreter.cc index c2a47e17f2f31c677c6113e762459c87d6a7a1e4..e2263051288033215b842904fdce1d9233f89fa4 100644 --- a/PythonInterpreter/PythonInterpreter.cc +++ b/PythonInterpreter/PythonInterpreter.cc @@ -80,7 +80,9 @@ PythonInterpreter* PythonInterpreter::getInstance() { } -PythonInterpreter::PythonInterpreter() { +PythonInterpreter::PythonInterpreter() : + externalLogging_(false) +{ } @@ -213,19 +215,37 @@ bool PythonInterpreter::runScript(QString _script) { return result; } +QString PythonInterpreter::runScriptOutput(QString _script) { + LogOut.clear(); + LogErr.clear(); + externalLogging_ = false; + runScript(_script); + externalLogging_ = true; + return LogOut + LogErr; + LogOut.clear(); + LogErr.clear(); +} // Python callback functions void PythonInterpreter::pyOutput(const char* w) { - std::cerr << "Python output:\n " << w << std::endl; - Q_EMIT log(LOGOUT, QString(w)); + if (externalLogging_) { + std::cerr << "Python output:\n " << w << std::endl; + Q_EMIT log(LOGOUT, QString(w)); + } else { + LogOut += QString::fromUtf8(w); + } } void PythonInterpreter::pyError(const char* w) { - std::cerr << "Python error:\n " << w << std::endl; - Q_EMIT log(LOGERR, QString(w)); + if (externalLogging_) { + std::cerr << "Python error:\n " << w << std::endl; + Q_EMIT log(LOGERR, QString(w)); + } else { + LogErr += QString::fromUtf8(w); + } } namespace pybind11 { namespace detail { diff --git a/PythonInterpreter/PythonInterpreter.hh b/PythonInterpreter/PythonInterpreter.hh index 05382ac76c650000af7be72e4cdb61b6b02b374f..1b6b2a070a59056ae2bf5d3f55dc885668fcde7a 100644 --- a/PythonInterpreter/PythonInterpreter.hh +++ b/PythonInterpreter/PythonInterpreter.hh @@ -70,8 +70,21 @@ public: */ static PythonInterpreter* getInstance(); + /** \brief Run a script. Output is passed to the standard logging facilities of OpenFlipper + * + * @param _script + * @return + */ bool runScript(QString _script); + /** \ brief run a script and return the output as a QString + * + * @param _script + * @return + */ + QString runScriptOutput(QString _script); + + private: /** \brief private constructor because of singleton @@ -105,6 +118,10 @@ private: void pyError(const char* w); +private: + bool externalLogging_; + QString LogErr; + QString LogOut; }; /** \brief give Core pointer to PythonInterpreter for exporting of Core functionality to python diff --git a/cmake/plugin.cmake b/cmake/plugin.cmake index 5138162b38fbf1129f9ca874943892da5bc463b5..9f4217823386c7b201843928103aca29eb374d87 100755 --- a/cmake/plugin.cmake +++ b/cmake/plugin.cmake @@ -647,7 +647,6 @@ function (_build_openflipper_plugin plugin) acg_append_files (sources "*.cc" PythonInterface) link_directories(${Python3_LIBRARY_DIRS}) include_directories( ${Python3_INCLUDE_DIRS} ) - add_definitions(-DPYTHONINTERFACE_ENABLED) endif() endif() @@ -676,7 +675,7 @@ function (_build_openflipper_plugin plugin) # Link plugin against python if possible if ( ${_PLUGIN}_PYTHONINTERFACE AND NOT DISABLE_OPENFLIPPER_PYTHON_SYSTEM ) if(PYTHON3_FOUND) - target_link_libraries (Plugin-${plugin} Python3::Python ) + target_link_libraries (Plugin-${plugin} pybind11::module pybind11::embed Python3::Python ) endif() endif() diff --git a/widgets/pythonWidget/pythonWidget.cc b/widgets/pythonWidget/pythonWidget.cc index 2f103ad460509ae18518e022b40e7d183f35d206..6cf60dbc6bea5d1bc5c3fceea93a774102fcf13b 100644 --- a/widgets/pythonWidget/pythonWidget.cc +++ b/widgets/pythonWidget/pythonWidget.cc @@ -89,6 +89,23 @@ PythonWidget::PythonWidget(QWidget *parent ) pythonInfo->append(" " + pythonPlugins[i] ); } + PythonInterpreter* interpreter = PythonInterpreter::getInstance(); + + QTextEdit* coreInfo = new QTextEdit( infoTab ); + infoTab->addTab(coreInfo,"Core"); + QString coreDoc = interpreter->runScriptOutput("import pydoc ;import openflipper;html = pydoc.HTMLDoc();object, name = pydoc.resolve(openflipper);page = html.page(pydoc.describe(object), html.document(object, name));print(page)"); + coreInfo->setHtml(coreDoc); + + // Collect all Python Documentation for the OpenFlipper Plugin Modules + for ( int i = 0 ; i < pythonPlugins.size() ; ++i ) { + QTextEdit* edit = new QTextEdit( infoTab ); + infoTab->addTab(edit,pythonPlugins[i]); + QString data = interpreter->runScriptOutput("import pydoc ;import "+pythonPlugins[i]+";html = pydoc.HTMLDoc();object, name = pydoc.resolve("+pythonPlugins[i]+");page = html.page(pydoc.describe(object), html.document(object, name));print(page)"); + edit->setHtml(data); + } + + + }