Skip to content
Snippets Groups Projects
Commit 0e19ef31 authored by marco's avatar marco
Browse files

move logger initialisation to an earlier time point

Syntax errors can no longer screw up logging of errors.

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2389 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 42a28bcf
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <ost/gui/module_config.hh> #include <ost/gui/module_config.hh>
#include <ost/log.hh> #include <ost/log.hh>
#include <ost/platform.hh> #include <ost/platform.hh>
#include <ost/gui/python_shell/text_logger.hh>
#include <ost/gui/python_shell/python_shell.hh> #include <ost/gui/python_shell/python_shell.hh>
#include <ost/gui/python_shell/python_interpreter.hh> #include <ost/gui/python_shell/python_interpreter.hh>
#include "gl_win.hh" #include "gl_win.hh"
...@@ -124,6 +125,19 @@ int setup_resources(QApplication& app) ...@@ -124,6 +125,19 @@ int setup_resources(QApplication& app)
return 0; return 0;
} }
void read_logger_settings(const QString& group_name, TextLogger* logger)
{
QSettings settings;
settings.beginGroup("logging");
settings.beginGroup(group_name);
logger->SetCodeLogging(settings.value("log_code",QVariant(false)).toBool());
logger->SetOutputLogging(settings.value("log_output",QVariant(true)).toBool());
logger->SetErrorLogging(settings.value("log_error",QVariant(true)).toBool());
settings.endGroup();
settings.endGroup();
}
int init_python_interpreter() int init_python_interpreter()
{ {
// the order of these two calls is important! // the order of these two calls is important!
...@@ -136,8 +150,23 @@ int init_python_interpreter() ...@@ -136,8 +150,23 @@ int init_python_interpreter()
if(root == "") { if(root == "") {
return -1; return -1;
} }
// setup python shell logging
TextLogger* console_logger=new TextLogger(stdout);
read_logger_settings("console", console_logger);
if (console_logger->GetErrorLogging()) {
QObject::connect(&PythonInterpreter::Instance(),
SIGNAL(ErrorOutput(unsigned int, const QString &)),
console_logger,
SLOT(AppendOutput(unsigned int, const QString &)));
}
if (console_logger->GetOutputLogging()) {
QObject::connect(&PythonInterpreter::Instance(),
SIGNAL(Output(unsigned int, const QString &)),
console_logger,
SLOT(AppendOutput(unsigned int, const QString &)));
}
setup_python_search_path(root, py); setup_python_search_path(root, py);
py.RunCommand("from ost import *"); py.RunCommand("from ost import *");
return 0; return 0;
} }
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include <ost/gui/python_shell/python_shell.hh> #include <ost/gui/python_shell/python_shell.hh>
#include <ost/gui/gl_win.hh> #include <ost/gui/gl_win.hh>
#include <ost/gui/tools/tool_options_win.hh> #include <ost/gui/tools/tool_options_win.hh>
#include <ost/gui/python_shell/text_logger.hh>
#include <ost/gui/perspective.hh> #include <ost/gui/perspective.hh>
#include <ost/gui/main_area.hh> #include <ost/gui/main_area.hh>
...@@ -110,39 +109,11 @@ ost::img::gui::DataViewer* GostyApp::CreateDataViewer(const ost::img::Data& d, c ...@@ -110,39 +109,11 @@ ost::img::gui::DataViewer* GostyApp::CreateDataViewer(const ost::img::Data& d, c
return new ost::img::gui::DataViewer(main_,d,name); return new ost::img::gui::DataViewer(main_,d,name);
} }
#endif #endif
void GostyApp::ReadLoggerSettings(const QString& group_name, TextLogger* logger)
{
QSettings settings;
settings.beginGroup("logging");
settings.beginGroup(group_name);
logger->SetCodeLogging(settings.value("log_code",QVariant(false)).toBool());
logger->SetOutputLogging(settings.value("log_output",QVariant(true)).toBool());
logger->SetErrorLogging(settings.value("log_error",QVariant(true)).toBool());
settings.endGroup();
settings.endGroup();
}
void GostyApp::SetupPyShellLogging()
{
TextLogger* console_logger=new TextLogger(stdout);
this->ReadLoggerSettings("console", console_logger);
if (console_logger->GetErrorLogging()) {
connect(&PythonInterpreter::Instance(), SIGNAL(ErrorOutput(unsigned int, const QString &)),
console_logger,SLOT(AppendOutput(unsigned int, const QString &)));
}
if (console_logger->GetOutputLogging()) {
connect(&PythonInterpreter::Instance(), SIGNAL(Output(unsigned int, const QString &)),
console_logger,SLOT(AppendOutput(unsigned int, const QString &)));
}
// TODO: Setup file logging
}
PythonShell* GostyApp::GetPyShell() PythonShell* GostyApp::GetPyShell()
{ {
if (py_shell_==NULL) { if (py_shell_==NULL) {
py_shell_=new PythonShell; py_shell_=new PythonShell;
this->SetupPyShellLogging();
py_shell_->SetDestroyOnClose(false); py_shell_->SetDestroyOnClose(false);
} }
return py_shell_; return py_shell_;
......
...@@ -142,8 +142,6 @@ public slots: ...@@ -142,8 +142,6 @@ public slots:
/// \brief This slot must be called when the application is going to be terminated. /// \brief This slot must be called when the application is going to be terminated.
void OnQuit(); void OnQuit();
private: private:
void SetupPyShellLogging();
void ReadLoggerSettings(const QString& group_name, TextLogger* logger);
GostyApp(); GostyApp();
PythonShell* py_shell_; PythonShell* py_shell_;
QWidget* w_py_shell_; QWidget* w_py_shell_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment