Salome HOME
0022652: [CEA 1194] Redirect the traces from embedded Python console in a log file
[modules/gui.git] / src / SALOME_PYQT / SalomePyQt / SalomePyQt.cxx
index 46cffcc0ca965738d112c36d2fabf673618f68f8..75642bf48cc6c3bfe231bdb2af8d4748e37954e6 100644 (file)
@@ -50,6 +50,7 @@
 #include "SUIT_ResourceMgr.h"
 #include "SUIT_Session.h"
 #include "SUIT_Tools.h"
+#include "PyConsole_Console.h"
 
 #include <QAction>
 #include <QApplication>
@@ -3907,3 +3908,39 @@ int SalomePyQt::getObjectPosition( const QString& theEntry )
 {
   return ProcessEvent( new TGetObjectPositionEvent(theEntry) );
 }
+
+void SalomePyQt::startPyLog(const QString& theFileName)
+{
+  class TEvent: public SALOME_Event
+  {
+    QString myFileName;
+  public:
+    TEvent( const QString& theFileName ):
+      myFileName( theFileName ) {}
+    virtual void Execute() 
+    {
+      if ( getApplication() ) {
+       PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
+       if ( pyConsole ) pyConsole->startLog( myFileName );
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent( theFileName ) );
+}
+
+void SalomePyQt::stopPyLog()
+{
+  class TEvent: public SALOME_Event
+  {
+  public:
+    TEvent() {}
+    virtual void Execute() 
+    {
+      if ( getApplication() ) {
+       PyConsole_Console* pyConsole = getApplication()->pythonConsole( false );
+       if ( pyConsole ) pyConsole->stopLog();
+      }
+    }
+  };
+  ProcessVoidEvent( new TEvent() );
+}