]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
0022652: [CEA 1194] Redirect the traces from embedded Python console in a log file
authorvsr <vsr@opencascade.com>
Mon, 22 Sep 2014 12:40:05 +0000 (16:40 +0400)
committervsr <vsr@opencascade.com>
Mon, 22 Sep 2014 12:40:05 +0000 (16:40 +0400)
Additional changes:
- Use *.log *.txt as filter for log files
- Remove Python file name validator from Save Log dialog box
- Show prompt with the command in the output log

src/PyConsole/PyConsole_Editor.cxx
src/PyConsole/PyConsole_Editor.h
src/PyConsole/resources/PyConsole_msg_en.ts
src/PyConsole/resources/PyConsole_msg_fr.ts
src/PyConsole/resources/PyConsole_msg_ja.ts

index 46dc368ca606f830b0b217c981e8f91e7c7b1ed5..c9542464aa7ec3ab7d24d1785fc7e9233ab7e353 100644 (file)
@@ -342,6 +342,7 @@ void PyConsole_Editor::exec( const QString& command )
     if ( !lines[i].trimmed().isEmpty() ) {
       PyCommand aCommand;
       aCommand.command = lines[i];
+      aCommand.prompt = i == 0 ? READY_PROMPT : DOTS_PROMPT;
       myHistory.append( aCommand );
     }
     addText( ( i == 0 ? READY_PROMPT : DOTS_PROMPT ) + lines[i], i != 0 );
@@ -415,6 +416,7 @@ void PyConsole_Editor::handleReturn()
   if ( !cmd.trimmed().isEmpty() ) {
     PyCommand aCommand;
     aCommand.command = cmd;
+    aCommand.prompt = myPrompt;
     myHistory.append( aCommand );
   }
 
@@ -1123,17 +1125,17 @@ void PyConsole_Editor::dump()
   aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
   
   QString fileName = SUIT_FileDlg::getFileName( this, QString(),
-                                    aFilters, tr( "TOT_DUMP_PYCOMMANDS" ),
-                                    false, true, new DumpCommandsFileValidator( this ) );
-  if ( fileName != "" ) {
+                                               aFilters, tr( "TOT_DUMP_PYCOMMANDS" ),
+                                               false, true, new DumpCommandsFileValidator( this ) );
+  if ( !fileName.isEmpty() ) {
     QFile file( fileName ); 
     if ( !file.open( QFile::WriteOnly ) )
       return;
 
     QTextStream out (&file);
   
-    for( int i=0; i<myHistory.count(); i++ ) {
-         out<<myHistory.at(i).command<<endl;
+    for ( int i=0; i<myHistory.count(); i++ ) {
+      out << myHistory.at(i).command << endl;
     }
     file.close();
   }
@@ -1144,21 +1146,21 @@ void PyConsole_Editor::dump()
 void PyConsole_Editor::saveLog()
 {
   QStringList aFilters;
-  aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
+  aFilters.append( tr( "LOG_FILES_FILTER" ) );
 
   QString fileName = SUIT_FileDlg::getFileName( this, QString(),
-                     aFilters, tr( "TOT_SAVE_PYLOG" ),
-                 false, true, new DumpCommandsFileValidator( this ) );
-  if ( fileName != "" ) {
+                                               aFilters, tr( "TOT_SAVE_PYLOG" ),
+                                               false, true );
+  if ( !fileName.isEmpty() ) {
     QFile file( fileName );
     if ( !file.open( QFile::WriteOnly ) )
       return;
 
     QTextStream out (&file);
 
-    for( int i = 0; i < myHistory.count(); i++ ) {
-         out << myHistory.at(i).command << endl;
-         out << myHistory.at(i).output;
+     for( int i = 0; i < myHistory.count(); i++ ) {
+      out << myHistory.at(i).prompt << myHistory.at(i).command << endl;
+      out << myHistory.at(i).output;
     }
     file.close();
   }
index e9d5ad2ccaefbacd4e382d340123268701294a1b..994be9db658238f8d1f2fa0add2b1ea9d74ecee9 100644 (file)
@@ -36,7 +36,7 @@ class PyInterp_Request;
 class QEventLoop;
 
 typedef struct {
-  QString command, output;
+  QString command, output, prompt;
 } PyCommand;
 
 class PYCONSOLE_EXPORT PyConsole_Editor : public QTextEdit
index bb060d8a2bc89f8124961c2027ba2d3d3f254ac5..a4818b95b4006b77a11058add4b65fe29dc54e0b 100644 (file)
@@ -46,5 +46,9 @@
         <source>PYTHON_FILES_FILTER</source>
         <translation>PYTHON Files (*.py)</translation>
     </message>
+    <message>
+        <source>LOG_FILES_FILTER</source>
+        <translation>Log files (*.log *.txt)</translation>
+    </message>
 </context>
 </TS>
index 5c7ba5fe1ad4b490e9a5595271d73a5a03805684..92dd76dde25fda0e4c073ee4dfe68b9da93228b2 100755 (executable)
@@ -46,5 +46,9 @@
         <source>PYTHON_FILES_FILTER</source>
         <translation>Fichiers PYTHON (*.py)</translation>
     </message>
+    <message>
+        <source>LOG_FILES_FILTER</source>
+        <translation type="unfinished">Log files (*.log *.txt)</translation>
+    </message>
 </context>
 </TS>
index 82c2bbdb50352c1b0261d7d23025c976ca9f7596..23de7907ed0fc8badc5514afb736452ad4c7f983 100644 (file)
@@ -46,5 +46,9 @@
       <source>PYTHON_FILES_FILTER</source>
       <translation>ファイル (*.py) PYTHON</translation>
     </message>
+    <message>
+        <source>LOG_FILES_FILTER</source>
+        <translation type="unfinished">Log files (*.log *.txt)</translation>
+    </message>
   </context>
 </TS>