From 66ccab11e57cff2974461f55be8c085d6908f4d3 Mon Sep 17 00:00:00 2001 From: imn Date: Wed, 17 Sep 2014 12:34:18 +0400 Subject: [PATCH] 0022652: [CEA 1194] Redirect the traces from embedded Python console in a log file --- src/PyConsole/PyConsole_Console.cxx | 8 ++++ src/PyConsole/PyConsole_Console.h | 13 +++--- src/PyConsole/PyConsole_Editor.cxx | 48 +++++++++++++++++---- src/PyConsole/PyConsole_Editor.h | 7 ++- src/PyConsole/resources/PyConsole_msg_en.ts | 8 ++++ src/PyConsole/resources/PyConsole_msg_fr.ts | 8 ++++ src/PyConsole/resources/PyConsole_msg_ja.ts | 8 ++++ 7 files changed, 85 insertions(+), 15 deletions(-) diff --git a/src/PyConsole/PyConsole_Console.cxx b/src/PyConsole/PyConsole_Console.cxx index a14eca1d0..c613866d1 100644 --- a/src/PyConsole/PyConsole_Console.cxx +++ b/src/PyConsole/PyConsole_Console.cxx @@ -248,6 +248,7 @@ void PyConsole_Console::contextMenuPopup( QMenu* menu ) menu->addAction( myActions[SelectAllId] ); menu->addSeparator(); menu->addAction( myActions[DumpCommandsId] ); + menu->addAction( myActions[SaveLogId] ); Qtx::simplifySeparators( menu ); @@ -269,6 +270,7 @@ void PyConsole_Console::setMenuActions( const int flags ) myActions[ClearId]->setVisible( flags & ClearId ); myActions[SelectAllId]->setVisible( flags & SelectAllId ); myActions[DumpCommandsId]->setVisible( flags & DumpCommandsId ); + myActions[SaveLogId]->setVisible( flags & SaveLogId ); } /*! @@ -284,6 +286,7 @@ int PyConsole_Console::menuActions() const ret = ret | ( myActions[ClearId]->isVisible() ? ClearId : 0 ); ret = ret | ( myActions[SelectAllId]->isVisible() ? SelectAllId : 0 ); ret = ret | ( myActions[DumpCommandsId]->isVisible() ? DumpCommandsId : 0 ); + ret = ret | ( myActions[SaveLogId]->isVisible() ? SaveLogId : 0 ); return ret; } @@ -318,6 +321,11 @@ void PyConsole_Console::createActions() a->setStatusTip( tr( "EDIT_DUMPCOMMANDS_CMD" ) ); connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( dump() ) ); myActions.insert( DumpCommandsId, a ); + + a = new QAction( tr( "EDIT_SAVELOG_CMD" ), this ); + a->setStatusTip( tr( "EDIT_SAVELOG_CMD" ) ); + connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( saveLog() ) ); + myActions.insert( SaveLogId, a ); } /*! diff --git a/src/PyConsole/PyConsole_Console.h b/src/PyConsole/PyConsole_Console.h index 75163a9ae..783c6567a 100644 --- a/src/PyConsole/PyConsole_Console.h +++ b/src/PyConsole/PyConsole_Console.h @@ -44,12 +44,13 @@ public: //! Context popup menu actions flags enum { - CopyId = 0x01, //!< "Copy" menu action - PasteId = 0x02, //!< "Paste" menu action - ClearId = 0x04, //!< "Clear" menu action - SelectAllId = 0x08, //!< "Select All" menu action - DumpCommandsId = 0x16, //!< "DumpCommands" menu action - All = CopyId | PasteId | ClearId | SelectAllId | DumpCommandsId //!< all menu actions + CopyId = 0x01, //!< "Copy" menu action + PasteId = 0x02, //!< "Paste" menu action + ClearId = 0x04, //!< "Clear" menu action + SelectAllId = 0x08, //!< "Select All" menu action + DumpCommandsId = 0x10, //!< "DumpCommands" menu action + SaveLogId = 0x20, //!< "Save log" menu action + All = CopyId | PasteId | ClearId | SelectAllId | DumpCommandsId | SaveLogId //!< all menu actions }; public: diff --git a/src/PyConsole/PyConsole_Editor.cxx b/src/PyConsole/PyConsole_Editor.cxx index 09a345540..29c8d1ade 100644 --- a/src/PyConsole/PyConsole_Editor.cxx +++ b/src/PyConsole/PyConsole_Editor.cxx @@ -339,8 +339,11 @@ void PyConsole_Editor::exec( const QString& command ) if ( !cmd.endsWith( "\n" ) ) cmd += "\n"; QStringList lines = command.split( "\n" ); for ( int i = 0; i < lines.size(); i++ ) { - if ( !lines[i].trimmed().isEmpty() ) - myHistory.push_back( lines[i] ); + if ( !lines[i].trimmed().isEmpty() ) { + PyCommand aCommand; + aCommand.command = lines[i]; + myHistory.append( aCommand ); + } addText( ( i == 0 ? READY_PROMPT : DOTS_PROMPT ) + lines[i], i != 0 ); } // IPAL20182 @@ -409,8 +412,11 @@ void PyConsole_Editor::handleReturn() // extend the command buffer with the current command myCommandBuffer.append( cmd ); // add command to the history - if ( !cmd.trimmed().isEmpty() ) - myHistory.push_back( cmd ); + if ( !cmd.trimmed().isEmpty() ) { + PyCommand aCommand; + aCommand.command = cmd; + myHistory.append( aCommand ); + } // IPAL19397 addText( "", true ); @@ -596,7 +602,7 @@ void PyConsole_Editor::keyPressEvent( QKeyEvent* event ) if ( myCmdInHistory > 0 ) { myCmdInHistory--; // get previous command in the history - QString previousCommand = myHistory.at( myCmdInHistory ); + QString previousCommand = myHistory.at( myCmdInHistory ).command; // print previous command moveCursor( QTextCursor::End ); moveCursor( QTextCursor::StartOfBlock, QTextCursor::KeepAnchor ); @@ -633,7 +639,7 @@ void PyConsole_Editor::keyPressEvent( QKeyEvent* event ) QString nextCommand; if ( myCmdInHistory < myHistory.count() ) { // next command in history - nextCommand = myHistory.at( myCmdInHistory ); + nextCommand = myHistory.at( myCmdInHistory ).command; } else { // end of history is reached @@ -740,7 +746,7 @@ void PyConsole_Editor::keyPressEvent( QKeyEvent* event ) if ( myCmdInHistory > 0 ) { myCmdInHistory = 0; // get very first command in the history - QString firstCommand = myHistory.at( myCmdInHistory ); + QString firstCommand = myHistory.at( myCmdInHistory ).command; // print first command moveCursor( QTextCursor::End ); moveCursor( QTextCursor::StartOfBlock, QTextCursor::KeepAnchor ); @@ -935,6 +941,7 @@ void PyConsole_Editor::customEvent( QEvent* event ) { PrintEvent* pe=(PrintEvent*)event; addText( pe->text(), false, pe->isError()); + myHistory.last().output = myHistory.last().output + pe->text(); return; } case PyInterp_Event::ES_OK: @@ -1126,7 +1133,32 @@ void PyConsole_Editor::dump() QTextStream out (&file); for( int i=0; i myHistory; //!< commands history buffer QEventLoop* myEventLoop; //!< internal event loop QString myBanner; //!< current banner bool myShowBanner; //!< 'show banner' flag diff --git a/src/PyConsole/resources/PyConsole_msg_en.ts b/src/PyConsole/resources/PyConsole_msg_en.ts index 85393a2bf..bb060d8a2 100644 --- a/src/PyConsole/resources/PyConsole_msg_en.ts +++ b/src/PyConsole/resources/PyConsole_msg_en.ts @@ -27,6 +27,10 @@ EDIT_DUMPCOMMANDS_CMD D&ump commands + + EDIT_SAVELOG_CMD + &Save log + PyConsole_Editor @@ -34,6 +38,10 @@ TOT_DUMP_PYCOMMANDS Dump commands + + TOT_SAVE_PYLOG + Save log + PYTHON_FILES_FILTER PYTHON Files (*.py) diff --git a/src/PyConsole/resources/PyConsole_msg_fr.ts b/src/PyConsole/resources/PyConsole_msg_fr.ts index 910911562..5c7ba5fe1 100755 --- a/src/PyConsole/resources/PyConsole_msg_fr.ts +++ b/src/PyConsole/resources/PyConsole_msg_fr.ts @@ -27,6 +27,10 @@ EDIT_DUMPCOMMANDS_CMD &Générer le script des commandes + + EDIT_SAVELOG_CMD + &Save log + PyConsole_Editor @@ -34,6 +38,10 @@ TOT_DUMP_PYCOMMANDS &Générer le script des commandes + + TOT_SAVE_PYLOG + Save log + PYTHON_FILES_FILTER Fichiers PYTHON (*.py) diff --git a/src/PyConsole/resources/PyConsole_msg_ja.ts b/src/PyConsole/resources/PyConsole_msg_ja.ts index dde0da06b..82c2bbdb5 100644 --- a/src/PyConsole/resources/PyConsole_msg_ja.ts +++ b/src/PyConsole/resources/PyConsole_msg_ja.ts @@ -27,6 +27,10 @@ EDIT_DUMPCOMMANDS_CMD スクリプト コマンドを生成します。(&u) + + EDIT_SAVELOG_CMD + &Save log + PyConsole_Editor @@ -34,6 +38,10 @@ TOT_DUMP_PYCOMMANDS スクリプト コマンドを生成します。 + + TOT_SAVE_PYLOG + Save log + PYTHON_FILES_FILTER ファイル (*.py) PYTHON -- 2.39.2