From 6b5646865f62cac73f4f423e16871b1cdf16aeb5 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 6 Nov 2014 17:48:53 +0300 Subject: [PATCH] 0022802: EDF 9111 GUI: Regression: SIGSEV error when loading JOBMANGER after a python module --- src/LightApp/LightApp_Application.cxx | 23 +++- src/LightApp/LightApp_Application.h | 9 ++ src/LightApp/LightApp_PyInterp.h | 4 +- src/PyConsole/PyConsole_Console.cxx | 31 +++--- src/PyConsole/PyConsole_Console.h | 7 +- src/PyConsole/PyConsole_Editor.cxx | 12 ++- src/PyConsole/PyConsole_Editor.h | 2 + src/PyConsole/PyConsole_EnhEditor.cxx | 124 ++++++++++++---------- src/PyConsole/PyConsole_EnhEditor.h | 10 +- src/PyConsole/PyConsole_EnhInterp.cxx | 39 +++++-- src/PyConsole/PyConsole_EnhInterp.h | 18 ++-- src/PyConsole/PyConsole_Interp.cxx | 31 ++++-- src/PyConsole/PyConsole_Interp.h | 14 ++- src/PyConsole/PyConsole_Request.cxx | 58 +++++----- src/PyConsole/PyConsole_Request.h | 20 ++-- src/SalomeApp/SalomeApp_Application.cxx | 12 ++- src/SalomeApp/SalomeApp_Application.h | 1 + src/SalomeApp/SalomeApp_DoubleSpinBox.cxx | 4 +- src/SalomeApp/SalomeApp_IntSpinBox.cxx | 4 +- src/SalomeApp/SalomeApp_NoteBook.cxx | 4 +- src/SalomeApp/SalomeApp_PyInterp.h | 4 +- src/SalomeApp/SalomeApp_Study.cxx | 4 +- 22 files changed, 251 insertions(+), 184 deletions(-) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 2229aa3ea..56b3f8852 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -221,7 +221,6 @@ static const char* imageEmptyIcon[] = { int LightApp_Application::lastStudyId = 0; - // Markers used to parse array with dockable windows and toolbars state. // For more details please see the qdockarealayout.cpp && qtoolbararealayout.cpp // in the Qt source code. @@ -1616,7 +1615,7 @@ void LightApp_Application::onStudyCreated( SUIT_Study* theStudy ) #ifndef DISABLE_PYCONSOLE if( pythonConsole() ) - pythonConsole()->getInterp()->initStudy(); + getPyInterp()->initStudy(); #endif } @@ -1647,7 +1646,7 @@ void LightApp_Application::onStudyOpened( SUIT_Study* theStudy ) #ifndef DISABLE_PYCONSOLE if( pythonConsole() ) - pythonConsole()->getInterp()->initStudy(); + getPyInterp()->initStudy(); #endif emit studyOpened(); @@ -1916,7 +1915,7 @@ QWidget* LightApp_Application::createWindow( const int flag ) #ifndef DISABLE_PYCONSOLE else if ( flag == WT_PyConsole ) { - PyConsole_Console* pyCons = new PyConsole_EnhConsole( desktop(),new LightApp_PyInterp()); + PyConsole_Console* pyCons = new PyConsole_EnhConsole( desktop(), getPyInterp() ); pyCons->setObjectName( "pythonConsole" ); pyCons->setWindowTitle( tr( "PYTHON_CONSOLE" ) ); pyCons->setFont(resourceMgr()->fontValue( "PyConsole", "font" )); @@ -4456,3 +4455,19 @@ bool LightApp_Application::checkExistingDoc() return result; } +#ifndef DISABLE_PYCONSOLE + +PyConsole_Interp* LightApp_Application::getPyInterp() +{ + static PyConsole_Interp* myInterp = 0; + if ( !myInterp ) + myInterp = createPyInterp(); + return myInterp; +} + +PyConsole_Interp* LightApp_Application::createPyInterp() +{ + return new LightApp_PyInterp(); +} + +#endif // DISABLE_PYCONSOLE diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 3ea6cb1dd..54be0df78 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -42,6 +42,7 @@ class LogWindow; #ifndef DISABLE_PYCONSOLE class PyConsole_Console; +class PyConsole_Interp; #endif class LightApp_WidgetContainer; class LightApp_Preferences; @@ -182,6 +183,10 @@ public: virtual bool checkExistingDoc(); +#ifndef DISABLE_PYCONSOLE + PyConsole_Interp* getPyInterp(); +#endif + signals: void studyOpened(); void studySaved(); @@ -231,6 +236,10 @@ protected: virtual QMap activateModuleActions() const; virtual void moduleActionSelected( const int ); +#ifndef DISABLE_PYCONSOLE + virtual PyConsole_Interp* createPyInterp(); +#endif + protected slots: virtual void onDesktopActivated(); virtual void onViewManagerRemoved( SUIT_ViewManager* ); diff --git a/src/LightApp/LightApp_PyInterp.h b/src/LightApp/LightApp_PyInterp.h index de8c26636..7f35fbb25 100644 --- a/src/LightApp/LightApp_PyInterp.h +++ b/src/LightApp/LightApp_PyInterp.h @@ -27,11 +27,13 @@ class LightApp_PyInterp : public PyConsole_EnhInterp { + friend class LightApp_Application; + public: - LightApp_PyInterp(); virtual ~LightApp_PyInterp(); protected: + LightApp_PyInterp(); virtual void initPython(); }; diff --git a/src/PyConsole/PyConsole_Console.cxx b/src/PyConsole/PyConsole_Console.cxx index a3991bf88..5ec6eb57e 100644 --- a/src/PyConsole/PyConsole_Console.cxx +++ b/src/PyConsole/PyConsole_Console.cxx @@ -52,18 +52,15 @@ PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* interp ) : QWidget( parent ) { - // create python interpreter - myInterp = interp; - if ( !myInterp ) - myInterp = new PyConsole_Interp(); + PyConsole_Interp* anInterp = interp ? interp : new PyConsole_Interp(); // initialize Python interpretator - myInterp->initialize(); + anInterp->initialize(); // create editor console QVBoxLayout* lay = new QVBoxLayout( this ); lay->setMargin( 0 ); - myEditor = new PyConsole_Editor( myInterp, this ); + myEditor = new PyConsole_Editor( anInterp, this ); char* synchronous = getenv("PYTHON_CONSOLE_SYNC"); if (synchronous && atoi(synchronous)) { @@ -78,8 +75,8 @@ PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* interp /** * Protected constructor. */ -PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* i, PyConsole_Editor* e) - : QWidget (parent), myEditor(e), myInterp(i) +PyConsole_Console::PyConsole_Console( QWidget* parent, PyConsole_Interp* /*i*/, PyConsole_Editor* e ) + : QWidget (parent), myEditor(e) {} /*! @@ -91,6 +88,11 @@ PyConsole_Console::~PyConsole_Console() { } +PyConsole_Interp* PyConsole_Console::getInterp() const +{ + return myEditor ? myEditor->getInterp() : 0; +} + /*! \brief Execute python command in the interpreter. \param command string with command and arguments @@ -373,21 +375,18 @@ void PyConsole_Console::stopLog() * @param parent * @param interp */ -PyConsole_EnhConsole::PyConsole_EnhConsole( QWidget* parent, PyConsole_EnhInterp* interp) - : PyConsole_Console(parent, interp, 0) +PyConsole_EnhConsole::PyConsole_EnhConsole( QWidget* parent, PyConsole_Interp* interp ) + : PyConsole_Console( parent, interp, 0 ) { - // create python interpreter - myInterp = interp; - if ( !myInterp ) - myInterp = new PyConsole_EnhInterp(); + PyConsole_Interp* anInterp = interp ? interp : new PyConsole_EnhInterp(); // initialize Python interpretator - myInterp->initialize(); + anInterp->initialize(); // create editor console QVBoxLayout* lay = new QVBoxLayout( this ); lay->setMargin( 0 ); - myEditor = new PyConsole_EnhEditor( static_cast(myInterp), this ); + myEditor = new PyConsole_EnhEditor( anInterp, this ); char* synchronous = getenv("PYTHON_CONSOLE_SYNC"); if (synchronous && atoi(synchronous)) { diff --git a/src/PyConsole/PyConsole_Console.h b/src/PyConsole/PyConsole_Console.h index 54442c2cd..b32b078e4 100644 --- a/src/PyConsole/PyConsole_Console.h +++ b/src/PyConsole/PyConsole_Console.h @@ -34,7 +34,6 @@ class PyConsole_Interp; class PyConsole_Editor; -class PyConsole_EnhInterp; class PYCONSOLE_EXPORT PyConsole_Console : public QWidget, public SUIT_PopupClient { @@ -59,7 +58,7 @@ public: virtual ~PyConsole_Console(); //! \brief Get python interperter - PyConsole_Interp* getInterp() { return myInterp; } + PyConsole_Interp* getInterp() const; QFont font() const; virtual void setFont( const QFont& ); @@ -93,8 +92,6 @@ protected: PyConsole_Console( QWidget* parent, PyConsole_Interp*, PyConsole_Editor*); - - PyConsole_Interp* myInterp; //!< python interpreter PyConsole_Editor* myEditor; //!< python console editor widget QMap myActions; //!< menu actions list }; @@ -109,7 +106,7 @@ class PYCONSOLE_EXPORT PyConsole_EnhConsole: public PyConsole_Console Q_OBJECT public: - PyConsole_EnhConsole( QWidget* parent, PyConsole_EnhInterp* interp = 0); + PyConsole_EnhConsole( QWidget* parent, PyConsole_Interp* interp = 0 ); virtual ~PyConsole_EnhConsole() {} }; diff --git a/src/PyConsole/PyConsole_Editor.cxx b/src/PyConsole/PyConsole_Editor.cxx index 42ea63e4f..aeb61f965 100644 --- a/src/PyConsole/PyConsole_Editor.cxx +++ b/src/PyConsole/PyConsole_Editor.cxx @@ -191,16 +191,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. diff --git a/src/PyConsole/PyConsole_Editor.h b/src/PyConsole/PyConsole_Editor.h index c939ef1b7..5094f8687 100644 --- a/src/PyConsole/PyConsole_Editor.h +++ b/src/PyConsole/PyConsole_Editor.h @@ -42,6 +42,8 @@ class PYCONSOLE_EXPORT PyConsole_Editor : public QTextEdit public: PyConsole_Editor( PyConsole_Interp* theInterp, QWidget *theParent = 0 ); ~PyConsole_Editor(); + + PyConsole_Interp* getInterp() const; virtual void addText( const QString& str, const bool newBlock = false, const bool isError = false ); bool isCommand( const QString& str ) const; diff --git a/src/PyConsole/PyConsole_EnhEditor.cxx b/src/PyConsole/PyConsole_EnhEditor.cxx index 20a5ef1c5..aa73ac04b 100644 --- a/src/PyConsole/PyConsole_EnhEditor.cxx +++ b/src/PyConsole/PyConsole_EnhEditor.cxx @@ -43,7 +43,7 @@ const std::vector PyConsole_EnhEditor::SEPARATORS = \ * @param interp the interpreter linked to the editor * @param parent parent widget */ -PyConsole_EnhEditor::PyConsole_EnhEditor(PyConsole_EnhInterp * interp, QWidget * parent) : +PyConsole_EnhEditor::PyConsole_EnhEditor(PyConsole_Interp* interp, QWidget* parent) : PyConsole_Editor(interp, parent), _tab_mode(false), _cursor_pos(-1), @@ -117,7 +117,8 @@ void PyConsole_EnhEditor::clearCompletion() setTextCursor(tc); textCursor().deletePreviousChar(); // TODO: before wait for any TAB event to be completed - static_cast(myInterp)->clearCompletion(); + if ( myInterp ) + myInterp->clearCompletion(); } _tab_mode = false; } @@ -222,8 +223,8 @@ PyInterp_Request* PyConsole_EnhEditor::createTabRequest( const QString& input ) _compl_before_point = QString(""); } - return new CompletionCommand( static_cast(myInterp), _compl_before_point, - _compl_after_point, this, isSync() ); + return new CompletionCommand( myInterp, _compl_before_point, + _compl_after_point, this, isSync() ); } /** @@ -231,7 +232,7 @@ PyInterp_Request* PyConsole_EnhEditor::createTabRequest( const QString& input ) * @param matches list of possible completions * @param result return value */ -void PyConsole_EnhEditor::formatCompletion(const std::vector & matches, QString & result) const +void PyConsole_EnhEditor::formatCompletion(const QStringList& matches, QString& result) const { int sz = matches.size(); @@ -255,90 +256,97 @@ void PyConsole_EnhEditor::formatCompletion(const std::vector & matches, */ void PyConsole_EnhEditor::customEvent( QEvent* event ) { - std::vector matches; + QStringList matches; QString first_match, comple_text, doc, base; QTextCursor cursor(textCursor()); QTextBlockFormat bf; QTextCharFormat cf; - PyConsole_EnhInterp * interp = static_cast(myInterp); int cursorPos; switch( event->type() ) { case PyInterp_Event::ES_TAB_COMPLETE_OK: + { // Extract corresponding matches from the interpreter - matches = interp->getLastMatches(); + matches = getInterp()->getLastMatches(); + doc = getInterp()->getDocStr(); if (matches.size() == 0) - { - // Completion successful but nothing returned. - _tab_mode = false; - _cursor_pos = -1; - return; - } - + { + // Completion successful but nothing returned. + _tab_mode = false; + _cursor_pos = -1; + return; + } + // Only one match - complete directly and update doc string window - doc = interp->getDocStr(); if (matches.size() == 1) - { - first_match = matches[0].mid(_compl_after_point.size()); - cursor.insertText(first_match); - _tab_mode = false; - if (doc == QString("")) - emit updateDoc(formatDocHTML("(no documentation available)\n")); - else - emit updateDoc(formatDocHTML(doc)); - } + { + first_match = matches[0].mid(_compl_after_point.size()); + cursor.insertText(first_match); + _tab_mode = false; + if (doc.isEmpty()) + emit updateDoc(formatDocHTML("(no documentation available)\n")); + else + emit updateDoc(formatDocHTML(doc)); + } else - { - // Detect if there is a common base to all available completion - // In this case append this base to the text already - extractCommon(matches, base); - first_match = base.mid(_compl_after_point.size()); - cursor.insertText(first_match); - - // If this happens to match exaclty the first completion - // also provide doc - if (base == matches[0]) - { - doc = formatDocHTML(doc); - emit updateDoc(doc); - } - - // Print all matching completion in a "undo-able" block - cursorPos = cursor.position(); - cursor.insertBlock(); - cursor.beginEditBlock(); - - // Insert all matches - QTextCharFormat cf; - cf.setForeground(QBrush(Qt::darkGreen)); - cursor.setCharFormat(cf); - formatCompletion(matches, comple_text); - cursor.insertText(comple_text); - cursor.endEditBlock(); - - // Position cursor where it was before inserting the completion list: - cursor.setPosition(cursorPos); - setTextCursor(cursor); - } + { + // Detect if there is a common base to all available completion + // In this case append this base to the text already + extractCommon(matches, base); + first_match = base.mid(_compl_after_point.size()); + cursor.insertText(first_match); + + // If this happens to match exaclty the first completion + // also provide doc + if (base == matches[0]) + { + doc = formatDocHTML(doc); + emit updateDoc(doc); + } + + // Print all matching completion in a "undo-able" block + cursorPos = cursor.position(); + cursor.insertBlock(); + cursor.beginEditBlock(); + + // Insert all matches + QTextCharFormat cf; + cf.setForeground(QBrush(Qt::darkGreen)); + cursor.setCharFormat(cf); + formatCompletion(matches, comple_text); + cursor.insertText(comple_text); + cursor.endEditBlock(); + + // Position cursor where it was before inserting the completion list: + cursor.setPosition(cursorPos); + setTextCursor(cursor); + } break; + } case PyInterp_Event::ES_TAB_COMPLETE_ERR: + { // Tab completion was unsuccessful, switch off mode: _tab_mode = false; _cursor_pos = -1; break; + } case PyInterp_Event::ES_OK: case PyInterp_Event::ES_ERROR: case PyInterp_Event::ES_INCOMPLETE: + { // Before everything else, call super() PyConsole_Editor::customEvent(event); // If we are in multi_paste_mode, process the next item: multiLineProcessNextLine(); break; + } default: + { PyConsole_Editor::customEvent( event ); break; + } } } @@ -347,7 +355,7 @@ void PyConsole_EnhEditor::customEvent( QEvent* event ) * @param matches * @param result */ -void PyConsole_EnhEditor::extractCommon(const std::vector & matches, QString & result) const +void PyConsole_EnhEditor::extractCommon(const QStringList& matches, QString& result) const { result = ""; int charIdx = 0; diff --git a/src/PyConsole/PyConsole_EnhEditor.h b/src/PyConsole/PyConsole_EnhEditor.h index c18738f29..546ea98fc 100644 --- a/src/PyConsole/PyConsole_EnhEditor.h +++ b/src/PyConsole/PyConsole_EnhEditor.h @@ -23,13 +23,11 @@ #define PYCONSOLE_ENHEDITOR_H_ #include "PyConsole.h" - #include "PyConsole_Editor.h" + #include #include -class PyConsole_EnhInterp; - /** * Enhanced Python editor handling tab completion. */ @@ -38,7 +36,7 @@ class PYCONSOLE_EXPORT PyConsole_EnhEditor: public PyConsole_Editor Q_OBJECT; public: - PyConsole_EnhEditor(PyConsole_EnhInterp * interp, QWidget * parent=0); + PyConsole_EnhEditor(PyConsole_Interp* interp, QWidget* parent = 0); virtual ~PyConsole_EnhEditor() {} signals: @@ -83,14 +81,14 @@ protected: virtual void handleTab(); virtual void handleBackTab(); virtual void clearCompletion(); - virtual void formatCompletion(const std::vector & matches, QString & result) const; + virtual void formatCompletion(const QStringList& matches, QString& result) const; virtual QString formatDocHTML(const QString & doc) const; virtual void multilinePaste(const QString & s); virtual void multiLineProcessNextLine(); private: - void extractCommon(const std::vector & matches, QString & result) const; + void extractCommon(const QStringList& matches, QString& result) const; }; diff --git a/src/PyConsole/PyConsole_EnhInterp.cxx b/src/PyConsole/PyConsole_EnhInterp.cxx index 1f5defe07..eb5cb2705 100644 --- a/src/PyConsole/PyConsole_EnhInterp.cxx +++ b/src/PyConsole/PyConsole_EnhInterp.cxx @@ -37,6 +37,31 @@ static const char * tmp_k[] = {"and", "as", "assert", "break", "class", const std::vector PyConsole_EnhInterp::PYTHON_KEYWORDS = \ std::vector(tmp_k, tmp_k+sizeof(tmp_k)/sizeof(tmp_k[0])); +/*! + \brief Constructor +*/ +PyConsole_EnhInterp::PyConsole_EnhInterp() + : PyConsole_Interp() +{ +} + +/*! + \brief Destructor +*/ +PyConsole_EnhInterp::~PyConsole_EnhInterp() +{ +} + +QStringList PyConsole_EnhInterp::getLastMatches() const +{ + return _last_matches; +} + +QString PyConsole_EnhInterp::getDocStr() const +{ + return _doc_str; +} + /*! \brief Run Python dir() command and saves the result internally in _lastPy \param dirArgument Python expression to pass to the dir command. The parsing of what the @@ -45,7 +70,7 @@ const std::vector PyConsole_EnhInterp::PYTHON_KEYWORDS = \ the user types "a_string_variable.rsp ", this is "rsp". \return command exit status - 0 = success */ -int PyConsole_EnhInterp::runDirCommand(const QString & dirArgument, const QString & startMatch) +int PyConsole_EnhInterp::runDirCommand(const QString& dirArgument, const QString& startMatch) { int ret; std::vector v; @@ -99,8 +124,9 @@ int PyConsole_EnhInterp::runDirCommand(const QString & dirArgument, const QStrin * @return -1 if the call to dir() or the parsing of the result failed, 0 otherwise. */ int PyConsole_EnhInterp::runDirAndExtract(const QString& dirArgument, - const QString & startMatch, std::vector & result, - bool discardSwig) const + const QString& startMatch, + QStringList& result, + bool discardSwig) const { QRegExp re("^[A-Z].+_[A-Z]+[a-z]+.+$"); // discard SWIG static method, e.g. MEDCouplingUMesh_Blabla QString command("dir(" + dirArgument + ")"); @@ -146,9 +172,6 @@ int PyConsole_EnhInterp::runDirAndExtract(const QString& dirArgument, */ void PyConsole_EnhInterp::clearCompletion() { - _last_matches.resize(0); - _doc_str = QString(""); + _last_matches.clear(); + _doc_str = ""; } - - - diff --git a/src/PyConsole/PyConsole_EnhInterp.h b/src/PyConsole/PyConsole_EnhInterp.h index 4b16aa369..42c0ab35d 100644 --- a/src/PyConsole/PyConsole_EnhInterp.h +++ b/src/PyConsole/PyConsole_EnhInterp.h @@ -38,14 +38,11 @@ class PYCONSOLE_EXPORT PyConsole_EnhInterp: public PyConsole_Interp { public: - PyConsole_EnhInterp() - : PyConsole_Interp(), _last_matches(0), _doc_str("") - {} + PyConsole_EnhInterp(); + virtual ~PyConsole_EnhInterp(); - virtual ~PyConsole_EnhInterp() {} - - const std::vector& getLastMatches() const { return _last_matches; } - const QString & getDocStr() const { return _doc_str; } + virtual QStringList getLastMatches() const; + virtual QString getDocStr() const; virtual int runDirCommand(const QString& dirArgument, const QString& startMatch); virtual void clearCompletion(); @@ -55,13 +52,12 @@ protected: static const std::vector PYTHON_KEYWORDS; /** Last computed matches */ - std::vector _last_matches; + QStringList _last_matches; /** Doc string of the first match - when only one match it will be displayed by the Editor*/ QString _doc_str; - virtual int runDirAndExtract(const QString& dirArgument, const QString & startMatch, - std::vector & result, bool discardSwig=true) const; - + virtual int runDirAndExtract(const QString& dirArgument, const QString& startMatch, + QStringList& result, bool discardSwig=true) const; }; #endif /* PYCONSOLE_ENHINTERP_H_ */ diff --git a/src/PyConsole/PyConsole_Interp.cxx b/src/PyConsole/PyConsole_Interp.cxx index 01c94fe20..e1365760a 100644 --- a/src/PyConsole/PyConsole_Interp.cxx +++ b/src/PyConsole/PyConsole_Interp.cxx @@ -19,12 +19,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // - -// SALOME SALOMEGUI : implementation of desktop and GUI kernel // File : PyConsole_Interp.cxx // Author : Nicolas REJNERI, Adrien BRUNETON -// Module : SALOME -// + #include "PyConsole_Interp.h" /*! @@ -48,14 +45,17 @@ Creates new python interpreter. */ PyConsole_Interp::PyConsole_Interp(): PyInterp_Interp() -{} +{ +} /*! \brief Destructor. Does nothing for the moment. */ -PyConsole_Interp::~PyConsole_Interp() { } +PyConsole_Interp::~PyConsole_Interp() +{ +} /*! Sets the variable "__IN_SALOME_GUI_CONSOLE" to True. * This is not attached to a module (like salome_iapp.IN_SALOME_GUI_CONSOLE) @@ -72,3 +72,22 @@ int PyConsole_Interp::afterRun() { return PyRun_SimpleString("__builtins__.__IN_SALOME_GUI_CONSOLE=False"); } + +QStringList PyConsole_Interp::getLastMatches() const +{ + return QStringList(); +} + +QString PyConsole_Interp::getDocStr() const +{ + return QString(); +} + +int PyConsole_Interp::runDirCommand(const QString&, const QString& ) +{ + return 0; +} + +void PyConsole_Interp::clearCompletion() +{ +} diff --git a/src/PyConsole/PyConsole_Interp.h b/src/PyConsole/PyConsole_Interp.h index 5434e4813..31e8f7e97 100644 --- a/src/PyConsole/PyConsole_Interp.h +++ b/src/PyConsole/PyConsole_Interp.h @@ -19,18 +19,16 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // - -// SALOME SALOMEGUI : implementation of desktop and GUI kernel // File : PyConsole_Interp.h // Author : Nicolas REJNERI, Adrien BRUNETON -// Module : SALOME -// + #ifndef PYCONSOLE_INTERP_H #define PYCONSOLE_INTERP_H #include "PyConsole.h" +#include "PyInterp_Interp.h" /// !!! WARNING !!! THIS INCLUDE MUST BE VERY FIRST !!! -#include /// !!! WARNING !!! THIS INCLUDE MUST BE VERY FIRST !!! +#include class PYCONSOLE_EXPORT PyConsole_Interp : public PyInterp_Interp { @@ -40,6 +38,12 @@ public: virtual int afterRun(); virtual int beforeRun(); + + virtual QStringList getLastMatches() const; + virtual QString getDocStr() const; + + virtual int runDirCommand(const QString&, const QString&); + virtual void clearCompletion(); }; #endif // PYCONSOLE_INTERP_H diff --git a/src/PyConsole/PyConsole_Request.cxx b/src/PyConsole/PyConsole_Request.cxx index 97bf7f2df..12a5e612d 100644 --- a/src/PyConsole/PyConsole_Request.cxx +++ b/src/PyConsole/PyConsole_Request.cxx @@ -20,11 +20,9 @@ // Created on: 3 avr. 2013 #include "PyConsole_Request.h" - -#include "PyInterp_Event.h" +#include "PyConsole_Interp.h" #include "PyConsole_Event.h" -#include "PyConsole_EnhInterp.h" -#include "PyConsole_EnhEditor.h" +#include "PyInterp_Event.h" #include @@ -37,12 +35,12 @@ * @param sync */ ExecCommand::ExecCommand( PyInterp_Interp* theInterp, - const QString& theCommand, - PyConsole_Editor* theListener, - bool sync ) - : PyInterp_LockRequest( theInterp, theListener, sync ), - myCommand( theCommand ), myState( PyInterp_Event::ES_OK ) - {} + const QString& theCommand, + QObject* theListener, + bool theSync ) + : PyInterp_LockRequest( theInterp, theListener, theSync ), + myCommand( theCommand ), myState( PyInterp_Event::ES_OK ) +{} /** * Execute the command by calling the run() method of the embedded interpreter. @@ -50,13 +48,13 @@ ExecCommand::ExecCommand( PyInterp_Interp* theInterp, void ExecCommand::execute() { if ( myCommand != "" ) - { - int ret = getInterp()->run( myCommand.toUtf8().data() ); - if ( ret < 0 ) - myState = PyInterp_Event::ES_ERROR; - else if ( ret > 0 ) - myState = PyInterp_Event::ES_INCOMPLETE; - } + { + int ret = getInterp()->run( myCommand.toUtf8().data() ); + if ( ret < 0 ) + myState = PyInterp_Event::ES_ERROR; + else if ( ret > 0 ) + myState = PyInterp_Event::ES_INCOMPLETE; + } } /** @@ -80,13 +78,13 @@ QEvent* ExecCommand::createEvent() \param theListener widget to get the notification messages \param sync if True the request is processed synchronously */ -CompletionCommand::CompletionCommand( PyConsole_EnhInterp* theInterp, - const QString& input, - const QString& startMatch, - PyConsole_EnhEditor* theListener, - bool sync) - : PyInterp_LockRequest( theInterp, theListener, sync ), - _tabSuccess(false), _dirArg(input), _startMatch(startMatch) +CompletionCommand::CompletionCommand( PyInterp_Interp* theInterp, + const QString& theInput, + const QString& theStartMatch, + QObject* theListener, + bool theSync ) + : PyInterp_LockRequest( theInterp, theListener, theSync ), + _tabSuccess(false), _dirArg(theInput), _startMatch(theStartMatch) {} /** @@ -95,12 +93,8 @@ CompletionCommand::CompletionCommand( PyConsole_EnhInterp* theInterp, */ void CompletionCommand::execute() { - PyConsole_EnhInterp * interp = static_cast(getInterp()); - int ret = interp->runDirCommand( _dirArg, _startMatch); - if (ret == 0) - _tabSuccess = true; - else - _tabSuccess = false; + int ret = static_cast(getInterp())->runDirCommand( _dirArg, _startMatch ); + _tabSuccess = ret == 0; } /** @@ -110,9 +104,5 @@ void CompletionCommand::execute() QEvent* CompletionCommand::createEvent() { int typ = _tabSuccess ? PyInterp_Event::ES_TAB_COMPLETE_OK : PyInterp_Event::ES_TAB_COMPLETE_ERR; - return new PyInterp_Event( typ, this); } - - - diff --git a/src/PyConsole/PyConsole_Request.h b/src/PyConsole/PyConsole_Request.h index c2f22ff43..5605cc7fa 100644 --- a/src/PyConsole/PyConsole_Request.h +++ b/src/PyConsole/PyConsole_Request.h @@ -23,7 +23,6 @@ #ifndef PYCONSOLE_REQUEST_H_ #define PYCONSOLE_REQUEST_H_ -#include "PyConsole.h" #include "PyInterp_Request.h" #include @@ -31,7 +30,6 @@ #include class PyInterp_Interp; -class PyConsole_Editor; /*! \class ExecCommand @@ -52,8 +50,8 @@ public: */ ExecCommand( PyInterp_Interp* theInterp, const QString& theCommand, - PyConsole_Editor* theListener, - bool sync = false ); + QObject* theListener, + bool theSync = false ); protected: /*! @@ -73,17 +71,14 @@ private: int myState; //!< Python command execution status }; -class PyConsole_EnhInterp; -class PyConsole_EnhEditor; - class CompletionCommand : public PyInterp_LockRequest { public: - CompletionCommand( PyConsole_EnhInterp* theInterp, - const QString& input, - const QString& startMatch, - PyConsole_EnhEditor* theListener, - bool sync = false ); + CompletionCommand( PyInterp_Interp* theInterp, + const QString& theInput, + const QString& theStartMatch, + QObject* theListener, + bool theSync = false ); protected: @@ -99,7 +94,6 @@ protected: virtual void execute(); virtual QEvent* createEvent(); - }; #endif /* PYCONSOLE_REQUEST_H_ */ diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index c9e8d72e1..c142eca0b 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -1112,7 +1112,7 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) #ifndef DISABLE_PYCONSOLE else if ( flag == WT_PyConsole ) { - PyConsole_Console* pyCons = new PyConsole_EnhConsole( desktop(), new SalomeApp_PyInterp() ); + PyConsole_Console* pyCons = new PyConsole_EnhConsole( desktop(), getPyInterp() ); pyCons->setObjectName( "pythonConsole" ); pyCons->setWindowTitle( tr( "PYTHON_CONSOLE" ) ); pyCons->setFont(resourceMgr()->fontValue( "PyConsole", "font" )); @@ -2124,3 +2124,13 @@ bool SalomeApp_Application::checkExistingDoc() } return result; } + + +#ifndef DISABLE_PYCONSOLE + +PyConsole_Interp* SalomeApp_Application::createPyInterp() +{ + return new SalomeApp_PyInterp(); +} + +#endif // DISABLE_PYCONSOLE diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index b9833a1dc..aeee6dcb2 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -168,6 +168,7 @@ protected: #ifndef DISABLE_PYCONSOLE bool updateStudy(); + virtual PyConsole_Interp* createPyInterp(); #endif virtual void afterCloseDoc(); diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx index 527449499..9611f2ff4 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx @@ -23,7 +23,6 @@ #ifndef DISABLE_PYCONSOLE #include // this include must be first (see PyInterp_base.h)! - #include #endif #include "SalomeApp_DoubleSpinBox.h" @@ -438,8 +437,7 @@ SalomeApp_DoubleSpinBox::SearchState SalomeApp_DoubleSpinBox::findVariable( cons if( studyDS->IsString( aName ) ) { #ifndef DISABLE_PYCONSOLE - PyConsole_Console* pyConsole = app->pythonConsole(); - PyConsole_Interp* pyInterp = pyConsole->getInterp(); + PyConsole_Interp* pyInterp = app->getPyInterp(); PyLockWrapper aLock; // Acquire GIL std::string command; command = "import salome_notebook ; "; diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.cxx b/src/SalomeApp/SalomeApp_IntSpinBox.cxx index 2e8bcc78d..b5cc01765 100644 --- a/src/SalomeApp/SalomeApp_IntSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_IntSpinBox.cxx @@ -23,7 +23,6 @@ #ifndef DISABLE_PYCONSOLE #include //this include must be first (see PyInterp_base.h)! - #include #endif #include "SalomeApp_IntSpinBox.h" @@ -386,8 +385,7 @@ SalomeApp_IntSpinBox::SearchState SalomeApp_IntSpinBox::findVariable( const QStr if( studyDS->IsString( aName ) ) { #ifndef DISABLE_PYCONSOLE - PyConsole_Console* pyConsole = app->pythonConsole(); - PyConsole_Interp* pyInterp = pyConsole->getInterp(); + PyConsole_Interp* pyInterp = app->getPyInterp(); PyLockWrapper aLock; // Acquire GIL std::string command; command = "import salome_notebook ; "; diff --git a/src/SalomeApp/SalomeApp_NoteBook.cxx b/src/SalomeApp/SalomeApp_NoteBook.cxx index b5ecb767a..242aae2ca 100644 --- a/src/SalomeApp/SalomeApp_NoteBook.cxx +++ b/src/SalomeApp/SalomeApp_NoteBook.cxx @@ -285,7 +285,7 @@ bool NoteBook_TableRow::IsValidStringValue(const QString theValue) SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ); PyConsole_Console* pyConsole = app->pythonConsole(); - PyConsole_Interp* pyInterp = pyConsole->getInterp(); + PyConsole_Interp* pyInterp = app->getPyInterp(); PyLockWrapper aLock; // Acquire GIL std::string command = "import salome_notebook ; "; command += "salome_notebook.checkThisNoteBook("; @@ -459,7 +459,7 @@ bool NoteBook_Table::IsValid() const SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ); PyConsole_Console* pyConsole = app->pythonConsole(); - PyConsole_Interp* pyInterp = pyConsole->getInterp(); + PyConsole_Interp* pyInterp = app->getPyInterp(); PyLockWrapper aLock; // Acquire GIL std::string command = "import salome_notebook ; "; command += "salome_notebook.checkThisNoteBook("; diff --git a/src/SalomeApp/SalomeApp_PyInterp.h b/src/SalomeApp/SalomeApp_PyInterp.h index bf7bd8d50..a0b6a3ec2 100755 --- a/src/SalomeApp/SalomeApp_PyInterp.h +++ b/src/SalomeApp/SalomeApp_PyInterp.h @@ -31,8 +31,9 @@ class SalomeApp_PyInterp : public PyConsole_EnhInterp { + friend class SalomeApp_Application; + public: - SalomeApp_PyInterp(); virtual ~SalomeApp_PyInterp(); virtual void initPython(); @@ -40,6 +41,7 @@ public: virtual void closeContext(); protected: + SalomeApp_PyInterp(); virtual int beforeRun(); private: diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 293488936..ab6166997 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -49,7 +49,6 @@ #ifndef DISABLE_PYCONSOLE #include "SalomeApp_PyInterp.h" // WARNING! This include must be the first! - #include #endif #include "utilities.h" @@ -741,8 +740,7 @@ void SalomeApp_Study::closeDocument(bool permanently) desk->blockSignals( isBlocked ); #ifndef DISABLE_PYCONSOLE SalomeApp_Application* app = dynamic_cast( application() ); - if( app->pythonConsole() ) - app->pythonConsole()->getInterp()->destroy(); + app->getPyInterp()->destroy(); #endif } SALOMEDSClient_Study* aStudy = 0; -- 2.39.2