From 42a28bcfc3e618b19943d5e3b0d67950fa0f8fa2 Mon Sep 17 00:00:00 2001
From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Sat, 12 Jun 2010 09:27:16 +0000
Subject: [PATCH] log python output to console

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2388 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 modules/gui/src/gosty_app.cc                | 16 +++++++++++-----
 modules/gui/src/python_shell/text_logger.cc | 11 +----------
 modules/gui/src/python_shell/text_logger.hh |  2 +-
 3 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/modules/gui/src/gosty_app.cc b/modules/gui/src/gosty_app.cc
index 7090e7449..91216a846 100644
--- a/modules/gui/src/gosty_app.cc
+++ b/modules/gui/src/gosty_app.cc
@@ -115,7 +115,7 @@ void GostyApp::ReadLoggerSettings(const QString& group_name, TextLogger* logger)
 {
   QSettings settings;
   settings.beginGroup("logging");
-  settings.beginGroup(group_name);
+  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());
@@ -127,8 +127,14 @@ void GostyApp::SetupPyShellLogging()
 {
   TextLogger* console_logger=new TextLogger(stdout);
   this->ReadLoggerSettings("console", console_logger);
-  // get log from Interpreter instead of shell
-  //py_shell_->AddLogger(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
 }
 
@@ -136,8 +142,8 @@ PythonShell* GostyApp::GetPyShell()
 {
   if (py_shell_==NULL) {
     py_shell_=new PythonShell;
-    this->SetupPyShellLogging();             
-    py_shell_->SetDestroyOnClose(false);                 
+    this->SetupPyShellLogging();
+    py_shell_->SetDestroyOnClose(false);
   }
   return py_shell_;
 }
diff --git a/modules/gui/src/python_shell/text_logger.cc b/modules/gui/src/python_shell/text_logger.cc
index ef0dee578..04123b9a7 100644
--- a/modules/gui/src/python_shell/text_logger.cc
+++ b/modules/gui/src/python_shell/text_logger.cc
@@ -70,18 +70,9 @@ void TextLogger::AppendCode(const QString& text)
   operator<<('\n');
   flush();
 }
-void TextLogger::AppendOutput(int status,const QString& text)
+void TextLogger::AppendOutput(unsigned int id,const QString& text)
 {
-  if (text=="\n") {
-    return;
-  }  
-  if(!((log_output_ && status==STATUS_OK) || (log_error_ && status==STATUS_ERROR))
-     || text.size()==0){
-    return;
-  }
-
   operator<<(text);
-  operator<<('\n');
   flush();
 }
 void TextLogger::SetCodeLogging(bool flag)
diff --git a/modules/gui/src/python_shell/text_logger.hh b/modules/gui/src/python_shell/text_logger.hh
index 1be25f652..9e46fc740 100644
--- a/modules/gui/src/python_shell/text_logger.hh
+++ b/modules/gui/src/python_shell/text_logger.hh
@@ -49,7 +49,7 @@ public:
   
 public slots:
   void AppendCode(const QString& text); 
-  void AppendOutput(int status,const QString& text); 
+  void AppendOutput(unsigned int id,const QString& text); 
   
 protected:
   bool log_code_;
-- 
GitLab