Skip to content

Commit

Permalink
Merge e1aac80 into 3748cb7
Browse files Browse the repository at this point in the history
  • Loading branch information
impact27 committed Aug 29, 2019
2 parents 3748cb7 + e1aac80 commit 127b751
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
32 changes: 22 additions & 10 deletions qtconsole/console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,16 +642,7 @@ def do_execute(self, source, complete, indent):
self._append_plain_text('\n')
self._input_buffer_executing = self.input_buffer
self._executing = True
self._prompt_finished()

# The maximum block count is only in effect during execution.
# This ensures that _prompt_pos does not become invalid due to
# text truncation.
self._control.document().setMaximumBlockCount(self.buffer_size)

# Setting a positive maximum block count will automatically
# disable the undo/redo history, but just to be safe:
self._control.setUndoRedoEnabled(False)
self._finalize_input_request()

# Perform actual execution.
self._execute(source, False)
Expand All @@ -677,6 +668,27 @@ def export_html(self):
"""
self._html_exporter.export()

def _finalize_input_request(self):
"""
Set the widget to a non-reading state.
"""
# Must set _reading to False before calling _prompt_finished
self._reading = False
self._prompt_finished()

# There is no prompt now, so before_prompt_position is eof
self._append_before_prompt_cursor.setPosition(
self._get_end_cursor().position())

# The maximum block count is only in effect during execution.
# This ensures that _prompt_pos does not become invalid due to
# text truncation.
self._control.document().setMaximumBlockCount(self.buffer_size)

# Setting a positive maximum block count will automatically
# disable the undo/redo history, but just to be safe:
self._control.setUndoRedoEnabled(False)

def _get_input_buffer(self, force=False):
""" The text that the user has entered entered at the current prompt.
Expand Down
1 change: 1 addition & 0 deletions qtconsole/frontend_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ def _handle_input_request(self, msg):
self.kernel_client.iopub_channel.flush()

def callback(line):
self._finalize_input_request()
self.kernel_client.input(line)
if self._reading:
self.log.debug("Got second input request, assuming first was interrupted.")
Expand Down
35 changes: 35 additions & 0 deletions qtconsole/tests/test_00_console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,41 @@ def run_line(line, block=True):
assert scroll_bar.value() > prev_position


def test_input(qtconsole, qtbot):
"""
Test input function
"""
window = qtconsole.window
shell = window.active_frontend
control = shell._control

# Wait until the console is fully up
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

with qtbot.waitSignal(shell.executed):
shell.execute("import time")

if sys.version[0] == '2':
input_function = 'raw_input'
else:
input_function = 'input'
shell.execute("print(" + input_function + "('name: ')); time.sleep(3)")

qtbot.waitUntil(lambda: control.toPlainText().split()[-1] == 'name:')

qtbot.keyClicks(control, 'test')
qtbot.keyClick(control, QtCore.Qt.Key_Enter)
qtbot.waitUntil(lambda: not shell._reading)
qtbot.keyClick(control, 'z', modifier=QtCore.Qt.ControlModifier)
for i in range(10):
qtbot.keyClick(control, QtCore.Qt.Key_Backspace)
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

assert 'name: test\ntest' in control.toPlainText()


def test_debug(qtconsole, qtbot):
"""
Make sure the cursor works while debugging
Expand Down

0 comments on commit 127b751

Please sign in to comment.