Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add qt config option to clear_on_kernel_restart #1681

Merged
merged 4 commits into from May 16, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 23 additions & 7 deletions IPython/frontend/qt/console/frontend_widget.py
Expand Up @@ -95,6 +95,9 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):
enable_calltips = Bool(True, config=True,
help="Whether to draw information calltips on open-parentheses.")

clear_on_kernel_restart = Bool(True, config=True,
help="Whether to clear the console when the kernel is restarted")

# Emitted when a user visible 'execute_request' has been submitted to the
# kernel from the FrontendWidget. Contains the code to be executed.
executing = QtCore.Signal(object)
Expand Down Expand Up @@ -516,6 +519,8 @@ def _handle_shutdown_reply(self, msg):
if reply == QtGui.QMessageBox.Yes:
self.exit_requested.emit(self)
else:
# XXX: remove message box in favor of using the
# clear_on_kernel_restart setting?
reply = QtGui.QMessageBox.question(self, title,
"Kernel has been reset. Clear the Console?",
QtGui.QMessageBox.Yes,QtGui.QMessageBox.No)
Expand All @@ -529,7 +534,7 @@ def _started_channels(self):
""" Called when the KernelManager channels have started listening or
when the frontend is assigned an already listening KernelManager.
"""
self.reset()
self.reset(clear=True)

#---------------------------------------------------------------------------
# 'FrontendWidget' public interface
Expand Down Expand Up @@ -563,18 +568,29 @@ def interrupt_kernel(self):
self._append_plain_text('Kernel process is either remote or '
'unspecified. Cannot interrupt.\n')

def reset(self):
""" Resets the widget to its initial state. Similar to ``clear``, but
also re-writes the banner and aborts execution if necessary.
def reset(self, clear=False):
""" Resets the widget to its initial state if ``clear`` parameter or
``clear_on_kernel_restart`` configuration setting is True, otherwise
prints a visual indication of the fact that the kernel restarted, but
does not clear the traces from previous usage of the kernel before it
was restarted. With ``clear=True``, it is similar to ``%clear``, but
also re-writes the banner and aborts execution if necessary.
"""
if self._executing:
self._executing = False
self._request_info['execute'] = {}
self._reading = False
self._highlighter.highlighting_on = False

self._control.clear()
self._append_plain_text(self.banner)
if self.clear_on_kernel_restart or clear:
self._control.clear()
self._append_plain_text(self.banner)
else:
self._append_plain_text("# restarting kernel...")
self._append_html("<hr><br>")
# XXX: Reprinting the full banner may be too much, but once #1680 is
# addressed, that will mitigate it.
#self._append_plain_text(self.banner)
# update output marker for stdout/stderr, so that startup
# messages appear after banner:
self._append_before_prompt_pos = self._get_cursor().position()
Expand Down Expand Up @@ -693,7 +709,7 @@ def _process_execute_error(self, msg):
self._append_plain_text(traceback)

def _process_execute_ok(self, msg):
""" Process a reply for a successful execution equest.
""" Process a reply for a successful execution request.
"""
payload = msg['content']['payload']
for item in payload:
Expand Down