From 0e19ef31d47d62a45a1b5e97d9e720958d0a8452 Mon Sep 17 00:00:00 2001 From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Mon, 14 Jun 2010 08:18:33 +0000 Subject: [PATCH] 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 --- modules/gui/src/gosty.cc | 31 ++++++++++++++++++++++++++++++- modules/gui/src/gosty_app.cc | 29 ----------------------------- modules/gui/src/gosty_app.hh | 2 -- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/modules/gui/src/gosty.cc b/modules/gui/src/gosty.cc index c97830089..574d2cffd 100644 --- a/modules/gui/src/gosty.cc +++ b/modules/gui/src/gosty.cc @@ -28,6 +28,7 @@ #include <ost/gui/module_config.hh> #include <ost/log.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_interpreter.hh> #include "gl_win.hh" @@ -124,6 +125,19 @@ int setup_resources(QApplication& app) 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() { // the order of these two calls is important! @@ -136,8 +150,23 @@ int init_python_interpreter() if(root == "") { 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); - py.RunCommand("from ost import *"); + py.RunCommand("from ost import *"); return 0; } diff --git a/modules/gui/src/gosty_app.cc b/modules/gui/src/gosty_app.cc index 91216a846..212cb1781 100644 --- a/modules/gui/src/gosty_app.cc +++ b/modules/gui/src/gosty_app.cc @@ -28,7 +28,6 @@ #include <ost/gui/python_shell/python_shell.hh> #include <ost/gui/gl_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/main_area.hh> @@ -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); } #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() { if (py_shell_==NULL) { py_shell_=new PythonShell; - this->SetupPyShellLogging(); py_shell_->SetDestroyOnClose(false); } return py_shell_; diff --git a/modules/gui/src/gosty_app.hh b/modules/gui/src/gosty_app.hh index f9ce1d851..bf92ec71e 100644 --- a/modules/gui/src/gosty_app.hh +++ b/modules/gui/src/gosty_app.hh @@ -142,8 +142,6 @@ public slots: /// \brief This slot must be called when the application is going to be terminated. void OnQuit(); private: - void SetupPyShellLogging(); - void ReadLoggerSettings(const QString& group_name, TextLogger* logger); GostyApp(); PythonShell* py_shell_; QWidget* w_py_shell_; -- GitLab