Salome HOME
0022652: [CEA 1194] Redirect the traces from embedded Python console in a log file
authorvsr <vsr@opencascade.com>
Tue, 23 Sep 2014 13:50:17 +0000 (17:50 +0400)
committervsr <vsr@opencascade.com>
Tue, 23 Sep 2014 13:50:17 +0000 (17:50 +0400)
Additional changes:
- Add functions to start/stop trace from embedded Python console to the Python API (SalomePyQt module)

src/PyConsole/PyConsole_Console.cxx
src/PyConsole/PyConsole_Console.h
src/PyConsole/PyConsole_Editor.cxx
src/PyConsole/PyConsole_Editor.h
src/SALOME_PYQT/SalomePyQt/CMakeLists.txt
src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx
src/SALOME_PYQT/SalomePyQt/SalomePyQt.h
src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip

index f386ebfdb6ee77588d7a0af85fcc0f2df911ce49..a3991bf88a8885103e52a684776b8716e737f344 100644 (file)
@@ -350,6 +350,23 @@ void PyConsole_Console::updateActions()
   myActions[SelectAllId]->setEnabled( !myEditor->document()->isEmpty() );
 }
 
+/*!
+  \brief Start python trace logging
+  \param fileName the path to the log file
+*/
+void PyConsole_Console::startLog( const QString& fileName )
+{
+  myEditor->startLog( fileName );
+}
+
+/*!
+  \brief Stop python trace logging
+*/
+void PyConsole_Console::stopLog()
+{
+  myEditor->stopLog();
+}
+
 /**
  * Similar to constructor of the base class but using enhanced objects.
  * TODO: this should really be done in a factory to avoid code duplication.
index de909960de54c4c6a1e27a49929abe350436917a..54442c2cd9c162cf2ed847410406789064866075 100644 (file)
@@ -84,6 +84,9 @@ public:
   void                setMenuActions( const int );
   int                 menuActions() const;
 
+  void                startLog( const QString& );
+  void                stopLog();
+
 protected:
   void                createActions();
   void                updateActions();
index be9ba6b981c72efc0380d4e31dba87c2d20df411..66aaf5b9b72b12f3e4cf30ad04dbc512a2cfa989 100644 (file)
@@ -1151,7 +1151,7 @@ void PyConsole_Editor::dump()
   }
 }
 /*!
-  \brief "Save log" operation.
+  \brief "Start log" operation.
  */
 void PyConsole_Editor::startLog()
 {
@@ -1163,10 +1163,7 @@ void PyConsole_Editor::startLog()
                                                  aFilters, tr( "TOT_SAVE_PYLOG" ),
                                                  false, true );
     if ( !fileName.isEmpty() ) {
-      QFile file( fileName );
-      if ( file.open( QFile::WriteOnly ) ) {
-       file.close();
-       myLogFile = fileName;
+      if ( startLog( fileName ) ) {
        break;
       }
       else {
@@ -1181,6 +1178,24 @@ void PyConsole_Editor::startLog()
   }
 }
 
+/*!
+  \brief Start python trace logging
+  \param fileName the path to the log file
+  \sa stopLog()
+ */
+bool PyConsole_Editor::startLog( const QString& fileName )
+{
+  bool ok = false;
+  if ( !fileName.isEmpty() ) {
+    QFile file( fileName );
+    if ( file.open( QFile::WriteOnly ) ) {
+      file.close();
+      myLogFile = fileName;
+      ok = true;
+    }
+  }
+  return ok;
+}
 
 /*!
   \brief "Stop log" operation.
index 650712a8f52c5db012996b5ad79016d4640d5a16..c939ef1b7da3e9fd78f947738427b11222426a42 100644 (file)
@@ -69,6 +69,7 @@ public slots:
     void           handleReturn();
     void           onPyInterpChanged( PyConsole_Interp* );
     void           dump();
+    bool           startLog( const QString& );
     void           startLog();
     void           stopLog();
     void           putLog( const QString& );
index 692883aac15a6d27a3e49a917d4082a23ff5ab23..540c27514ec55ce3f4c40b9fec443d482e0fcdfa 100755 (executable)
@@ -42,6 +42,7 @@ INCLUDE_DIRECTORIES(
   ${PROJECT_SOURCE_DIR}/src/ObjBrowser
   ${PROJECT_SOURCE_DIR}/src/Plot2d
   ${PROJECT_SOURCE_DIR}/src/PyInterp
+  ${PROJECT_SOURCE_DIR}/src/PyConsole
   ${PROJECT_SOURCE_DIR}/src/Qtx
   ${PROJECT_SOURCE_DIR}/src/SALOME_PYQT/SALOME_PYQT_GUILight
   ${PROJECT_SOURCE_DIR}/src/STD
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() );
+}
index 2747c0f7c1a271aa71c09820bf3862eed0d7ef63..68be1fafcdec7d4e9629dd94d6fab7cbaf0f6510 100644 (file)
@@ -304,6 +304,9 @@ public:
   static QString           getSetting      ( const QString& );
 
   static void              removeChild( const QString& = QString() );
+
+  static void              startPyLog(const QString&);
+  static void              stopPyLog();
 };
 
 #endif // SALOME_PYQT_H
index 4da473a0aa7c4e794b1200fb0cb9f241914046f4..7759940000deba804a487e38807df5f65b448832 100644 (file)
@@ -464,4 +464,7 @@ public:
   static QList<double>     getPlot2dFitRangeByCurves(const int) /ReleaseGIL/ ;
   static QList<double>     getPlot2dFitRangeCurrent(const int) /ReleaseGIL/ ;
   static void              setPlot2dFitRange(const int, const double XMin, const double XMax, const double YMin, const double YMax ) /ReleaseGIL/ ;
+
+  static void              startPyLog(const QString&) /ReleaseGIL/ ;
+  static void              stopPyLog() /ReleaseGIL/ ;
 };