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 =
' ' 55 old_color = self._text_edit.textColor()
56 self._text_edit.setTextColor(self.
_color)
57 self._text_edit.insertPlainText(line)
58 self._text_edit.setTextColor(old_color)
59 self._text_edit.ensureCursorVisible()
62 super(ConsoleTextEdit, self).
__init__(parent)
63 self.setFont(QFont(
'Mono'))
78 self._comment_writer.write(msg +
'\n')
82 self._comment_writer.write(
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')
157 self._history.insert(0, line)
181 if line_start <= self.textCursor().position() < prompt_position:
182 cursor = self.textCursor()
183 cursor.setPosition(prompt_position)
184 self.setTextCursor(cursor)
def keyPressEvent(self, event)
string _multi_line_indent
def _exec_with_captured_output(self, code)
def _clear_current_line(self, clear_prompt=False)
def _move_in_history(self, delta)
def __init__(self, parent=None)
def print_message(self, msg)
def __init__(self, text_edit, color)
def _exec_code(self, code)