Salome HOME
[bos #35159][EDF] (2023-T1) Following commands in Python console. Fixed intermediate...
[modules/gui.git] / tools / PyConsole / src / PyConsole_Editor.cxx
index 4c3df75f0225ff9314a2d5c69cbf917f3243f67c..e0e7f4a1a511c736bf2995c83eddabb78f67f6d0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -88,8 +88,8 @@
   - <Ctrl><Tab>          : undoes auto-completion
 */
 
-#include "PyConsole_Editor.h"
 #include "PyConsole_Interp.h"
+#include "PyConsole_Editor.h"
 #include "PyConsole_Event.h"
 #include "PyInterp_Dispatcher.h"
 #include "PyConsole_Request.h"
 #include <QChar>
 #include <QFileDialog>
 #include <QMessageBox>
+#include <QtGlobal>
 
 //VSR: uncomment below macro to support unicode text properly in SALOME
 //     current commented out due to regressions
@@ -166,7 +167,7 @@ PyConsole_Editor::PyConsole_Editor( QWidget* parent )
   
   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 )
@@ -182,7 +183,7 @@ void PyConsole_Editor::init()
   myCmdInHistory = -1;
   myEventLoop = 0;
   myShowBanner = true;
-  myIsSync = true;
+  myIsSync = false;
   myIsSuppressOutput = false;
   myMultiLinePaste = false;
   myAutoCompletion = false;
@@ -197,7 +198,7 @@ void PyConsole_Editor::init()
   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
@@ -368,8 +369,6 @@ void PyConsole_Editor::addText( const QString& str,
     aCursor.insertBlock();
   if ( isError )
     cf.setForeground( QBrush( Qt::red ) );
-  else
-    cf.setForeground( QBrush( Qt::black ) );
   aCursor.insertText( str, cf );
   moveCursor( QTextCursor::End );
   ensureCursorVisible();
@@ -386,7 +385,7 @@ void PyConsole_Editor::exec( const QString& command )
 {
   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;
   }
@@ -632,8 +631,12 @@ void PyConsole_Editor::handleBackTab()
 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();
-  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() ) {
@@ -645,8 +648,13 @@ void PyConsole_Editor::dropEvent( QDropEvent* event )
   QDropEvent de( pos,
                  event->possibleActions(),
                  event->mimeData(),
+#if QT_VERSION >= 0x060000
+                 event->buttons(),
+                 event->modifiers(),
+#else
                  event->mouseButtons(),
                  event->keyboardModifiers(),
+#endif
                  event->type() );
   QTextEdit::dropEvent( &de );
 
@@ -683,7 +691,7 @@ void PyConsole_Editor::mouseReleaseEvent( QMouseEvent* 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() ) {
@@ -1175,7 +1183,7 @@ void PyConsole_Editor::keyPressEvent( QKeyEvent* event )
 */
 void PyConsole_Editor::customEvent( QEvent* event )
 {
-  switch( event->type() )
+  switch( (int) event->type() )
   {
   case PyConsole_PrintEvent::EVENT_ID:
   {
@@ -1305,7 +1313,7 @@ void PyConsole_Editor::customEvent( QEvent* event )
 
   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 );
@@ -1392,7 +1400,11 @@ bool PyConsole_Editor::dump( const QString& fileName )
     if ( file.open( QFile::WriteOnly ) ) {
       QTextStream out( &file );
       for ( int i = 0; i < myHistory.count(); i++ ) {
+#if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
+        out << myHistory[i] << Qt::endl;
+#else
         out << myHistory[i] << endl;
+#endif
       }
       file.close();
       ok = true;
@@ -1561,7 +1573,11 @@ void PyConsole_Editor::multilinePaste( const QString& s )
   // Split string data to lines
   QString s2 = s;
   s2.replace( "\r", "" ); // Windows string format converted to Unix style
+#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
+  QStringList lst = s2.split( QChar('\n'), Qt::KeepEmptyParts );
+#else
   QStringList lst = s2.split( QChar('\n'), QString::KeepEmptyParts );
+#endif
 
   // Perform the proper paste operation for the first line to handle the case where
   // something was already there