menu->addAction( myActions[SelectAllId] );
menu->addSeparator();
menu->addAction( myActions[DumpCommandsId] );
- menu->addAction( myActions[SaveLogId] );
+ if ( !myEditor->isLogging() )
+ menu->addAction( myActions[StartLogId] );
+ else
+ menu->addAction( myActions[StopLogId] );
Qtx::simplifySeparators( menu );
myActions[ClearId]->setVisible( flags & ClearId );
myActions[SelectAllId]->setVisible( flags & SelectAllId );
myActions[DumpCommandsId]->setVisible( flags & DumpCommandsId );
- myActions[SaveLogId]->setVisible( flags & SaveLogId );
+ myActions[StartLogId]->setVisible( flags & StartLogId );
+ myActions[StopLogId]->setVisible( flags & StopLogId );
}
/*!
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 );
+ ret = ret | ( myActions[StartLogId]->isVisible() ? StartLogId : 0 );
+ ret = ret | ( myActions[StopLogId]->isVisible() ? StopLogId : 0 );
return ret;
}
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 );
+ a = new QAction( tr( "EDIT_STARTLOG_CMD" ), this );
+ a->setStatusTip( tr( "EDIT_STARTLOG_CMD" ) );
+ connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( startLog() ) );
+ myActions.insert( StartLogId, a );
+
+ a = new QAction( tr( "EDIT_STOPLOG_CMD" ), this );
+ a->setStatusTip( tr( "EDIT_STOPLOG_CMD" ) );
+ connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( stopLog() ) );
+ myActions.insert( StopLogId, a );
}
/*!
//! 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 = 0x10, //!< "DumpCommands" menu action
- SaveLogId = 0x20, //!< "Save log" menu action
- All = CopyId | PasteId | ClearId | SelectAllId | DumpCommandsId | SaveLogId //!< 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
+ StartLogId = 0x20, //!< "Start log" menu action
+ StopLogId = 0x40, //!< "Stop log" menu action
+ All = 0xFF, //!< all menu actions
};
public:
void staticCallbackStdout( void* data, char* c )
{
- if(!((PyConsole_Editor*)data)->isSuppressOutput())
- QApplication::postEvent( (PyConsole_Editor*)data, new PrintEvent( QString::fromUtf8(c), false ) );
+ if(!((PyConsole_Editor*)data)->isSuppressOutput()) {
+ PyConsole_Editor* e = (PyConsole_Editor*)data;
+ e->putLog( QString::fromUtf8(c) );
+ QApplication::postEvent( e, new PrintEvent( QString::fromUtf8(c), false ) );
+ }
}
void staticCallbackStderr( void* data, char* c )
{
- if(!((PyConsole_Editor*)data)->isSuppressOutput())
- QApplication::postEvent( (PyConsole_Editor*)data, new PrintEvent( QString::fromUtf8(c), true ) );
+ if(!((PyConsole_Editor*)data)->isSuppressOutput()) {
+ PyConsole_Editor* e = (PyConsole_Editor*)data;
+ e->putLog( QString::fromUtf8(c) );
+ QApplication::postEvent( e, new PrintEvent( QString::fromUtf8(c), true ) );
+ }
}
}
}
+/*!
+ \brief Check if trace logging is switched on.
+
+ \sa startLog(), stopLog()
+ \return \c true if trace logging is switched on
+*/
+bool PyConsole_Editor::isLogging() const
+{
+ return !myLogFile.isEmpty();
+}
+
/*!
\brief Get size hint for the Python console window
\return size hint value
if ( !cmd.endsWith( "\n" ) ) cmd += "\n";
QStringList lines = command.split( "\n" );
for ( int i = 0; i < lines.size(); i++ ) {
- if ( !lines[i].trimmed().isEmpty() ) {
- PyCommand aCommand;
- aCommand.command = lines[i];
- aCommand.prompt = i == 0 ? READY_PROMPT : DOTS_PROMPT;
- myHistory.append( aCommand );
- }
+ if ( !lines[i].trimmed().isEmpty() )
+ myHistory.push_back( lines[i] );
addText( ( i == 0 ? READY_PROMPT : DOTS_PROMPT ) + lines[i], i != 0 );
+ putLog( QString( "%1%2\n" ).arg( i == 0 ? READY_PROMPT : DOTS_PROMPT ).arg( lines[i] ) );
}
// IPAL20182
addText( "", true );
// extend the command buffer with the current command
myCommandBuffer.append( cmd );
// add command to the history
- if ( !cmd.trimmed().isEmpty() ) {
- PyCommand aCommand;
- aCommand.command = cmd;
- aCommand.prompt = myPrompt;
- myHistory.append( aCommand );
- }
+ if ( !cmd.trimmed().isEmpty() )
+ myHistory.push_back( cmd );
+ putLog( QString( "%1%2\n" ).arg( myPrompt ).arg( cmd ) );
// IPAL19397
addText( "", true );
if ( myCmdInHistory > 0 ) {
myCmdInHistory--;
// get previous command in the history
- QString previousCommand = myHistory.at( myCmdInHistory ).command;
+ QString previousCommand = myHistory.at( myCmdInHistory );
// print previous command
moveCursor( QTextCursor::End );
moveCursor( QTextCursor::StartOfBlock, QTextCursor::KeepAnchor );
QString nextCommand;
if ( myCmdInHistory < myHistory.count() ) {
// next command in history
- nextCommand = myHistory.at( myCmdInHistory ).command;
+ nextCommand = myHistory.at( myCmdInHistory );
}
else {
// end of history is reached
if ( myCmdInHistory > 0 ) {
myCmdInHistory = 0;
// get very first command in the history
- QString firstCommand = myHistory.at( myCmdInHistory ).command;
+ QString firstCommand = myHistory.at( myCmdInHistory );
// print first command
moveCursor( QTextCursor::End );
moveCursor( QTextCursor::StartOfBlock, QTextCursor::KeepAnchor );
{
PrintEvent* pe=(PrintEvent*)event;
addText( pe->text(), false, pe->isError());
- myHistory.last().output = myHistory.last().output + pe->text();
return;
}
case PyInterp_Event::ES_OK:
QTextStream out (&file);
for ( int i=0; i<myHistory.count(); i++ ) {
- out << myHistory.at(i).command << endl;
+ out << myHistory[i] << endl;
}
file.close();
}
/*!
\brief "Save log" operation.
*/
-void PyConsole_Editor::saveLog()
+void PyConsole_Editor::startLog()
{
QStringList aFilters;
aFilters.append( tr( "LOG_FILES_FILTER" ) );
- QString fileName = SUIT_FileDlg::getFileName( this, QString(),
- aFilters, tr( "TOT_SAVE_PYLOG" ),
- false, true );
- if ( !fileName.isEmpty() ) {
- QFile file( fileName );
- if ( !file.open( QFile::WriteOnly ) )
- return;
+ while (1) {
+ QString fileName = SUIT_FileDlg::getFileName( this, QString(),
+ aFilters, tr( "TOT_SAVE_PYLOG" ),
+ false, true );
+ if ( !fileName.isEmpty() ) {
+ QFile file( fileName );
+ if ( file.open( QFile::WriteOnly ) ) {
+ file.close();
+ myLogFile = fileName;
+ break;
+ }
+ else {
+ SUIT_MessageBox::critical( this,
+ QObject::tr("ERR_ERROR"),
+ QObject::tr("ERR_FILE_NOT_WRITABLE") );
+ }
+ }
+ else {
+ break;
+ }
+ }
+}
- QTextStream out (&file);
- for( int i = 0; i < myHistory.count(); i++ ) {
- out << myHistory.at(i).prompt << myHistory.at(i).command << endl;
- out << myHistory.at(i).output;
- }
+/*!
+ \brief "Stop log" operation.
+ \sa startLog()
+ */
+void PyConsole_Editor::stopLog()
+{
+ myLogFile = QString();
+}
+
+/*!
+ \brief Put string to the log file
+ */
+void PyConsole_Editor::putLog( const QString& s )
+{
+ if ( !myLogFile.isEmpty() ) {
+ QFile file( myLogFile );
+ if ( !file.open( QFile::Append ) )
+ return;
+
+ QTextStream out (&file);
+ out << s;
+
file.close();
}
}
class PyInterp_Request;
class QEventLoop;
-typedef struct {
- QString command, output, prompt;
-} PyCommand;
-
class PYCONSOLE_EXPORT PyConsole_Editor : public QTextEdit
{
Q_OBJECT;
bool isShowBanner() const;
void setIsShowBanner( const bool );
+ bool isLogging() const;
+
virtual QSize sizeHint() const;
public slots:
void handleReturn();
void onPyInterpChanged( PyConsole_Interp* );
void dump();
- void saveLog();
+ void startLog();
+ void stopLog();
+ void putLog( const QString& );
protected:
virtual void dropEvent( QDropEvent* event );
QString myCurrentCommand; //!< currently being printed command
QString myPrompt; //!< current command line prompt
int myCmdInHistory; //!< current history command index
- QList<PyCommand> myHistory; //!< commands history buffer
+ QString myLogFile; //!< current output log
+ QStringList myHistory; //!< commands history buffer
QEventLoop* myEventLoop; //!< internal event loop
QString myBanner; //!< current banner
bool myShowBanner; //!< 'show banner' flag
</message>
<message>
<source>EDIT_DUMPCOMMANDS_CMD</source>
- <translation>D&ump commands</translation>
+ <translation>D&ump Commands</translation>
</message>
<message>
- <source>EDIT_SAVELOG_CMD</source>
- <translation>&Save log</translation>
+ <source>EDIT_STARTLOG_CMD</source>
+ <translation>Start &Log</translation>
+ </message>
+ <message>
+ <source>EDIT_STOPLOG_CMD</source>
+ <translation>Stop &Log</translation>
</message>
</context>
<context>
<source>LOG_FILES_FILTER</source>
<translation>Log files (*.log *.txt)</translation>
</message>
+ <message>
+ <source>ERR_FILE_NOT_WRITABLE</source>
+ <translation>File is not writable!</translation>
+ </message>
</context>
</TS>
<translation>&Générer le script des commandes</translation>
</message>
<message>
- <source>EDIT_SAVELOG_CMD</source>
- <translation type="unfinished">&Save log</translation>
+ <source>EDIT_STARTLOG_CMD</source>
+ <translation type="unfinished">Start &Log</translation>
+ </message>
+ <message>
+ <source>EDIT_STOPLOG_CMD</source>
+ <translation type="unfinished">Stop &Log</translation>
</message>
</context>
<context>
<source>LOG_FILES_FILTER</source>
<translation type="unfinished">Log files (*.log *.txt)</translation>
</message>
+ <message>
+ <source>ERR_FILE_NOT_WRITABLE</source>
+ <translation type="unfinished">File is not writable!</translation>
+ </message>
</context>
</TS>
<translation>スクリプト コマンドを生成します。(&u)</translation>
</message>
<message>
- <source>EDIT_SAVELOG_CMD</source>
- <translation type="unfinished">&Save log</translation>
+ <source>EDIT_STARTLOG_CMD</source>
+ <translation type="unfinished">Start &Log</translation>
+ </message>
+ <message>
+ <source>EDIT_STOPLOG_CMD</source>
+ <translation type="unfinished">Stop &Log</translation>
</message>
</context>
<context>
<source>LOG_FILES_FILTER</source>
<translation type="unfinished">Log files (*.log *.txt)</translation>
</message>
+ <message>
+ <source>ERR_FILE_NOT_WRITABLE</source>
+ <translation type="unfinished">File is not writable!</translation>
+ </message>
</context>
</TS>