@@ -580,7 +580,10 @@ bool QtPythonConsole::stopOnError = true;
580580const QSize QtPythonConsole::iconSize (32 , 32 );
581581bool QtPythonConsole::_catchStdOutputs = true ;
582582
583+ // QTextCharFormat : zone avec du texte
584+ // QTextBlockFormat : le reste du bloc
583585static QTextBlockFormat defaultBlockFormat;
586+ static QTextCharFormat defaultCharFormat;
584587static QBrush defaultBackground;
585588
586589
@@ -750,6 +753,7 @@ QtPythonConsole::QtPythonConsole (QWidget* parent, const string& appName)
750753{
751754 setCenterOnScroll (true );
752755 QTextCursor cursor = textCursor ( );
756+ defaultCharFormat = cursor.charFormat ( );
753757 defaultBlockFormat = cursor.blockFormat ( );
754758 defaultBackground = defaultBlockFormat.background ( );
755759
@@ -780,8 +784,7 @@ QtPythonConsole::QtPythonConsole (QWidget* parent, const string& appName)
780784 // Enlève tous les points d'arrêt.
781785 _clearBreakPointsAction = new QAction (QIcon (" :/images/clear_breakpoints.png" ), QSTR (" Enlever tous les points d'arrêt" ),this );
782786 connect (_clearBreakPointsAction, SIGNAL (triggered ( )), this , SLOT (clearBreakPointsCallback ( )));
783- // Affiche un sélecteur de fichier de chargement de script au point
784- // d'édition courant :
787+ // Affiche un sélecteur de fichier de chargement de script au point d'édition courant :
785788 _insertScriptAction = new QAction (QIcon (" :/images/load_script.png" ), QSTR (" Insérer un script ..." ), this );
786789 connect (_insertScriptAction, SIGNAL (triggered ( )), this , SLOT (insertScriptCallback ( )));
787790
@@ -987,7 +990,7 @@ void QtPythonConsole::setRunningMode (QtPythonConsole::RUNNING_MODE mode)
987990 case QtPythonConsole::RM_DEBUG :
988991 try
989992 {
990- _waitingForRunning = false ; // v 1.14.0
993+ _waitingForRunning = false ;
991994 quitDbg ( );
992995 }
993996 catch (...)
@@ -1009,8 +1012,7 @@ void QtPythonConsole::insert (const string& fileName, string& warnings)
10091012 // On se met en début de ligne courante :
10101013 moveCursor (QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
10111014
1012- Charset::CHARSET streamCharset = getFileCharset (fileName); // v 3.3.0
1013- // streamCharset = Charset::UNKNOWN == streamCharset ? Charset::ASCII : streamCharset;
1015+ Charset::CHARSET streamCharset = getFileCharset (fileName);
10141016 streamCharset = Charset::UNKNOWN == streamCharset ? Charset::UTF_8 : streamCharset; // v 5.1.7, éviter un rejet de conversion si caractère accentué
10151017
10161018 // UTF-16 : les sauts de ligne ne sont pas des \n => réécrire différemment la lecture du fichier.
@@ -1021,7 +1023,7 @@ void QtPythonConsole::insert (const string& fileName, string& warnings)
10211023 if ((false == stream.good ( )) && (false == stream.eof ( )))
10221024 throw Exception (" Fichier invalide." );
10231025 char buffer [10001 ];
1024- const size_t currentExecLine = _currentExecLine; // v 5.1.7
1026+ const size_t currentExecLine = _currentExecLine;
10251027 while ((true == stream.good ( )) && (false == stream.eof ( )))
10261028 {
10271029 memset (buffer, ' \0 ' , 10001 );
@@ -1240,17 +1242,18 @@ void QtPythonConsole::validateCursorPosition ( )
12401242 block = document ( )->lastBlock ( );
12411243 cursor.movePosition (QTextCursor::EndOfBlock, QTextCursor::MoveAnchor);
12421244 cursor = textCursor ( );
1243- // Les 2 instructions suivantes sont nécessaires pour que les
1244- // lignes ajoutées ne soient pas en mode "exécutées" :
1245+ // Les 2 instructions suivantes sont nécessaires pour que les lignes ajoutées ne soient pas en mode "exécutées" :
12451246 cursor.setBlockFormat (defaultBlockFormat);
1247+ setCurrentCharFormat (defaultCharFormat);
12461248 appendPlainText (" " );
12471249 }
12481250 } // if (_currentExecLine > document ( )->blockCount ( ))
12491251 else
12501252 {
12511253 block = document ( )->findBlockByNumber (_currentExecLine - 1 );
12521254 cursor.setPosition (block.position ( ), QTextCursor::MoveAnchor);
1253- cursor.setBlockFormat (defaultBlockFormat);
1255+ // cursor.setCharFormat (defaultCharFormat); // v 6.4.1
1256+ // cursor.setBlockFormat (defaultBlockFormat); // v 6.4.1
12541257 } // else if (_currentExecLine > document ( )->blockCount ( ))
12551258 }
12561259 catch (...)
@@ -1568,29 +1571,39 @@ void QtPythonConsole::lineProcessedCallback (size_t line, bool ok, const string&
15681571 {
15691572 if (false == isComment)
15701573 {
1571- // Tant que les lignes précédentes sont des commentaires on les récupère pour les ajouter au fichier script.
1572- QTextBlockFormat bformat = block.blockFormat ( ); // v6.4.1
1573- bformat.setBackground (true == ok ? QtScriptTextFormat::ranInstructionFormat.background ( ) : QtScriptTextFormat::failedInstructionFormat.background ( )); // v 6.4.1
1574+ // Tant que les lignes précédentes sont des commentaires on les récupère pour les ajouter au fichier script + colorisation dans la console :
15741575 UTF8String comments (Charset::UTF_8);
15751576 size_t bl = true == isComment ? line - 1 : line - 2 ;
15761577 bool stopped = 2 > bl ? true : false ;
15771578 while (false == stopped)
15781579 {
1579- const QTextBlock b = document ()->findBlockByNumber (bl);
1580- const string l = b.text ( ).toStdString ( );
1580+ const QTextBlock b = document ()->findBlockByNumber (bl);
1581+ const string l = b.text ( ).toStdString ( );
1582+ bool colorize = true ; // v 6.4.1. Coloriser la console couleur "déjà joué" ?
1583+
15811584 if ((true == l.empty ( )) || (' #' != l [0 ]) || (bl <= 0 ))
15821585 {
1586+ if (false == l.empty ( ))
1587+ colorize = false ;
15831588 stopped = true ;
15841589 bl = bl < line - 1 ? bl + 1 : line - 1 ;
15851590 }
15861591 else
15871592 {
1588- QTextCursor cursor (b); // v 6.4.1
1589- cursor.select (QTextCursor::LineUnderCursor); // v 6.4.1
1590-
1591- cursor.setBlockFormat (bformat); // v 6.4.1
15921593 bl--;
15931594 } // else if ((true == l.empty ( )) || ('#' != l [0]) || (bl <= 0))
1595+
1596+ if (true == colorize) // v 6.4.1
1597+ {
1598+ QTextCursor cursor (b);
1599+ QTextBlockFormat commentBlockFormat = b.blockFormat ( );
1600+ QTextCharFormat commentCharFormat = b.charFormat ( );
1601+ cursor.select (QTextCursor::LineUnderCursor);
1602+ commentBlockFormat.setBackground (QtScriptTextFormat::ranInstructionFormat.background ( ));
1603+ commentCharFormat.setBackground (QtScriptTextFormat::ranInstructionFormat.background ( ));
1604+ cursor.setBlockFormat (commentBlockFormat);
1605+ cursor.setCharFormat (commentCharFormat);
1606+ } // if (true == colorize)
15941607 } // while (false == stopped)
15951608 for (size_t i = bl; i < line - 1 ; i++)
15961609 {
@@ -1605,19 +1618,24 @@ void QtPythonConsole::lineProcessedCallback (size_t line, bool ok, const string&
16051618 getLogDispatcher ( ).log (ScriptingLog (instruction, comments));
16061619 } // if (false == isComment)
16071620 } // if (line >= maxExecLine ( ))
1621+ QTextCharFormat cformat = block.charFormat ( ); // v 6.4.1
16081622 QTextBlockFormat bformat = block.blockFormat ( );
16091623 bformat.setProperty (QTextFormat::FullWidthSelection, true );
1624+ cformat.setBackground (true == ok ? QtScriptTextFormat::ranInstructionFormat.background ( ) : QtScriptTextFormat::failedInstructionFormat.background ( )); // v 6.4.1
16101625 bformat.setBackground (true == ok ? QtScriptTextFormat::ranInstructionFormat.background ( ) : QtScriptTextFormat::failedInstructionFormat.background ( ));
16111626 QTextCursor cursor (block); // v 6.4.1
16121627 cursor.select (QTextCursor::LineUnderCursor); // v 6.4.1 why BlockUnderCursor does not work ???
1628+ cursor.setCharFormat (cformat);
16131629 cursor.setBlockFormat (bformat);
16141630
16151631 if (true == cursor.atEnd ( ))
16161632 {
16171633 cursor.clearSelection ( );
16181634 QTextBlockFormat newformat = block.blockFormat ( );
1619- bformat .setBackground (QtScriptTextFormat::emptyLineFormat.background ( ));
1635+ newformat .setBackground (QtScriptTextFormat::emptyLineFormat.background ( )); // v 6.4.1
16201636 cursor.setBlockFormat (newformat);
1637+ cformat.setBackground (QtScriptTextFormat::emptyLineFormat.background ( )); // v 6.4.1
1638+ cursor.setCharFormat (cformat); // v 6.4.1
16211639 cursor.insertBlock (newformat, QtScriptTextFormat::emptyLineFormat);
16221640 } // if (true == cursor.atEnd ( ))
16231641 addToHistoric (instruction);
@@ -2346,7 +2364,6 @@ size_t QtPythonConsole::followingInstruction (size_t line) const
23462364void QtPythonConsole::addInstruction (const string& instruction)
23472365{
23482366 // Un instruction en cours est peut être à compléter :
2349- const size_t pendingLinesCount = Instruction (_pendingString).lineCount ( ); // v 6.4.1
23502367 _pendingString += instruction;
23512368
23522369 // Commentaire, ligne blanche, ... : on ajoute et on passe à la suite.
@@ -2396,7 +2413,7 @@ void QtPythonConsole::addInstruction (const string& instruction)
23962413
23972414void QtPythonConsole::execInstructions ( )
23982415{
2399- // EndOfDocCursor endOfDocCursor (*this); 241
2416+ // EndOfDocCursor endOfDocCursor (*this); v 6.4.1
24002417
24012418 setRunningMode (QtPythonConsole::RM_CONTINUOUS);
24022419 _running = true ;
0 commit comments