@@ -37,9 +37,7 @@ USE_ENCODING_AUTODETECTION
3737
3838
3939
40- /* On utilise la fonction python builtin execfile pour exécuter sous Pdb
41- * des fichiers. Fonctionne bien avec Python 2.6 et 2.7, Pdb s'arrête bien aux
42- * points d'arrêt demandés.
40+ /* On utilise la fonction python builtin execfile pour exécuter sous Pdb des fichiers. Fonctionne bien avec Python 2.6 et 2.7, Pdb s'arrête bien aux points d'arrêt demandés.
4341 * Pb : cette fonction n'existe plus en Python 3.x, il faudra la réécrire.
4442 */
4543// #define USE_EXECFILE_PYTHON_FUNCTION 1
@@ -383,9 +381,7 @@ void QtPythonConsole::InstructionsFile::addLines (const vector<string>& lines, s
383381 throw exc;
384382 } // if (0 == _tmpStream.get ( ))
385383
386- // Attention : on peut appeler addLines plusieurs fois pour le même
387- // script ... _firstLineNum sert ensuite pour faire les conversions
388- // num script <-> num fichier
384+ // Attention : on peut appeler addLines plusieurs fois pour le même script ... _firstLineNum sert ensuite pour faire les conversions num script <-> num fichier
389385 if (0 == _firstLineNum)
390386 _firstLineNum = firstLineNum;
391387 for (vector<string>::const_iterator it = lines.begin ( ); lines.end ( ) != it; it++)
@@ -585,7 +581,6 @@ const QSize QtPythonConsole::iconSize (32, 32);
585581bool QtPythonConsole::_catchStdOutputs = true ;
586582
587583static QTextBlockFormat defaultBlockFormat;
588- static QTextCharFormat defaultCharFormat;
589584static QBrush defaultBackground;
590585
591586
@@ -755,7 +750,6 @@ QtPythonConsole::QtPythonConsole (QWidget* parent, const string& appName)
755750{
756751 setCenterOnScroll (true );
757752 QTextCursor cursor = textCursor ( );
758- defaultCharFormat = cursor.charFormat ( );
759753 defaultBlockFormat = cursor.blockFormat ( );
760754 defaultBackground = defaultBlockFormat.background ( );
761755
@@ -945,11 +939,9 @@ void QtPythonConsole::drawLinesNumbers (const QRect& rect)
945939 {
946940 if ((true == block.isVisible ( )) && (bottom >= rect.top ( )))
947941 {
948- // Rem : sous Qt 4.7.4 la surimpression (breakpoint, et par dessus
949- // ligne actuelle) ne fonctionne pas ... (pixmap ? autre ?)
942+ // Rem : sous Qt 4.7.4 la surimpression (breakpoint, et par dessus ligne actuelle) ne fonctionne pas ... (pixmap ? autre ?)
950943 // => on n'affiche pas le BP si ligne courrante.
951- if ((_breakpoints.end ( ) != _breakpoints.find (number)) &&
952- (currentInstruction ( ) != number))
944+ if ((_breakpoints.end ( ) != _breakpoints.find (number)) && (currentInstruction ( ) != number))
953945 {
954946 _breakPointIcon.paint (&painter, 3 , top, width, height);
955947 } // if (_breakpoints.end ( ) != _breakpoints.find (number))
@@ -1021,8 +1013,7 @@ void QtPythonConsole::insert (const string& fileName, string& warnings)
10211013// streamCharset = Charset::UNKNOWN == streamCharset ? Charset::ASCII : streamCharset;
10221014 streamCharset = Charset::UNKNOWN == streamCharset ? Charset::UTF_8 : streamCharset; // v 5.1.7, éviter un rejet de conversion si caractère accentué
10231015
1024- // UTF-16 : les sauts de ligne ne sont pas des \n => réécrire différemment
1025- // la lecture du fichier.
1016+ // UTF-16 : les sauts de ligne ne sont pas des \n => réécrire différemment la lecture du fichier.
10261017 if (Charset::UTF_16 == streamCharset)
10271018 throw Exception (" Encodage UTF-16 non supporté dans cette version." );
10281019
@@ -1252,15 +1243,13 @@ void QtPythonConsole::validateCursorPosition ( )
12521243 // Les 2 instructions suivantes sont nécessaires pour que les
12531244 // lignes ajoutées ne soient pas en mode "exécutées" :
12541245 cursor.setBlockFormat (defaultBlockFormat);
1255- setCurrentCharFormat (defaultCharFormat);
12561246 appendPlainText (" " );
12571247 }
12581248 } // if (_currentExecLine > document ( )->blockCount ( ))
12591249 else
12601250 {
12611251 block = document ( )->findBlockByNumber (_currentExecLine - 1 );
12621252 cursor.setPosition (block.position ( ), QTextCursor::MoveAnchor);
1263- cursor.setCharFormat (defaultCharFormat);
12641253 cursor.setBlockFormat (defaultBlockFormat);
12651254 } // else if (_currentExecLine > document ( )->blockCount ( ))
12661255 }
@@ -1568,7 +1557,7 @@ void QtPythonConsole::lineProcessedCallback (size_t line, bool ok, const string&
15681557 // Gérer les sorties du script python :
15691558 processPythonOutputs ( );
15701559 if (true == _checkingCompletion)
1571- return ; // v 5.3.0
1560+ return ;
15721561
15731562 // Cette ligne a été jouée (rem : les numéros Qt commencent à 0 ...) :
15741563 QTextBlock block = document ( )->findBlockByNumber (line-1 );
@@ -1580,6 +1569,8 @@ void QtPythonConsole::lineProcessedCallback (size_t line, bool ok, const string&
15801569 if (false == isComment)
15811570 {
15821571 // 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
15831574 UTF8String comments (Charset::UTF_8);
15841575 size_t bl = true == isComment ? line - 1 : line - 2 ;
15851576 bool stopped = 2 > bl ? true : false ;
@@ -1593,7 +1584,13 @@ void QtPythonConsole::lineProcessedCallback (size_t line, bool ok, const string&
15931584 bl = bl < line - 1 ? bl + 1 : line - 1 ;
15941585 }
15951586 else
1587+ {
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
15961592 bl--;
1593+ } // else if ((true == l.empty ( )) || ('#' != l [0]) || (bl <= 0))
15971594 } // while (false == stopped)
15981595 for (size_t i = bl; i < line - 1 ; i++)
15991596 {
@@ -1608,40 +1605,26 @@ void QtPythonConsole::lineProcessedCallback (size_t line, bool ok, const string&
16081605 getLogDispatcher ( ).log (ScriptingLog (instruction, comments));
16091606 } // if (false == isComment)
16101607 } // if (line >= maxExecLine ( ))
1611- // QTextCharFormat : zone avec du texte
1612- // QTextBlockFormat : le reste du bloc
1613- QTextCharFormat cformat = block.charFormat ( );
16141608 QTextBlockFormat bformat = block.blockFormat ( );
1615- cformat.setProperty (QTextFormat::FullWidthSelection, true );
16161609 bformat.setProperty (QTextFormat::FullWidthSelection, true );
1617- cformat.setBackground (true == ok ? QtScriptTextFormat::ranInstructionFormat.background ( ) : QtScriptTextFormat::failedInstructionFormat.background ( ));
1618- bformat.setBackground ( true == ok ? QtScriptTextFormat::ranInstructionFormat.background ( ) : QtScriptTextFormat::failedInstructionFormat.background ( ));
1619- QTextCursor cursor = textCursor ( );
1620- const int position= cursor.position ( );
1621- cursor.setPosition (block.position ( ), QTextCursor::MoveAnchor);
1622- cursor.select (QTextCursor::BlockUnderCursor);
1623- cursor.setCharFormat (cformat); // v 5.0.0
1624- cursor.setBlockFormat (bformat); // v 5.0.0
1610+ bformat.setBackground (true == ok ? QtScriptTextFormat::ranInstructionFormat.background ( ) : QtScriptTextFormat::failedInstructionFormat.background ( ));
1611+ QTextCursor cursor (block); // v 6.4.1
1612+ cursor.select (QTextCursor::LineUnderCursor); // v 6.4.1 why BlockUnderCursor does not work ???
1613+ cursor.setBlockFormat (bformat);
1614+
16251615 if (true == cursor.atEnd ( ))
16261616 {
16271617 cursor.clearSelection ( );
16281618 QTextBlockFormat newformat = block.blockFormat ( );
16291619 bformat.setBackground (QtScriptTextFormat::emptyLineFormat.background ( ));
1630- // cursor.insertBlock (newformat, QtScriptTextFormat::emptyLineFormat);
16311620 cursor.setBlockFormat (newformat);
1632- cursor.setCharFormat (QtScriptTextFormat::emptyLineFormat);
16331621 cursor.insertBlock (newformat, QtScriptTextFormat::emptyLineFormat);
1634- // appendPlainText (""); // v 5.0.0
16351622 } // if (true == cursor.atEnd ( ))
16361623 addToHistoric (instruction);
1637- // cursor.setCharFormat (cformat); // v 5.0.0
1638- // cursor.setBlockFormat (bformat); // v 5.0.0
16391624 cursor.clearSelection ( );
16401625 // On en profite pour s'assurer que la ligne courante est visible :
16411626 setTextCursor (cursor);
16421627 ensureCursorVisible ( );
1643- // On se repositionne là où on était :
1644- cursor.setPosition (position, QTextCursor::MoveAnchor);
16451628
16461629 // On passe à la ligne suivante :
16471630 _maxExecLine = line > _maxExecLine ? line : _maxExecLine;
@@ -1736,7 +1719,6 @@ void QtPythonConsole::addToHistoric (
17361719 } // if (linesCount > 1)
17371720
17381721 size_t line = currentInstruction ( );
1739- // if ((false == isRunning ( )) || (true == isExecutingFile ( )))
17401722 if ((false == isRunning ( )) || ((true == isExecutingFile ( )) && (QtPythonConsole::RM_DEBUG != _runningMode))) // v 5.0.5, en mode debug l'exécution de la console passe par un fichier ...
17411723 {
17421724 if (line < currentInstruction ( )) // Eviter de réécrire les boucles
@@ -1786,7 +1768,6 @@ void QtPythonConsole::addToHistoric (
17861768 QTextCharFormat defaultBlockCharFormat = cursor.blockCharFormat ( );
17871769 defaultBlockCharFormat.setBackground (defaultBackground);
17881770 cursor.setBlockCharFormat (defaultBlockCharFormat);
1789- setCurrentCharFormat (defaultCharFormat);
17901771 line += lineNumber (scriptingLog.getText ( ).utf8 ( )) - 1 ;
17911772 cursor.insertText (UTF8TOQSTRING (scriptingLog.getText ( )));
17921773 cursor.insertText (" \n " );
@@ -1803,13 +1784,9 @@ void QtPythonConsole::addToHistoric (
18031784 QTextCursor cursor = textCursor ( );
18041785 cursor.setPosition (block.position ( ), QTextCursor::MoveAnchor);
18051786 cursor.movePosition (QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
1806- QTextCharFormat charFormat = cursor.charFormat ( );
1807- charFormat.setBackground (QtScriptTextFormat::failedInstructionFormat.background ( ));
1808- cursor.setCharFormat (charFormat);
18091787 cursor.movePosition (QTextCursor::EndOfBlock, QTextCursor::MoveAnchor);
18101788 setTextCursor (cursor);
18111789 cursor.setBlockFormat (defaultBlockFormat);
1812- setCurrentCharFormat (defaultCharFormat);
18131790 setTextCursor (cursor);
18141791
18151792 // Faut-il arrêter l'exécution du script ?
@@ -2036,10 +2013,8 @@ bool QtPythonConsole::handleDownKeyPress (QKeyEvent& event)
20362013 if (currentLine != instruction)
20372014 {
20382015 QTextCursor cursor = textCursor ( );
2039- // cursor.movePosition (QTextCursor::StartOfLine);
2040- // cursor.movePosition (QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
2041- cursor.movePosition (QTextCursor::StartOfBlock); // v 5.0.0
2042- cursor.movePosition (QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); // v 5.0.0
2016+ cursor.movePosition (QTextCursor::StartOfBlock);
2017+ cursor.movePosition (QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
20432018 cursor.insertText (instruction.c_str ( ));
20442019 } // if (currentLine != instruction)
20452020 } // if (_historyIndex < size)
@@ -2068,10 +2043,8 @@ bool QtPythonConsole::handleUpKeyPress (QKeyEvent& event)
20682043 if (currentLine != instruction)
20692044 {
20702045 QTextCursor cursor = textCursor ( );
2071- // cursor.movePosition (QTextCursor::StartOfLine);
2072- // cursor.movePosition (QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
2073- cursor.movePosition (QTextCursor::StartOfBlock); // v 5.0.0
2074- cursor.movePosition (QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); // v 5.0.0
2046+ cursor.movePosition (QTextCursor::StartOfBlock);
2047+ cursor.movePosition (QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
20752048 cursor.insertText (instruction.c_str ( ));
20762049 } // if (currentLine != instruction)
20772050 } // if (_historyIndex < _history.count ( ))
@@ -2131,8 +2104,7 @@ bool QtPythonConsole::handleComplete (QKeyEvent& event)
21312104 try
21322105 {
21332106 UTF8String request (charset);
2134- // request << "NECCompletionSession.instance ( ).complete ('" << editedInstruction ( ) << "'," << i << ")";
2135- request << " NECCompletionSession.instance ( ).complete ('" << trimedInstruction << " '," << i << " )" ; // v 5.3.0
2107+ request << " NECCompletionSession.instance ( ).complete ('" << trimedInstruction << " '," << i << " )" ;
21362108
21372109 PyCompilerFlags flags;
21382110// flags.cf_flags = CO_FUTURE_DIVISION;
@@ -2205,13 +2177,12 @@ bool QtPythonConsole::handleComplete (QKeyEvent& event)
22052177 cmps.insert (completions.begin ( ), completions.end ( ));
22062178 for (set<string>::const_iterator it = cmps.begin ( ); cmps.end ( ) != it; it++)
22072179 {
2208- // _completionComboBox->addItem ((*it).c_str ( )); // v 5.3.0
22092180 UTF8String completion (charset);
22102181 if ((size_t )-1 != equalPos) // => A = ...
22112182 completion = left + head.utf8 ( )+ *it + tail.utf8 ( );
22122183 else
22132184 completion = head.utf8 ( )+ *it + tail.utf8 ( );
2214- _completionComboBox->addItem (completion.utf8 ( ).c_str ( )); // v 5.3.0
2185+ _completionComboBox->addItem (completion.utf8 ( ).c_str ( ));
22152186 } // for (set<string>::const_iterator it = cmps.begin ( ); cmps.end ( ) != it; it++)
22162187 _completionComboBox->setCurrentIndex (0 );
22172188 _completionComboBox->setGeometry (rect);
@@ -2226,8 +2197,8 @@ bool QtPythonConsole::handleComplete (QKeyEvent& event)
22262197 catch (...)
22272198 {
22282199 }
2229- _currentExecLine = currentLine; // v 5.3.0 déplacé par mécanisme de complétion
2230- _previousExecLine = _checkingCompletion; // v 5.3.0
2200+ _currentExecLine = currentLine;
2201+ _previousExecLine = _checkingCompletion;
22312202 _checkingCompletion = false ;
22322203 } // if (0 != completions.size ( ))
22332204
@@ -2237,7 +2208,7 @@ bool QtPythonConsole::handleComplete (QKeyEvent& event)
22372208
22382209void QtPythonConsole::addToHistoric (const string& instruction)
22392210{ // On ne stocke pas 2 fois successivement la même instruction
2240- if (true == _checkingCompletion) // v 5.3.0
2211+ if (true == _checkingCompletion)
22412212 return ;
22422213
22432214 const size_t size = _history.size ( );
@@ -2375,8 +2346,9 @@ size_t QtPythonConsole::followingInstruction (size_t line) const
23752346void QtPythonConsole::addInstruction (const string& instruction)
23762347{
23772348 // Un instruction en cours est peut être à compléter :
2349+ const size_t pendingLinesCount = Instruction (_pendingString).lineCount ( ); // v 6.4.1
23782350 _pendingString += instruction;
2379-
2351+
23802352 // Commentaire, ligne blanche, ... : on ajoute et on passe à la suite.
23812353 bool completed = false ;
23822354 if ((0 == _pendingString.size ( )) || (' #' == _pendingString [0 ]))
@@ -2400,11 +2372,10 @@ void QtPythonConsole::addInstruction (const string& instruction)
24002372 }
24012373 } // if (false == completed)
24022374 else
2403- { // v 5.1.5 : cas de l'insertion d'un commentaire multiligne. A noter qu'un bogue subsiste et qu'on peut
2404- // observer un décalage entre commentaires et instructions associées.
2375+ { // v 5.1.5 : cas de l'insertion d'un commentaire multiligne. A noter qu'un bogue subsiste et qu'on peut observer un décalage entre commentaires et instructions associées.
24052376 if ((0 != _pendingString.size ( )) && (' #' == _pendingString [0 ]))
24062377 {
2407- _pendingString = ' \n ' + _pendingString;
2378+ // _pendingString = '\n' + _pendingString; v 6.4.1
24082379 const size_t count = Instruction (_pendingString).lineCount ( );
24092380 _currentExecLine += count;
24102381 } // if ((0 != _pendingString.size ( )) && ('#' == _pendingString [0]))
@@ -2413,7 +2384,6 @@ void QtPythonConsole::addInstruction (const string& instruction)
24132384 if (true == completed)
24142385 {
24152386 Instruction ins (_pendingString);
2416- setCurrentCharFormat (QtPythonConsole::QtScriptTextFormat::textFormat (ins));
24172387 _pendingString += ' \n ' ;
24182388 insertPlainText (QString::fromUtf8 (_pendingString.c_str ( )));
24192389 _pendingString.clear ( );
@@ -2426,7 +2396,7 @@ void QtPythonConsole::addInstruction (const string& instruction)
24262396
24272397void QtPythonConsole::execInstructions ( )
24282398{
2429- EndOfDocCursor endOfDocCursor (*this );
2399+ // EndOfDocCursor endOfDocCursor (*this); 241
24302400
24312401 setRunningMode (QtPythonConsole::RM_CONTINUOUS);
24322402 _running = true ;
@@ -2440,8 +2410,7 @@ void QtPythonConsole::execInstructions ( )
24402410 const bool autoDelete = true ;
24412411 _currentScript.reset (new QtPythonConsole::InstructionsFile (false , " python_panel_script_" , QtPythonConsole::enableCodingIso8859_15, autoDelete));
24422412 _currentScript->addLines (instructions, _currentExecLine);
2443- // 2 cas de figure : une ligne uniquement, on la traite telle que, permet d'avoir dans stdout des retours type "4" pour
2444- // une ligne t.q. "2 + 2".
2413+ // 2 cas de figure : une ligne uniquement, on la traite telle que, permet d'avoir dans stdout des retours type "4" pour une ligne t.q. "2 + 2".
24452414 // C'est le fait d'être en une seule instruction + Py_single_input qui offre cette possibilité là.
24462415 // Pour les autres cas on reste avec Py_file_input qui est dédié aux cas multilignes.
24472416 PyObject* result = 0 ;
@@ -2490,8 +2459,6 @@ void QtPythonConsole::execInstructions ( )
24902459 _running = false ;
24912460 _halted = true ;
24922461
2493- // Actualisation IHM :
2494- const size_t lastAt = ++_currentExecLine;
24952462 _currentScript.reset (0 );
24962463
24972464 validateCursorPosition ( );
@@ -2569,12 +2536,12 @@ void QtPythonConsole::execDbgInstructions (bool stopImmediatly)
25692536 {
25702537 error = exc.getFullMessage ( );
25712538 // addToHistoric ici car il faut false == isRunning ( )
2572- addToHistoric (" " , " " , error, true , false );
2539+ // addToHistoric ("", "", error, true, false); // v 6.4.1
25732540 }
25742541 catch (...)
25752542 {
25762543 // addToHistoric ici car il faut false == isRunning ( )
2577- addToHistoric (" " , " " , error, true , false );
2544+ // addToHistoric ("", "", error, true, false); // v 6.4.1
25782545 error = " Erreur non documentée." ;
25792546 }
25802547 unregisterConsole (*this );
@@ -2628,7 +2595,7 @@ void QtPythonConsole::execInstruction (const string& instruction, bool insert)
26282595 flags.cf_flags = 0 ;
26292596 PyObject* result = 0 ;
26302597
2631- registerConsole (*this ); // CP v 5.0.5
2598+ registerConsole (*this );
26322599 try
26332600 { // gérer les erreurs C++ de l'API appelée
26342601 result = PyRun_StringFlags (instruction.c_str ( ), Py_file_input, _globalDict, _localDict, &flags);
@@ -2638,7 +2605,7 @@ void QtPythonConsole::execInstruction (const string& instruction, bool insert)
26382605 if ((QtPythonConsole::RM_DEBUG == getRunningMode ( )) && (0 != _runningModeAction))
26392606 _runningModeAction->setChecked (false );
26402607 }
2641- unregisterConsole (*this ); // CP v 5.0.5
2608+ unregisterConsole (*this );
26422609
26432610 processPythonOutputs ( );
26442611
@@ -2652,11 +2619,6 @@ void QtPythonConsole::execInstruction (const string& instruction, bool insert)
26522619 throw Exception (error);
26532620 } // if (0 != retCode)
26542621 Py_DECREF (result);
2655-
2656- // Actualisation IHM :
2657- // v 5.0.5 : déjà appelé via tracePythonExecution
2658- // if (true == insert)
2659- // lineProcessedCallback (_currentExecLine, true, string ( ));
26602622} // QtPythonConsole::execInstruction
26612623
26622624
@@ -3035,6 +2997,7 @@ void QtPythonConsole::cursorPositionCallback ( )
30352997 try
30362998 {
30372999 QtTextEditor::cursorPositionCallback ( ); // presumed no throw
3000+ validateCursorPosition ( ); // v 6.4.1 : s'assurer qu'il y a au moins un point d'insertion de texte (ex : suite backspace sur la seule ligne éditable)
30383001 updateActions ( );
30393002 }
30403003 catch (...)
0 commit comments