From e2a96fd9d3d88f2c3ab6cf63a08befb6d5957fbf Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 23 Sep 2014 17:50:17 +0400 Subject: [PATCH] 0022652: [CEA 1194] Redirect the traces from embedded Python console in a log file Additional changes: - Add functions to start/stop trace from embedded Python console to the Python API (SalomePyQt module) --- src/PyConsole/PyConsole_Console.cxx | 17 +++++++++++ src/PyConsole/PyConsole_Console.h | 3 ++ src/PyConsole/PyConsole_Editor.cxx | 25 ++++++++++++--- src/PyConsole/PyConsole_Editor.h | 1 + src/SALOME_PYQT/SalomePyQt/CMakeLists.txt | 1 + src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx | 37 +++++++++++++++++++++++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.h | 3 ++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip | 3 ++ 8 files changed, 85 insertions(+), 5 deletions(-) diff --git a/src/PyConsole/PyConsole_Console.cxx b/src/PyConsole/PyConsole_Console.cxx index f386ebfdb..a3991bf88 100644 --- a/src/PyConsole/PyConsole_Console.cxx +++ b/src/PyConsole/PyConsole_Console.cxx @@ -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. diff --git a/src/PyConsole/PyConsole_Console.h b/src/PyConsole/PyConsole_Console.h index de909960d..54442c2cd 100644 --- a/src/PyConsole/PyConsole_Console.h +++ b/src/PyConsole/PyConsole_Console.h @@ -84,6 +84,9 @@ public: void setMenuActions( const int ); int menuActions() const; + void startLog( const QString& ); + void stopLog(); + protected: void createActions(); void updateActions(); diff --git a/src/PyConsole/PyConsole_Editor.cxx b/src/PyConsole/PyConsole_Editor.cxx index be9ba6b98..66aaf5b9b 100644 --- a/src/PyConsole/PyConsole_Editor.cxx +++ b/src/PyConsole/PyConsole_Editor.cxx @@ -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. diff --git a/src/PyConsole/PyConsole_Editor.h b/src/PyConsole/PyConsole_Editor.h index 650712a8f..c939ef1b7 100644 --- a/src/PyConsole/PyConsole_Editor.h +++ b/src/PyConsole/PyConsole_Editor.h @@ -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& ); diff --git a/src/SALOME_PYQT/SalomePyQt/CMakeLists.txt b/src/SALOME_PYQT/SalomePyQt/CMakeLists.txt index 692883aac..540c27514 100755 --- a/src/SALOME_PYQT/SalomePyQt/CMakeLists.txt +++ b/src/SALOME_PYQT/SalomePyQt/CMakeLists.txt @@ -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 diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 46cffcc0c..75642bf48 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -50,6 +50,7 @@ #include "SUIT_ResourceMgr.h" #include "SUIT_Session.h" #include "SUIT_Tools.h" +#include "PyConsole_Console.h" #include #include @@ -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() ); +} diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index 2747c0f7c..68be1fafc 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -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 diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index 4da473a0a..775994000 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -464,4 +464,7 @@ public: static QList getPlot2dFitRangeByCurves(const int) /ReleaseGIL/ ; static QList 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/ ; }; -- 2.39.2