Commit 5b390585 authored by Jan Möbius's avatar Jan Möbius

Correctly log output from python interpreter via core to widget, file and console

parent 355f0b97
......@@ -87,6 +87,10 @@
#include <ACG/Scenegraph/MaterialNode.hh>
#include <ACG/Scenegraph/SeparatorNode.hh>
#ifdef PYTHON_ENABLED
#include <PythonInterpreter/PythonInterpreter.hh>
#endif
#define WIDGET_HEIGHT 800
#define WIDGET_WIDTH 800
......@@ -694,6 +698,33 @@ Core::init() {
OpenFlipper::Options::finishedStartup();
QTimer::singleShot(100, this, SLOT(slotExecuteAfterStartup()));
// Initialize and connect the logging of the Python interpreter to the core logging facilities
#ifdef PYTHON_ENABLED
PythonInterpreter* interpreter = PythonInterpreter::getInstance();
PluginLogger* pythonLog = new PluginLogger("PythonInterpreter");
loggers_.push_back(pythonLog);
// Connect input from python interpreter to wrapping logger
connect(interpreter,SIGNAL(log(Logtype,QString)),pythonLog,SLOT(slotLog(Logtype,QString)),Qt::DirectConnection);
// connect output to file logger
connect(pythonLog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
// Connect output to the Master loggers
if ( OpenFlipper::Options::gui())
connect(pythonLog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
connect(pythonLog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
std::cerr << "Connected logger!!! " << std::endl;
#endif
}
......
......@@ -419,6 +419,11 @@ void Core::executePythonScriptFile(QString _filename){
if (!file.exists()) {
emit scriptLog("Unable to load file " + _filename + " as python script. File not found!");
// Fail when in batch mode
if (OpenFlipper::Options::nogui())
exit(1);
return;
}
......@@ -428,9 +433,6 @@ void Core::executePythonScriptFile(QString _filename){
QString script = in.readAll();
std::cerr << "Script : " << std::endl;
std::cerr << script.toStdString() << std::endl;
executePythonScript(script);
}
......
......@@ -87,7 +87,7 @@ PythonInterpreter* PythonInterpreter::getInstance() {
}
PythonInterpreter::PythonInterpreter() :
externalLogging_(false)
externalLogging_(true)
{
}
......@@ -320,8 +320,7 @@ QString PythonInterpreter::runScriptOutput(QString _script) {
void PythonInterpreter::pyOutput(const char* w)
{
if (externalLogging_) {
std::cerr << "Python output: " << w << std::endl;
Q_EMIT log(LOGOUT, QString(w));
emit log(LOGOUT, QString(w));
} else {
LogOut += QString::fromUtf8(w);
}
......@@ -330,8 +329,7 @@ void PythonInterpreter::pyOutput(const char* w)
void PythonInterpreter::pyError(const char* w)
{
if (externalLogging_) {
std::cerr << "Python error: " << w << std::endl;
Q_EMIT log(LOGERR, QString(w));
emit log(LOGERR, QString(w));
} else {
LogErr += QString::fromUtf8(w);
}
......
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