35 from python_qt_binding.QtCore
import Qt
36 from python_qt_binding.QtGui
import QFont
37 from python_qt_binding.QtWidgets
import QTextEdit
41 _color_stdout = Qt.blue
42 _color_stderr = Qt.red
43 _color_stdin = Qt.black
44 _multi_line_char =
'\\'
45 _multi_line_indent =
' '
62 super(ConsoleTextEdit, self).
__init__(parent)
63 self.setFont(QFont(
'Mono'))
90 length = len(self.document().lastBlock().text()[prompt_length:])
95 for _
in range(length):
96 self.textCursor().deletePreviousChar()
109 raise NotImplementedError
112 old_out, old_err = sys.stdout, sys.stderr
115 sys.stdout, sys.stderr = old_out, old_err
119 block_length = self.document().lastBlock().length()
120 document_length = self.document().characterCount()
121 line_start = document_length - block_length
122 prompt_position = line_start + prompt_length
125 if self.textCursor().position() >= prompt_position:
126 if event.key() == Qt.Key_Down:
132 if event.key() == Qt.Key_Up:
136 if event.key()
in [Qt.Key_Backspace]:
138 if (self.textCursor().positionInBlock() == prompt_length
and
139 not self.textCursor().hasSelection()):
142 if event.key()
in [Qt.Key_Return, Qt.Key_Enter]:
144 cursor = self.textCursor()
145 cursor.setPosition(document_length - 1)
146 self.setTextCursor(cursor)
149 line = str(self.document().lastBlock().text())[
150 prompt_length:].rstrip()
152 self.insertPlainText(
'\n')
181 if line_start <= self.textCursor().position() < prompt_position:
182 cursor = self.textCursor()
183 cursor.setPosition(prompt_position)
184 self.setTextCursor(cursor)