##// END OF EJS Templates
Aliases fixes: ls alias improvements and frontend-dependent fixes....
Aliases fixes: ls alias improvements and frontend-dependent fixes. Isolated some aliases to the classes that can only run in certain frontends, so we don't try to call 'clear' on the Qt terminal (which doeesn't work).

File last commit:

r3000:df982265
r3003:9ff92aba
Show More
frontend_widget.py
530 lines | 21.7 KiB | text/x-python | PythonLexer
epatters
* Added ability to interrupt a kernel to FrontendWidget...
r2687 # Standard library imports
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 from collections import namedtuple
epatters
* Added ability to interrupt a kernel to FrontendWidget...
r2687 import signal
epatters
Added banners to FrontendWidget and IPythonWidget.
r2714 import sys
epatters
* Added ability to interrupt a kernel to FrontendWidget...
r2687
epatters
Initial checkin of Qt frontend code.
r2602 # System library imports
from pygments.lexers import PythonLexer
from PyQt4 import QtCore, QtGui
# Local imports
epatters
* Added "smart copy" support to FrontendWidget and ConsoleWidget. Tabs are expanded and prompts are stripped....
r2971 from IPython.core.inputsplitter import InputSplitter, transform_classic_prompt
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 from IPython.frontend.qt.base_frontend_mixin import BaseFrontendMixin
epatters
* ConsoleWidget no longer stores contiguous identical lines...
r2969 from IPython.utils.io import raw_print
epatters
First cut at a generic bracket matcher for Q[Plain]TextEdits.
r2894 from IPython.utils.traitlets import Bool
from bracket_matcher import BracketMatcher
epatters
Initial checkin of Qt frontend code.
r2602 from call_tip_widget import CallTipWidget
from completion_lexer import CompletionLexer
epatters
Moved HistoryConsoleWidget to its own file to make console_widget.py a little smaller.
r2983 from history_console_widget import HistoryConsoleWidget
epatters
Fixed imports and removed references to ETS/EPD
r2603 from pygments_highlighter import PygmentsHighlighter
epatters
Initial checkin of Qt frontend code.
r2602
class FrontendHighlighter(PygmentsHighlighter):
epatters
* IPythonWidget now has IPython-style prompts that are futher stylabla via CSS...
r2715 """ A PygmentsHighlighter that can be turned on and off and that ignores
prompts.
epatters
Initial checkin of Qt frontend code.
r2602 """
def __init__(self, frontend):
epatters
Refactored ConsoleWidget to encapsulate, rather than inherit from, QPlainTextEdit. This permits a QTextEdit to be substituted for a QPlainTextEdit if desired. It also makes it more clear what is the public interface of ConsoleWidget.
r2736 super(FrontendHighlighter, self).__init__(frontend._control.document())
epatters
Initial checkin of Qt frontend code.
r2602 self._current_offset = 0
self._frontend = frontend
self.highlighting_on = False
def highlightBlock(self, qstring):
""" Highlight a block of text. Reimplemented to highlight selectively.
"""
epatters
* IPythonWidget now has IPython-style prompts that are futher stylabla via CSS...
r2715 if not self.highlighting_on:
return
# The input to this function is unicode string that may contain
# paragraph break characters, non-breaking spaces, etc. Here we acquire
# the string as plain text so we can compare it.
current_block = self.currentBlock()
string = self._frontend._get_block_plain_text(current_block)
# Decide whether to check for the regular or continuation prompt.
if current_block.contains(self._frontend._prompt_pos):
prompt = self._frontend._prompt
else:
prompt = self._frontend._continuation_prompt
# Don't highlight the part of the string that contains the prompt.
if string.startswith(prompt):
self._current_offset = len(prompt)
qstring.remove(0, len(prompt))
else:
self._current_offset = 0
PygmentsHighlighter.highlightBlock(self, qstring)
epatters
Initial checkin of Qt frontend code.
r2602
epatters
Minor cleanup.
r2825 def rehighlightBlock(self, block):
""" Reimplemented to temporarily enable highlighting if disabled.
"""
old = self.highlighting_on
self.highlighting_on = True
super(FrontendHighlighter, self).rehighlightBlock(block)
self.highlighting_on = old
epatters
Initial checkin of Qt frontend code.
r2602 def setFormat(self, start, count, format):
epatters
* IPythonWidget now has IPython-style prompts that are futher stylabla via CSS...
r2715 """ Reimplemented to highlight selectively.
epatters
Initial checkin of Qt frontend code.
r2602 """
start += self._current_offset
PygmentsHighlighter.setFormat(self, start, count, format)
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):
epatters
* Created an IPythonWidget subclass of FrontendWidget to contain IPython specific functionality....
r2627 """ A Qt frontend for a generic Python kernel.
epatters
Initial checkin of Qt frontend code.
r2602 """
epatters
First cut at allowing the kernel to be restarted from the frontend.
r2851
# An option and corresponding signal for overriding the default kernel
# interrupt behavior.
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 custom_interrupt = Bool(False)
epatters
First cut at allowing the kernel to be restarted from the frontend.
r2851 custom_interrupt_requested = QtCore.pyqtSignal()
epatters
* Improved frontend-side kernel restart support....
r2913 # An option and corresponding signals for overriding the default kernel
epatters
First cut at allowing the kernel to be restarted from the frontend.
r2851 # restart behavior.
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 custom_restart = Bool(False)
epatters
* Improved frontend-side kernel restart support....
r2913 custom_restart_kernel_died = QtCore.pyqtSignal(float)
epatters
First cut at allowing the kernel to be restarted from the frontend.
r2851 custom_restart_requested = QtCore.pyqtSignal()
epatters
* ConsoleWidget now has better support for non-GUI tab completion. Multiple matches are formatted into columns....
r2723
epatters
Minor cleanup and bug fix.
r2771 # Emitted when an 'execute_reply' has been received from the kernel and
# processed by the FrontendWidget.
epatters
* Refactored KernelManager to use Traitlets and to have its channels as attributes...
r2611 executed = QtCore.pyqtSignal(object)
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961
# Emitted when an exit request has been received from the kernel.
exit_requested = QtCore.pyqtSignal()
epatters
First cut at allowing the kernel to be restarted from the frontend.
r2851
# Protected class variables.
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 _CallTipRequest = namedtuple('_CallTipRequest', ['id', 'pos'])
_CompletionRequest = namedtuple('_CompletionRequest', ['id', 'pos'])
_ExecutionRequest = namedtuple('_ExecutionRequest', ['id', 'kind'])
epatters
First cut at a generic bracket matcher for Q[Plain]TextEdits.
r2894 _input_splitter_class = InputSplitter
epatters
* Fixed bug where syntax highlighting was lost after updating a prompt with a bad number....
r2800
epatters
Initial checkin of Qt frontend code.
r2602 #---------------------------------------------------------------------------
epatters
Refactored ConsoleWidget to encapsulate, rather than inherit from, QPlainTextEdit. This permits a QTextEdit to be substituted for a QPlainTextEdit if desired. It also makes it more clear what is the public interface of ConsoleWidget.
r2736 # 'object' interface
epatters
Initial checkin of Qt frontend code.
r2602 #---------------------------------------------------------------------------
epatters
Refactored ConsoleWidget to encapsulate, rather than inherit from, QPlainTextEdit. This permits a QTextEdit to be substituted for a QPlainTextEdit if desired. It also makes it more clear what is the public interface of ConsoleWidget.
r2736 def __init__(self, *args, **kw):
super(FrontendWidget, self).__init__(*args, **kw)
epatters
Initial checkin of Qt frontend code.
r2602
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643 # FrontendWidget protected variables.
epatters
First cut at a generic bracket matcher for Q[Plain]TextEdits.
r2894 self._bracket_matcher = BracketMatcher(self._control)
epatters
Refactored ConsoleWidget to encapsulate, rather than inherit from, QPlainTextEdit. This permits a QTextEdit to be substituted for a QPlainTextEdit if desired. It also makes it more clear what is the public interface of ConsoleWidget.
r2736 self._call_tip_widget = CallTipWidget(self._control)
epatters
Initial checkin of Qt frontend code.
r2602 self._completion_lexer = CompletionLexer(PythonLexer())
epatters
* Added Cut support to ConsoleWidget....
r2990 self._copy_raw_action = QtGui.QAction('Copy (Raw Text)', None)
epatters
* The Qt console frontend now ignores cross chatter from other frontends....
r2824 self._hidden = False
epatters
First cut at a generic bracket matcher for Q[Plain]TextEdits.
r2894 self._highlighter = FrontendHighlighter(self)
Fernando Perez
Rename input modes of input splitter to 'line' and 'block'....
r2862 self._input_splitter = self._input_splitter_class(input_mode='block')
epatters
* Refactored KernelManager to use Traitlets and to have its channels as attributes...
r2611 self._kernel_manager = None
epatters
* Improved frontend-side kernel restart support....
r2913 self._possible_kernel_restart = False
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 self._request_info = {}
epatters
Initial checkin of Qt frontend code.
r2602
epatters
* IPythonWidget now has IPython-style prompts that are futher stylabla via CSS...
r2715 # Configure the ConsoleWidget.
epatters
* ConsoleWidget now has better support for non-GUI tab completion. Multiple matches are formatted into columns....
r2723 self.tab_width = 4
epatters
* IPythonWidget now has IPython-style prompts that are futher stylabla via CSS...
r2715 self._set_continuation_prompt('... ')
epatters
* Added Cut support to ConsoleWidget....
r2990 # Configure actions.
action = self._copy_raw_action
key = QtCore.Qt.CTRL | QtCore.Qt.SHIFT | QtCore.Qt.Key_C
action.setEnabled(False)
action.setShortcut(QtGui.QKeySequence(key))
action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
action.triggered.connect(self.copy_raw)
self.copy_available.connect(action.setEnabled)
self.addAction(action)
epatters
Refactored ConsoleWidget to encapsulate, rather than inherit from, QPlainTextEdit. This permits a QTextEdit to be substituted for a QPlainTextEdit if desired. It also makes it more clear what is the public interface of ConsoleWidget.
r2736 # Connect signal handlers.
document = self._control.document()
document.contentsChange.connect(self._document_contents_change)
epatters
* Adding object_info_request support to prototype kernel....
r2612
epatters
Minor comment cleanup.
r2669 #---------------------------------------------------------------------------
epatters
* Added "smart copy" support to FrontendWidget and ConsoleWidget. Tabs are expanded and prompts are stripped....
r2971 # 'ConsoleWidget' public interface
#---------------------------------------------------------------------------
def copy(self):
""" Copy the currently selected text to the clipboard, removing prompts.
"""
text = str(self._control.textCursor().selection().toPlainText())
if text:
# Remove prompts.
lines = map(transform_classic_prompt, text.splitlines())
text = '\n'.join(lines)
# Expand tabs so that we respect PEP-8.
QtGui.QApplication.clipboard().setText(text.expandtabs(4))
#---------------------------------------------------------------------------
epatters
Initial checkin of Qt frontend code.
r2602 # 'ConsoleWidget' abstract interface
#---------------------------------------------------------------------------
epatters
* Refactored ConsoleWidget execution API for greater flexibility and clarity....
r2688 def _is_complete(self, source, interactive):
""" Returns whether 'source' can be completely processed and a new
prompt created. When triggered by an Enter/Return key press,
'interactive' is True; otherwise, it is False.
epatters
Initial checkin of Qt frontend code.
r2602 """
epatters
* ConsoleWidget now has better support for non-GUI tab completion. Multiple matches are formatted into columns....
r2723 complete = self._input_splitter.push(source.expandtabs(4))
epatters
* Refactored ConsoleWidget execution API for greater flexibility and clarity....
r2688 if interactive:
complete = not self._input_splitter.push_accepts_more()
return complete
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961 def _execute(self, source, hidden):
epatters
* Refactored ConsoleWidget execution API for greater flexibility and clarity....
r2688 """ Execute 'source'. If 'hidden', do not show any output.
Fernando Perez
Rework messaging to better conform to our spec....
r2926
See parent class :meth:`execute` docstring for full details.
epatters
* Refactored ConsoleWidget execution API for greater flexibility and clarity....
r2688 """
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961 msg_id = self.kernel_manager.xreq_channel.execute(source, hidden)
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 self._request_info['execute'] = self._ExecutionRequest(msg_id, 'user')
epatters
* Refactored ConsoleWidget execution API for greater flexibility and clarity....
r2688 self._hidden = hidden
epatters
Initial checkin of Qt frontend code.
r2602
def _prompt_started_hook(self):
""" Called immediately after a new prompt is displayed.
"""
epatters
Fixed bug where syntax highlighting was enabled during raw_input mode.
r2709 if not self._reading:
self._highlighter.highlighting_on = True
epatters
Initial checkin of Qt frontend code.
r2602
def _prompt_finished_hook(self):
""" Called immediately after a prompt is finished, i.e. when some input
will be processed and a new prompt displayed.
"""
epatters
Fixed bug where syntax highlighting was enabled during raw_input mode.
r2709 if not self._reading:
self._highlighter.highlighting_on = False
epatters
Initial checkin of Qt frontend code.
r2602
def _tab_pressed(self):
""" Called when the tab key is pressed. Returns whether to continue
processing the event.
"""
epatters
The FrontendWidget now performs tab-completion more aggressively.
r2847 # Perform tab completion if:
# 1) The cursor is in the input buffer.
# 2) There is a non-whitespace character before the cursor.
text = self._get_input_buffer_cursor_line()
if text is None:
return False
complete = bool(text[:self._get_input_buffer_cursor_column()].strip())
if complete:
self._complete()
return not complete
epatters
Initial checkin of Qt frontend code.
r2602
#---------------------------------------------------------------------------
epatters
Fixed bug with ConsoleWidget smart paste.
r2787 # 'ConsoleWidget' protected interface
#---------------------------------------------------------------------------
epatters
* Added Cut support to ConsoleWidget....
r2990 def _context_menu_make(self, pos):
""" Reimplemented to add an action for raw copy.
"""
menu = super(FrontendWidget, self)._context_menu_make(pos)
for before_action in menu.actions():
if before_action.shortcut().matches(QtGui.QKeySequence.Paste) == \
QtGui.QKeySequence.ExactMatch:
menu.insertAction(before_action, self._copy_raw_action)
break
return menu
epatters
First cut at allowing the kernel to be restarted from the frontend.
r2851 def _event_filter_console_keypress(self, event):
""" Reimplemented to allow execution interruption.
"""
key = event.key()
epatters
Cmd-C will no longer interrupt the kernel in Mac OS (only Ctrl-C will do this).
r2941 if self._control_key_down(event.modifiers(), include_command=False):
epatters
Numerous usability enhancements to the Qt console widget, particularly with regard to key bindings.
r2897 if key == QtCore.Qt.Key_C and self._executing:
epatters
* Improved frontend-side kernel restart support....
r2913 self.interrupt_kernel()
epatters
Fixed scrolling bugs when using rich text mode. (Work around probable bug in Qt.)
r2914 return True
epatters
First cut at allowing the kernel to be restarted from the frontend.
r2851 elif key == QtCore.Qt.Key_Period:
Brian Granger
Added heartbeat support.
r2910 message = 'Are you sure you want to restart the kernel?'
Fernando Perez
Added kernel shutdown support: messaging spec, zmq and client code ready....
r2972 self.restart_kernel(message, instant_death=False)
epatters
First cut at allowing the kernel to be restarted from the frontend.
r2851 return True
return super(FrontendWidget, self)._event_filter_console_keypress(event)
epatters
Fixed several bugs involving the insertion of new lines. Pressing Enter in the ConsoleWidget now works as expected.
r2896 def _insert_continuation_prompt(self, cursor):
epatters
Fixed bug with ConsoleWidget smart paste.
r2787 """ Reimplemented for auto-indentation.
"""
epatters
Fixed several bugs involving the insertion of new lines. Pressing Enter in the ConsoleWidget now works as expected.
r2896 super(FrontendWidget, self)._insert_continuation_prompt(cursor)
epatters
Fixed bug with ConsoleWidget smart paste.
r2787 spaces = self._input_splitter.indent_spaces
epatters
Fixed several bugs involving the insertion of new lines. Pressing Enter in the ConsoleWidget now works as expected.
r2896 cursor.insertText('\t' * (spaces / self.tab_width))
cursor.insertText(' ' * (spaces % self.tab_width))
epatters
Fixed bug with ConsoleWidget smart paste.
r2787
#---------------------------------------------------------------------------
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 # 'BaseFrontendMixin' abstract interface
epatters
Initial checkin of Qt frontend code.
r2602 #---------------------------------------------------------------------------
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 def _handle_complete_reply(self, rep):
""" Handle replies for tab completion.
epatters
Initial checkin of Qt frontend code.
r2602 """
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 cursor = self._get_cursor()
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 info = self._request_info.get('complete')
if info and info.id == rep['parent_header']['msg_id'] and \
info.pos == cursor.position():
epatters
Fixed regressions in the pure Python kernel.
r2867 text = '.'.join(self._get_context())
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 cursor.movePosition(QtGui.QTextCursor.Left, n=len(text))
self._complete_with_items(cursor, rep['content']['matches'])
epatters
Initial checkin of Qt frontend code.
r2602
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 def _handle_execute_reply(self, msg):
""" Handles replies for code execution.
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609 """
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 info = self._request_info.get('execute')
if info and info.id == msg['parent_header']['msg_id'] and \
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961 info.kind == 'user' and not self._hidden:
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 # Make sure that all output from the SUB channel has been processed
# before writing a new prompt.
self.kernel_manager.sub_channel.flush()
epatters
Fixed ANSI compliance issue in AnsiCodeProcessor....
r3000 # Reset the ANSI style information to prevent bad text in stdout
# from messing up our colors. We're not a true terminal so we're
# allowed to do this.
if self.ansi_codes:
self._ansi_processor.reset_sgr()
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 content = msg['content']
status = content['status']
if status == 'ok':
self._process_execute_ok(msg)
elif status == 'error':
self._process_execute_error(msg)
elif status == 'abort':
self._process_execute_abort(msg)
epatters
Updated IPythonWidget to use new prompt information. Initial prompt requests are not implemented.
r2797 self._show_interpreter_prompt_for_reply(msg)
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 self.executed.emit(msg)
def _handle_input_request(self, msg):
""" Handle requests for raw_input.
"""
epatters
Minor cleanup and bug fix.
r2771 if self._hidden:
raise RuntimeError('Request for raw input during hidden execution.')
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 # Make sure that all output from the SUB channel has been processed
# before entering readline mode.
self.kernel_manager.sub_channel.flush()
def callback(line):
self.kernel_manager.rep_channel.input(line)
self._readline(msg['content']['prompt'], callback=callback)
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609
epatters
* Improved frontend-side kernel restart support....
r2913 def _handle_kernel_died(self, since_last_heartbeat):
""" Handle the kernel's death by asking if the user wants to restart.
"""
message = 'The kernel heartbeat has been inactive for %.2f ' \
'seconds. Do you want to restart the kernel? You may ' \
'first want to check the network connection.' % \
since_last_heartbeat
if self.custom_restart:
self.custom_restart_kernel_died.emit(since_last_heartbeat)
else:
Fernando Perez
Added kernel shutdown support: messaging spec, zmq and client code ready....
r2972 self.restart_kernel(message, instant_death=True)
epatters
* Improved frontend-side kernel restart support....
r2913
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 def _handle_object_info_reply(self, rep):
""" Handle replies for call tips.
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609 """
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 cursor = self._get_cursor()
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 info = self._request_info.get('call_tip')
if info and info.id == rep['parent_header']['msg_id'] and \
info.pos == cursor.position():
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 doc = rep['content']['docstring']
if doc:
self._call_tip_widget.show_docstring(doc)
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 def _handle_pyout(self, msg):
""" Handle display hook output.
"""
epatters
* The Qt console frontend now ignores cross chatter from other frontends....
r2824 if not self._hidden and self._is_from_this_session(msg):
self._append_plain_text(msg['content']['data'] + '\n')
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 def _handle_stream(self, msg):
""" Handle stdout, stderr, and stdin.
"""
epatters
* The Qt console frontend now ignores cross chatter from other frontends....
r2824 if not self._hidden and self._is_from_this_session(msg):
Evan Patterson
FrontendWidget now treats tab characters in the std* streams like most consoles....
r2997 # Most consoles treat tabs as being 8 space characters. Convert tabs
# to spaces so that output looks as expected regardless of this
# widget's tab width.
text = msg['content']['data'].expandtabs(8)
self._append_plain_text(text)
epatters
* The Qt console frontend now ignores cross chatter from other frontends....
r2824 self._control.moveCursor(QtGui.QTextCursor.End)
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770
def _started_channels(self):
""" Called when the KernelManager channels have started listening or
when the frontend is assigned an already listening KernelManager.
"""
epatters
Fixed bug where the banner message was syntax highlighted when the frontend connected to a new kernel.
r2842 self._control.clear()
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 self._append_plain_text(self._get_banner())
self._show_interpreter_prompt()
def _stopped_channels(self):
""" Called when the KernelManager channels have stopped listening or
when a listening KernelManager is removed from the frontend.
"""
epatters
Fixed bug where the banner message was syntax highlighted when the frontend connected to a new kernel.
r2842 self._executing = self._reading = False
self._highlighter.highlighting_on = False
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770
#---------------------------------------------------------------------------
epatters
* Added "smart copy" support to FrontendWidget and ConsoleWidget. Tabs are expanded and prompts are stripped....
r2971 # 'FrontendWidget' public interface
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 #---------------------------------------------------------------------------
epatters
* Added Cut support to ConsoleWidget....
r2990 def copy_raw(self):
""" Copy the currently selected text to the clipboard without attempting
to remove prompts or otherwise alter the text.
"""
self._control.copy()
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 def execute_file(self, path, hidden=False):
""" Attempts to execute file with 'path'. If 'hidden', no output is
shown.
"""
self.execute('execfile("%s")' % path, hidden=hidden)
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609
epatters
* Improved frontend-side kernel restart support....
r2913 def interrupt_kernel(self):
""" Attempts to interrupt the running kernel.
"""
if self.custom_interrupt:
self.custom_interrupt_requested.emit()
elif self.kernel_manager.has_kernel:
self.kernel_manager.signal_kernel(signal.SIGINT)
else:
self._append_plain_text('Kernel process is either remote or '
'unspecified. Cannot interrupt.\n')
Fernando Perez
Added kernel shutdown support: messaging spec, zmq and client code ready....
r2972 def restart_kernel(self, message, instant_death=False):
epatters
* Improved frontend-side kernel restart support....
r2913 """ Attempts to restart the running kernel.
"""
Fernando Perez
Added kernel shutdown support: messaging spec, zmq and client code ready....
r2972 # FIXME: instant_death should be configurable via a checkbox in the
# dialog. Right now at least the heartbeat path sets it to True and
# the manual restart to False. But those should just be the
# pre-selected states of a checkbox that the user could override if so
# desired. But I don't know enough Qt to go implementing the checkbox
# now.
epatters
* Improved frontend-side kernel restart support....
r2913 # We want to make sure that if this dialog is already happening, that
# other signals don't trigger it again. This can happen when the
# kernel_died heartbeat signal is emitted and the user is slow to
# respond to the dialog.
if not self._possible_kernel_restart:
if self.custom_restart:
self.custom_restart_requested.emit()
elif self.kernel_manager.has_kernel:
# Setting this to True will prevent this logic from happening
# again until the current pass is completed.
self._possible_kernel_restart = True
buttons = QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
result = QtGui.QMessageBox.question(self, 'Restart kernel?',
message, buttons)
if result == QtGui.QMessageBox.Yes:
try:
Fernando Perez
Added kernel shutdown support: messaging spec, zmq and client code ready....
r2972 self.kernel_manager.restart_kernel(
instant_death=instant_death)
epatters
* Improved frontend-side kernel restart support....
r2913 except RuntimeError:
message = 'Kernel started externally. Cannot restart.\n'
self._append_plain_text(message)
else:
self._stopped_channels()
self._append_plain_text('Kernel restarting...\n')
self._show_interpreter_prompt()
# This might need to be moved to another location?
self._possible_kernel_restart = False
else:
self._append_plain_text('Kernel process is either remote or '
'unspecified. Cannot restart.\n')
epatters
Initial checkin of Qt frontend code.
r2602 #---------------------------------------------------------------------------
# 'FrontendWidget' protected interface
#---------------------------------------------------------------------------
def _call_tip(self):
""" Shows a call tip, if appropriate, at the current cursor location.
"""
# Decide if it makes sense to show a call tip
epatters
Refactored ConsoleWidget to encapsulate, rather than inherit from, QPlainTextEdit. This permits a QTextEdit to be substituted for a QPlainTextEdit if desired. It also makes it more clear what is the public interface of ConsoleWidget.
r2736 cursor = self._get_cursor()
epatters
Initial checkin of Qt frontend code.
r2602 cursor.movePosition(QtGui.QTextCursor.Left)
epatters
* The ConsoleWidget now has full undo/redo support. Previously, the undo/redo history was cleared after every continuation prompt. This is no longer the case....
r2864 if cursor.document().characterAt(cursor.position()).toAscii() != '(':
epatters
Initial checkin of Qt frontend code.
r2602 return False
context = self._get_context(cursor)
if not context:
return False
# Send the metadata request to the kernel
epatters
* Adding object_info_request support to prototype kernel....
r2612 name = '.'.join(context)
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 msg_id = self.kernel_manager.xreq_channel.object_info(name)
pos = self._get_cursor().position()
self._request_info['call_tip'] = self._CallTipRequest(msg_id, pos)
epatters
Initial checkin of Qt frontend code.
r2602 return True
def _complete(self):
""" Performs completion at the current cursor location.
"""
epatters
Fixed regressions in the pure Python kernel.
r2867 context = self._get_context()
if context:
# Send the completion request to the kernel
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 msg_id = self.kernel_manager.xreq_channel.complete(
epatters
Fixed regressions in the pure Python kernel.
r2867 '.'.join(context), # text
self._get_input_buffer_cursor_line(), # line
self._get_input_buffer_cursor_column(), # cursor_pos
self.input_buffer) # block
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 pos = self._get_cursor().position()
info = self._CompletionRequest(msg_id, pos)
self._request_info['complete'] = info
epatters
Initial checkin of Qt frontend code.
r2602
epatters
Added banners to FrontendWidget and IPythonWidget.
r2714 def _get_banner(self):
""" Gets a banner to display at the beginning of a session.
"""
banner = 'Python %s on %s\nType "help", "copyright", "credits" or ' \
'"license" for more information.'
return banner % (sys.version, sys.platform)
epatters
Initial checkin of Qt frontend code.
r2602 def _get_context(self, cursor=None):
epatters
* The ConsoleWidget now has full undo/redo support. Previously, the undo/redo history was cleared after every continuation prompt. This is no longer the case....
r2864 """ Gets the context for the specified cursor (or the current cursor
if none is specified).
epatters
Initial checkin of Qt frontend code.
r2602 """
if cursor is None:
epatters
Refactored ConsoleWidget to encapsulate, rather than inherit from, QPlainTextEdit. This permits a QTextEdit to be substituted for a QPlainTextEdit if desired. It also makes it more clear what is the public interface of ConsoleWidget.
r2736 cursor = self._get_cursor()
epatters
Numerous fixes to ConsoleWidget editing region maintenence code. It now impossible (or at least very difficult :) to break the input region.
r2764 cursor.movePosition(QtGui.QTextCursor.StartOfBlock,
epatters
Initial checkin of Qt frontend code.
r2602 QtGui.QTextCursor.KeepAnchor)
epatters
Made use of plain text consistent.
r2720 text = str(cursor.selection().toPlainText())
epatters
Initial checkin of Qt frontend code.
r2602 return self._completion_lexer.get_context(text)
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 def _process_execute_abort(self, msg):
""" Process a reply for an aborted execution request.
epatters
* IPythonWidget now has IPython-style prompts that are futher stylabla via CSS...
r2715 """
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 self._append_plain_text("ERROR: execution aborted\n")
epatters
Initial checkin of Qt frontend code.
r2602
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 def _process_execute_error(self, msg):
""" Process a reply for an execution request that resulted in an error.
epatters
Progress on raw_input.
r2705 """
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 content = msg['content']
traceback = ''.join(content['traceback'])
self._append_plain_text(traceback)
epatters
Progress on raw_input.
r2705
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 def _process_execute_ok(self, msg):
""" Process a reply for a successful execution equest.
epatters
Progress on raw_input.
r2705 """
epatters
* Refactored payload handling mechanism....
r2835 payload = msg['content']['payload']
for item in payload:
if not self._process_execute_payload(item):
epatters
* ConsoleWidget no longer stores contiguous identical lines...
r2969 warning = 'Warning: received unknown payload of type %s'
raw_print(warning % repr(item['source']))
epatters
* Refactored payload handling mechanism....
r2835
def _process_execute_payload(self, item):
""" Process a single payload item from the list of payload items in an
execution reply. Returns whether the payload was handled.
"""
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 # The basic FrontendWidget doesn't handle payloads, as they are a
# mechanism for going beyond the standard Python interpreter model.
epatters
* Refactored payload handling mechanism....
r2835 return False
epatters
Progress on raw_input.
r2705
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 def _show_interpreter_prompt(self):
""" Shows a prompt for the interpreter.
"""
self._show_prompt('>>> ')
epatters
Updated IPythonWidget to use new prompt information. Initial prompt requests are not implemented.
r2797 def _show_interpreter_prompt_for_reply(self, msg):
""" Shows a prompt for the interpreter given an 'execute_reply' message.
"""
self._show_interpreter_prompt()
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 #------ Signal handlers ----------------------------------------------------
epatters
Initial checkin of Qt frontend code.
r2602 def _document_contents_change(self, position, removed, added):
epatters
* CallTipWidget and CompletionWidget no longer need to be fed key presses. This means that can be attached to any Q[Plain]TextEdit with zero hassle....
r2744 """ Called whenever the document's content changes. Display a call tip
epatters
Initial checkin of Qt frontend code.
r2602 if appropriate.
"""
# Calculate where the cursor should be *after* the change:
position += added
epatters
Refactored ConsoleWidget to encapsulate, rather than inherit from, QPlainTextEdit. This permits a QTextEdit to be substituted for a QPlainTextEdit if desired. It also makes it more clear what is the public interface of ConsoleWidget.
r2736 document = self._control.document()
if position == self._get_cursor().position():
epatters
Initial checkin of Qt frontend code.
r2602 self._call_tip()