Skip to content
Permalink
Browse files

improve handling of (raw) input in Python console

  • Loading branch information...
wwmayer committed Jan 4, 2019
1 parent 2c838bf commit 64fa8cb855e629ada81ccba85cc337fa4a9e6de8
Showing with 19 additions and 11 deletions.
  1. +19 −11 src/Gui/PythonConsole.cpp
@@ -578,6 +578,9 @@ void PythonConsole::keyPressEvent(QKeyEvent * e)
QTextBlock inputBlock = inputLineBegin.block(); //< get the last paragraph's text
QString inputLine = inputBlock.text();
QString inputStrg = stripPromptFrom( inputLine );
if (this->_sourceDrain && !this->_sourceDrain->isEmpty()) {
inputStrg = inputLine.mid(this->_sourceDrain->length());
}

switch (e->key())
{
@@ -1047,15 +1050,18 @@ void PythonConsole::insertFromMimeData (const QMimeData * source)
}
}

QTextCursor PythonConsole::inputBegin( void ) const
{
// construct cursor at begin of input line ...
QTextCursor inputLineBegin( this->textCursor() );
inputLineBegin.movePosition( QTextCursor::End );
inputLineBegin.movePosition( QTextCursor::StartOfBlock );
// ... and move cursor right beyond the prompt.
inputLineBegin.movePosition( QTextCursor::Right, QTextCursor::MoveAnchor, promptLength( inputLineBegin.block().text() ) );
return inputLineBegin;
QTextCursor PythonConsole::inputBegin(void) const
{
// construct cursor at begin of input line ...
QTextCursor inputLineBegin(this->textCursor());
inputLineBegin.movePosition(QTextCursor::End);
inputLineBegin.movePosition(QTextCursor::StartOfBlock);
// ... and move cursor right beyond the prompt.
int prompt = promptLength(inputLineBegin.block().text());
if (this->_sourceDrain && !this->_sourceDrain->isEmpty())
prompt = this->_sourceDrain->length();
inputLineBegin.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, prompt);
return inputLineBegin;
}

QMimeData * PythonConsole::createMimeDataFromSelection () const
@@ -1333,9 +1339,11 @@ void PythonConsole::onCopyCommand()
QString PythonConsole::readline( void )
{
QEventLoop loop;
QString inputBuffer;
// output is set to the current prompt which we need to extract
// the actual user input
QString inputBuffer = d->output;

printPrompt( PythonConsole::Special );
printPrompt(PythonConsole::Special);
this->_sourceDrain = &inputBuffer; //< enable source drain ...
// ... and wait until we get notified about pendingSource
QObject::connect( this, SIGNAL(pendingSource()), &loop, SLOT(quit()) );

0 comments on commit 64fa8cb

Please sign in to comment.
You can’t perform that action at this time.