Commit 2a804285 authored by Jan Möbius's avatar Jan Möbius

Added Documentation pages to the Python Widget

parent a868603e
//MIT License
//
//Copyright(c) 2017 Matthias Möller
//Copyright(c) 2017 Matthias Mller
//https://github.com/TinyTinni/PyLogHook
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
......
......@@ -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 {
......
......@@ -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
......
......@@ -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()
......
......@@ -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);
}
}
......
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