Salome HOME
PyInterp prepare for qt6.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Mon, 20 Feb 2023 13:01:37 +0000 (14:01 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Mon, 20 Feb 2023 13:01:37 +0000 (14:01 +0100)
Synchronisation with phimeca sources.

tools/PyConsole/src/PyConsole.h
tools/PyConsole/src/PyConsole_Console.cxx
tools/PyConsole/src/PyConsole_Editor.cxx
tools/PyConsole/src/PyConsole_Editor.h
tools/PyConsole/src/PyConsole_Interp.cxx
tools/PyConsole/src/PyConsole_Request.cxx
tools/PyConsole/src/PyConsole_Request.h
tools/PyInterp/src/PyInterp.h
tools/PyInterp/src/PyInterp_Interp.cxx
tools/PyInterp/src/PyInterp_Utils.h

index d089918d2c555fadf168f79165234449b99f175c..e5e769d4fc3ccb1bbb2e275d6bb13a472f08e346 100644 (file)
@@ -27,7 +27,7 @@
 
 // ========================================================
 // set dllexport type for Win platform 
 
 // ========================================================
 // set dllexport type for Win platform 
-#ifdef WIN32
+#if !defined(PYCONSOLE_STATIC) && defined(_WIN32)
 #  if defined PYCONSOLE_EXPORTS || defined PyConsole_EXPORTS
 #    define PYCONSOLE_EXPORT __declspec(dllexport)
 #  else
 #  if defined PYCONSOLE_EXPORTS || defined PyConsole_EXPORTS
 #    define PYCONSOLE_EXPORT __declspec(dllexport)
 #  else
index 1615721dbd7d81ea060e1d5ac1b83c3c8db6576a..5d1da3cddc78f94aeecbfa5dfdca7db050979109 100644 (file)
@@ -87,7 +87,7 @@ void PyConsole_Console::init( PyConsole_Editor* editor )
   
   // create editor console
   QVBoxLayout* lay = new QVBoxLayout( this );
   
   // create editor console
   QVBoxLayout* lay = new QVBoxLayout( this );
-  lay->setMargin( 0 );
+  lay->setContentsMargins( 0, 0, 0 ,0 );
   myEditor = editor ? editor : new PyConsole_Editor( this, interp );
   myEditor->setContextMenuPolicy( Qt::NoContextMenu );
   lay->addWidget( myEditor );
   myEditor = editor ? editor : new PyConsole_Editor( this, interp );
   myEditor->setContextMenuPolicy( Qt::NoContextMenu );
   lay->addWidget( myEditor );
index 62e1e6d56b0ba9d3ce234ebbda9b562323bc283f..d3ffff9df7189ea391eb3a27f1eb1ec739d08934 100644 (file)
@@ -167,7 +167,7 @@ PyConsole_Editor::PyConsole_Editor( QWidget* parent )
   
   Creates python editor window.
   \param parent parent widget
   
   Creates python editor window.
   \param parent parent widget
-  \param interp python interper
+  \param interp python interpreter
 */
 PyConsole_Editor::PyConsole_Editor( QWidget*          parent,
                                     PyConsole_Interp* interp )
 */
 PyConsole_Editor::PyConsole_Editor( QWidget*          parent,
                                     PyConsole_Interp* interp )
@@ -198,7 +198,7 @@ void PyConsole_Editor::init()
   setWordWrapMode( QTextOption::WrapAnywhere );
   setAcceptRichText( false );
 
   setWordWrapMode( QTextOption::WrapAnywhere );
   setAcceptRichText( false );
 
-  // set callbacks to interpeter
+  // set callbacks to interpreter
   myInterp->setvoutcb( PyConsole_CallbackStdout, this );
   myInterp->setverrcb( PyConsole_CallbackStderr, this );
   // print banner
   myInterp->setvoutcb( PyConsole_CallbackStdout, this );
   myInterp->setverrcb( PyConsole_CallbackStderr, this );
   // print banner
@@ -387,7 +387,7 @@ void PyConsole_Editor::exec( const QString& command )
 {
   if ( isReadOnly() ) {
     // some interactive command is being executed in this editor...
 {
   if ( isReadOnly() ) {
     // some interactive command is being executed in this editor...
-    // shedule the command to the queue
+    // schedule the command to the queue
     myQueue.push_back( command );
     return;
   }
     myQueue.push_back( command );
     return;
   }
@@ -633,8 +633,12 @@ void PyConsole_Editor::handleBackTab()
 void PyConsole_Editor::dropEvent( QDropEvent* event )
 {
   // get the initial drop position
 void PyConsole_Editor::dropEvent( QDropEvent* event )
 {
   // get the initial drop position
+#if QT_VERSION >= 0x060000
+  QPoint pos = event->position().toPoint();
+#else
   QPoint pos = event->pos();
   QPoint pos = event->pos();
-  QTextCursor aCursor = cursorForPosition( event->pos() );
+#endif
+  QTextCursor aCursor = cursorForPosition( pos );
 
   // if the position is not in the last line move it to the end of the command line
   if ( aCursor.position() < document()->end().previous().position() + promptSize() ) {
 
   // if the position is not in the last line move it to the end of the command line
   if ( aCursor.position() < document()->end().previous().position() + promptSize() ) {
@@ -646,8 +650,13 @@ void PyConsole_Editor::dropEvent( QDropEvent* event )
   QDropEvent de( pos,
                  event->possibleActions(),
                  event->mimeData(),
   QDropEvent de( pos,
                  event->possibleActions(),
                  event->mimeData(),
+#if QT_VERSION >= 0x060000
+                 event->buttons(),
+                 event->modifiers(),
+#else
                  event->mouseButtons(),
                  event->keyboardModifiers(),
                  event->mouseButtons(),
                  event->keyboardModifiers(),
+#endif
                  event->type() );
   QTextEdit::dropEvent( &de );
 
                  event->type() );
   QTextEdit::dropEvent( &de );
 
@@ -684,7 +693,7 @@ void PyConsole_Editor::mouseReleaseEvent( QMouseEvent* event )
   if ( event->button() == Qt::LeftButton ) {
     QTextEdit::mouseReleaseEvent( event );
   }
   if ( event->button() == Qt::LeftButton ) {
     QTextEdit::mouseReleaseEvent( event );
   }
-  else if ( event->button() == Qt::MidButton ) {
+  else if ( event->button() == Qt::MiddleButton ) {
     QTextCursor aCursor = cursorForPosition( event->pos() );
     // if the position is not in the last line move it to the end of the command line
     if ( aCursor.position() < document()->end().previous().position() + promptSize() ) {
     QTextCursor aCursor = cursorForPosition( event->pos() );
     // if the position is not in the last line move it to the end of the command line
     if ( aCursor.position() < document()->end().previous().position() + promptSize() ) {
@@ -1306,7 +1315,7 @@ void PyConsole_Editor::customEvent( QEvent* event )
 
   if ( (int)event->type() == (int)PyInterp_Event::ES_OK && myQueue.count() > 0 )
   {
 
   if ( (int)event->type() == (int)PyInterp_Event::ES_OK && myQueue.count() > 0 )
   {
-    // process the next sheduled command from the queue (if there is any)
+    // process the next scheduled command from the queue (if there is any)
     QString nextcmd = myQueue[0];
     myQueue.pop_front();
     exec( nextcmd );
     QString nextcmd = myQueue[0];
     myQueue.pop_front();
     exec( nextcmd );
@@ -1393,7 +1402,7 @@ bool PyConsole_Editor::dump( const QString& fileName )
     if ( file.open( QFile::WriteOnly ) ) {
       QTextStream out( &file );
       for ( int i = 0; i < myHistory.count(); i++ ) {
     if ( file.open( QFile::WriteOnly ) ) {
       QTextStream out( &file );
       for ( int i = 0; i < myHistory.count(); i++ ) {
-#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+#if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
         out << myHistory[i] << Qt::endl;
 #else
         out << myHistory[i] << endl;
         out << myHistory[i] << Qt::endl;
 #else
         out << myHistory[i] << endl;
index 0748cf1e66f56787607b551716baa8076fe8bfb3..451a79f97c508aeef81d917ddd8a7be2a88b200a 100644 (file)
@@ -38,7 +38,7 @@ class QEventLoop;
 
 class PYCONSOLE_EXPORT PyConsole_Editor : public QTextEdit
 {
 
 class PYCONSOLE_EXPORT PyConsole_Editor : public QTextEdit
 {
-  Q_OBJECT
+  Q_OBJECT;
 
 public:
   PyConsole_Editor( QWidget* = 0 );
 
 public:
   PyConsole_Editor( QWidget* = 0 );
index 7dcff79d8f0e5973cb2f89b5e504e809e497ff3e..2a0303e366e7e51a030f5e8f6d63f3c61b5cdb1b 100644 (file)
@@ -23,6 +23,7 @@
 // Author : Nicolas REJNERI (OPEN CASCADE), Adrien BRUNETON (CEA/DEN), Vadim SANDLER (OPEN CASCADE)
 
 #include "PyConsole_Interp.h"
 // Author : Nicolas REJNERI (OPEN CASCADE), Adrien BRUNETON (CEA/DEN), Vadim SANDLER (OPEN CASCADE)
 
 #include "PyConsole_Interp.h"
+#include <QRegularExpression>
 
 /*!
   \class PyConsole_Interp
 
 /*!
   \class PyConsole_Interp
@@ -90,7 +91,7 @@ int PyConsole_Interp::afterRun()
   \internal
   \param dirArgument Python expression to pass to the dir command. The parsing of what the
   user actually started typing is dedicated to the caller
   \internal
   \param dirArgument Python expression to pass to the dir command. The parsing of what the
   user actually started typing is dedicated to the caller
-  \param startMatch string representing the begining of the patter to be completed. For example, when
+  \param startMatch string representing the beginning of the pattern to be completed. For example, when
   the user types "a_string_variable.rsp <TAB>", this is "rsp".
   \param[out] matches resulting list of matches
   \param[out] docString resulting docstring of single match
   the user types "a_string_variable.rsp <TAB>", this is "rsp".
   \param[out] matches resulting list of matches
   \param[out] docString resulting docstring of single match
@@ -159,7 +160,7 @@ bool PyConsole_Interp::runDirAndExtract( const QString& dirArgument,
                                          QStringList& result,
                                          bool discardSwig ) const
 {
                                          QStringList& result,
                                          bool discardSwig ) const
 {
-  QRegExp re( "^[A-Z].+_[A-Z]+[a-z]+.+$" ); // REX to discard SWIG static method, e.g. MEDCouplingUMesh_Blabla
+  QRegularExpression re( "^[A-Z].+_[A-Z]+[a-z]+.+$" ); // REX to discard SWIG static method, e.g. MEDCouplingUMesh_Blabla
 
   // Execute dir() command
   QString command( "dir(" + dirArgument + ")" );
 
   // Execute dir() command
   QString command( "dir(" + dirArgument + ")" );
@@ -187,7 +188,7 @@ bool PyConsole_Interp::runDirAndExtract( const QString& dirArgument,
     // if the method is not from swig, not static (guessed from the reg exp) and matches
     // what is already there
     if ( s.startsWith( startMatch ) ) {
     // if the method is not from swig, not static (guessed from the reg exp) and matches
     // what is already there
     if ( s.startsWith( startMatch ) ) {
-      if ( !discardSwig || ( !re.exactMatch( s ) && !s.contains( "swig" ) ) )
+      if ( !discardSwig || ( !re.match( s ).hasMatch() && !s.contains( "swig" ) ) )
         result.append( s );
     }
     Py_DECREF( it );
         result.append( s );
     }
     Py_DECREF( it );
index b6e4cf3de0a4e4c4dd5d4e01e2d9a8c64d1898a8..10ef5fa94a739327a1730fe68b3c400cde7a0374 100644 (file)
@@ -56,7 +56,7 @@ PyConsole_ExecCommand::PyConsole_ExecCommand( PyInterp_Interp*        theInterp,
 void PyConsole_ExecCommand::execute()
 {
   if ( myCommand != "" ) {
 void PyConsole_ExecCommand::execute()
 {
   if ( myCommand != "" ) {
-    int ret = getInterp()->run( myCommand.toUtf8().data() );
+    int ret = getInterp()->run(myCommand.toUtf8());
     if ( ret < 0 )
       myState = PyInterp_Event::ES_ERROR;
     else if ( ret > 0 )
     if ( ret < 0 )
       myState = PyInterp_Event::ES_ERROR;
     else if ( ret > 0 )
index f126f5e7ccd1e5045bb82446e58cf141c946b0f9..642b2fb2cd5a834a622f348e88c738d558e1c446 100644 (file)
@@ -55,7 +55,7 @@ protected:
 
 private:
   QString     myDirArg;       //!< String to be passed to the dir() comman
 
 private:
   QString     myDirArg;       //!< String to be passed to the dir() comman
-  QString     myStartMatch;   //!< Begining of the command (as typed by the user)
+  QString     myStartMatch;   //!< Beginning of the command (as typed by the user)
   bool        myStatus;       //!< Status of completion command execution
   QStringList myMatches;      //!< Matches
   QString     myDoc;          //!< Docstring of single match
   bool        myStatus;       //!< Status of completion command execution
   QStringList myMatches;      //!< Matches
   QString     myDoc;          //!< Docstring of single match
index 387cf18496d618d88fbdda5d2cf927af91463f8c..985770d0ffdebbe248f6d17e767e923f319c250d 100644 (file)
@@ -27,7 +27,7 @@
 
 // ========================================================
 // set dllexport type for Win platform 
 
 // ========================================================
 // set dllexport type for Win platform 
-#ifdef WIN32
+#if !defined(PYINTERP_STATIC) && defined(_WIN32)
 # if defined PYINTERP_EXPORTS || defined PyInterp_EXPORTS
 #  define PYINTERP_EXPORT __declspec(dllexport)
 # else
 # if defined PYINTERP_EXPORTS || defined PyInterp_EXPORTS
 #  define PYINTERP_EXPORT __declspec(dllexport)
 # else
index 7a8d020cfd8841eed6cf4fda18410c4e3993f6e4..287f6400e0b834bc34c4bbc4fdb0c11f4c5f0bce 100644 (file)
@@ -35,7 +35,7 @@
 #include <sstream>
 #include <algorithm>
 
 #include <sstream>
 #include <algorithm>
 
-#include <QRegExp>
+#include <QRegularExpression>
 #include <QStringList>
 
 #define TOP_HISTORY_PY   "--- top of history ---"
 #include <QStringList>
 
 #define TOP_HISTORY_PY   "--- top of history ---"
@@ -185,7 +185,7 @@ char* PyInterp_Interp::_argv[] = {(char*)""};
   \brief Basic constructor.
 
   After construction the interpreter instance successor classes
   \brief Basic constructor.
 
   After construction the interpreter instance successor classes
-  must call virtual method initalize().
+  must call virtual method initialize().
 */
 PyInterp_Interp::PyInterp_Interp():
   _vout(0), _verr(0), _global_context(0), _local_context(0), _initialized(false)
 */
 PyInterp_Interp::PyInterp_Interp():
   _vout(0), _verr(0), _global_context(0), _local_context(0), _initialized(false)
@@ -203,7 +203,7 @@ PyInterp_Interp::~PyInterp_Interp()
 /*!
   \brief Initialize embedded interpreter.
 
 /*!
   \brief Initialize embedded interpreter.
 
-  This method shoud be called after construction of the interpreter.
+  This method should be called after construction of the interpreter.
   The method initialize() calls virtuals methods
   - initPython()  to initialize global Python interpreter
   - initContext() to initialize interpreter internal context
   The method initialize() calls virtuals methods
   - initPython()  to initialize global Python interpreter
   - initContext() to initialize interpreter internal context
@@ -341,7 +341,7 @@ void PyInterp_Interp::closeContext()
 /*!
   \brief Compile Python command and evaluate it in the
          python dictionary contexts if possible. This is not thread-safe.
 /*!
   \brief Compile Python command and evaluate it in the
          python dictionary contexts if possible. This is not thread-safe.
-         This is the caller's responsability to make this thread-safe.
+         This is the caller's responsibility to make this thread-safe.
   \internal
   \param command Python command string
   \return -1 on fatal error, 1 if command is incomplete and 0
   \internal
   \param command Python command string
   \return -1 on fatal error, 1 if command is incomplete and 0
@@ -479,11 +479,12 @@ static int compile_command(const char *command, PyObject * global_ctxt, PyObject
   QString singleCommand = command;
   QString commandArgs = "";
 
   QString singleCommand = command;
   QString commandArgs = "";
 
-  QRegExp rx("exec\\s*\\(.*open\\s*\\(\\s*(.*)\\s*\\)\\s*\\.\\s*read\\s*\\(\\)(\\s*,\\s*args\\s*=\\s*\\(.*\\))\\s*\\)");
-  if (rx.indexIn(command) != -1) {
-    commandArgs = rx.cap(2).remove(0, rx.cap(2).indexOf("(")); // arguments of command
-    commandArgs.insert(commandArgs.indexOf('(')+1, rx.cap(1).split(",")[0].trimmed() + ","); // prepend arguments list by the script file itself
-    singleCommand = singleCommand.remove(rx.pos(2), rx.cap(2).size()); // command for execution without arguments
+  QRegularExpression rx("exec\\s*\\(.*open\\s*\\(\\s*(.*)\\s*\\)\\s*\\.\\s*read\\s*\\(\\)(\\s*,\\s*args\\s*=\\s*\\(.*\\))\\s*\\)");
+  QRegularExpressionMatch match = rx.match(command);
+  if (match.hasMatch()) {
+    commandArgs = match.captured(2).remove(0, match.captured(2).indexOf("(")); // arguments of command
+    commandArgs.insert(commandArgs.indexOf('(')+1, match.captured(1).split(",")[0].trimmed() + ","); // prepend arguments list by the script file itself
+    singleCommand = singleCommand.remove(match.capturedStart(2), match.captured(2).size()); // command for execution without arguments
   }
 
   if (commandArgs.isEmpty()) {
   }
 
   if (commandArgs.isEmpty()) {
@@ -514,7 +515,7 @@ int PyInterp_Interp::run(const char *command)
 }
 
 /**
 }
 
 /**
- * Called before a command is run (when calling run() method). Not thread-safe. Caller's responsability
+ * Called before a command is run (when calling run() method). Not thread-safe. Caller's responsibility
  * to acquire GIL if needed.
  */
 int PyInterp_Interp::beforeRun()
  * to acquire GIL if needed.
  */
 int PyInterp_Interp::beforeRun()
@@ -523,7 +524,7 @@ int PyInterp_Interp::beforeRun()
 }
 
 /**
 }
 
 /**
- * Called after a command is run (when calling run() method). Not thread-safe. Caller's responsability
+ * Called after a command is run (when calling run() method). Not thread-safe. Caller's responsibility
  * to acquire GIL if needed.
  */
 int PyInterp_Interp::afterRun()
  * to acquire GIL if needed.
  */
 int PyInterp_Interp::afterRun()
@@ -532,7 +533,7 @@ int PyInterp_Interp::afterRun()
 }
 
 /*!
 }
 
 /*!
-  \brief Run Python command (used internally). Not thread-safe. GIL acquisition is caller's responsability.
+  \brief Run Python command (used internally). Not thread-safe. GIL acquisition is caller's responsibility.
   \param command Python command
   \param addToHistory if \c true (default), the command is added to the commands history
   \return command status
   \param command Python command
   \param addToHistory if \c true (default), the command is added to the commands history
   \return command status
index 4d3c5b199a1ee0486de03dd2d1da9944f6f10da7..2251b27b46a3972df0e689b28a829a312f8f3aa2 100644 (file)
@@ -51,7 +51,7 @@ Py_DecodeLocale(const char *arg, size_t *size)
  * Utility class wrapping the Python GIL acquisition. This makes use of the high level
  * API (PyGILState_Ensure and PyGILState_Release), and is hence compatible with only
  * one running Python interpreter (no call to Py_NewInterpreter()).
  * Utility class wrapping the Python GIL acquisition. This makes use of the high level
  * API (PyGILState_Ensure and PyGILState_Release), and is hence compatible with only
  * one running Python interpreter (no call to Py_NewInterpreter()).
- * When the class is instanciated the lock is acquired. It is released at destruction time.
+ * When the class is instantiated the lock is acquired. It is released at destruction time.
  * Copy construction (and hence assignation) is forbidden.
  */
 class PYINTERP_EXPORT PyLockWrapper
  * Copy construction (and hence assignation) is forbidden.
  */
 class PYINTERP_EXPORT PyLockWrapper