X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPyConsole%2FPyConsole_Editor.cxx;h=2311b58d46bb29a3e2b48be8b4b7cd2020572401;hb=a6c6f1e04c7c1a22e856db2d6538bf5197f86c6c;hp=09a3455405723fa69b93fcceb4a5571dfc2d89d0;hpb=3f411740f2fda2fcc5632a43d47c69339e0df7b7;p=modules%2Fgui.git diff --git a/src/PyConsole/PyConsole_Editor.cxx b/src/PyConsole/PyConsole_Editor.cxx index 09a345540..2311b58d4 100644 --- a/src/PyConsole/PyConsole_Editor.cxx +++ b/src/PyConsole/PyConsole_Editor.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -113,6 +113,22 @@ #include #include +//VSR: uncomment below macro to support unicode text properly in SALOME +// current commented out due to regressions +//#define PAL22528_UNICODE + +namespace +{ + QString fromUtf8( const char* txt ) + { +#ifdef PAL22528_UNICODE + return QString::fromUtf8( txt ); +#else + return QString( txt ); +#endif + } +} + static QString READY_PROMPT = ">>> "; static QString DOTS_PROMPT = "... "; @@ -138,14 +154,20 @@ bool DumpCommandsFileValidator::canSave(const QString& file, bool permissions) 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( fromUtf8(c) ); + QApplication::postEvent( e, new PrintEvent( 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( fromUtf8(c) ); + QApplication::postEvent( e, new PrintEvent( fromUtf8(c), true ) ); + } } @@ -163,7 +185,7 @@ PyConsole_Editor::PyConsole_Editor( PyConsole_Interp* theInterp, myCmdInHistory( -1 ), myEventLoop( 0 ), myShowBanner( true ), - myIsSync( false ), + myIsSync( true ), myIsSuppressOutput( false ) { QString fntSet( "" ); @@ -185,16 +207,20 @@ PyConsole_Editor::PyConsole_Editor( PyConsole_Interp* theInterp, /*! \brief Destructor. - - Does nothing for the moment. */ PyConsole_Editor::~PyConsole_Editor() { - myInterp->destroy(); - delete myInterp; myInterp = 0; } +/*! + \brief Get Python interpreter +*/ +PyConsole_Interp* PyConsole_Editor::getInterp() const +{ + return myInterp; +} + /*! \brief Get synchronous mode flag value. @@ -272,6 +298,17 @@ void PyConsole_Editor::setIsShowBanner( const bool on ) } } +/*! + \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 @@ -342,6 +379,7 @@ void PyConsole_Editor::exec( const QString& command ) 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 ); @@ -378,14 +416,21 @@ void PyConsole_Editor::execAndWait( const QString& command ) return; // create new event loop - myEventLoop = new QEventLoop( this ); + bool sync = isSync(); + if ( !sync ) { + myEventLoop = new QEventLoop( this ); + } + // execute command exec( command ); - // run event loop - myEventLoop->exec(); - // delete event loop after command is processed - delete myEventLoop; - myEventLoop = 0; + + if ( !sync ) { + // run event loop + myEventLoop->exec(); + // delete event loop after command is processed + delete myEventLoop; + myEventLoop = 0; + } } /*! @@ -411,6 +456,7 @@ void PyConsole_Editor::handleReturn() // add command to the history if ( !cmd.trimmed().isEmpty() ) myHistory.push_back( cmd ); + putLog( QString( "%1%2\n" ).arg( myPrompt ).arg( cmd ) ); // IPAL19397 addText( "", true ); @@ -1116,18 +1162,90 @@ 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