##// END OF EJS Templates
Update copyright year in dev template file.
Update copyright year in dev template file.

File last commit:

r3464:f71f71c1
r3729:0c4144cd
Show More
ipython_widget.py
490 lines | 20.3 KiB | text/x-python | PythonLexer
epatters
Reimplemented IPythonWidget's edit magic handling to support line numbers. Also, removed the code path for launching the file with the system default Python application, as this is too dangerous.
r2850 """ A FrontendWidget that emulates the interface of the console IPython and
supports the additional functionality provided by the IPython kernel.
"""
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
epatters
Added preliminary editor support to IPythonWidget.
r2793 # Standard library imports
epatters
Replaced internal storage object with namedtuple.
r2883 from collections import namedtuple
epatters
* Fixed bug with terminal-style tab completion for multi-line input....
r2920 import re
epatters
Added preliminary editor support to IPythonWidget.
r2793 from subprocess import Popen
Brian Granger
Implemented %loadpy magic for loading .py scripts into Qt console.
r3036 from textwrap import dedent
epatters
Added preliminary editor support to IPythonWidget.
r2793
epatters
* Updated FrontendWidget to use BlockBreaker for parsing input...
r2630 # System library imports
Evan Patterson
Paved the way for PySide support....
r3304 from IPython.external.qt import QtCore, QtGui
epatters
* Updated FrontendWidget to use BlockBreaker for parsing input...
r2630
# Local imports
epatters
* Added "smart copy" support to FrontendWidget and ConsoleWidget. Tabs are expanded and prompts are stripped....
r2971 from IPython.core.inputsplitter import IPythonInputSplitter, \
transform_ipy_prompt
Fernando Perez
Add %guiref to give a quick reference to the GUI console.
r3008 from IPython.core.usage import default_gui_banner
MinRK
fix at least some command-line unicode options
r3464 from IPython.utils.traitlets import Bool, Str, Unicode
epatters
* Created an IPythonWidget subclass of FrontendWidget to contain IPython specific functionality....
r2627 from frontend_widget import FrontendWidget
MinRK
added --colors flag to ipythonqt
r3171 from styles import (default_light_style_sheet, default_light_syntax_style,
default_dark_style_sheet, default_dark_syntax_style,
default_bw_style_sheet, default_bw_syntax_style)
epatters
* Created an IPythonWidget subclass of FrontendWidget to contain IPython specific functionality....
r2627
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916 #-----------------------------------------------------------------------------
# Constants
#-----------------------------------------------------------------------------
Fernando Perez
Rework messaging to better conform to our spec....
r2926 # Default strings to build and display input and output prompts (and separators
# in between)
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 default_in_prompt = 'In [<span class="in-prompt-number">%i</span>]: '
default_out_prompt = 'Out[<span class="out-prompt-number">%i</span>]: '
Fernando Perez
Rework messaging to better conform to our spec....
r2926 default_input_sep = '\n'
default_output_sep = ''
default_output_sep2 = ''
epatters
Made IPythonWidget and its subclasses Configurable.
r2884
epatters
Minor cleanup in IPythonWidget (fix long lines, method order, etc).
r3041 # Base path for most payload sources.
zmq_shell_source = 'IPython.zmq.zmqshell.ZMQInteractiveShell'
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916 #-----------------------------------------------------------------------------
# IPythonWidget class
#-----------------------------------------------------------------------------
epatters
* Created an IPythonWidget subclass of FrontendWidget to contain IPython specific functionality....
r2627
class IPythonWidget(FrontendWidget):
""" A FrontendWidget for an IPython kernel.
"""
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 # If set, the 'custom_edit_requested(str, int)' signal will be emitted when
# an editor is needed for a file. This overrides 'editor' and 'editor_line'
# settings.
custom_edit = Bool(False)
Evan Patterson
Paved the way for PySide support....
r3304 custom_edit_requested = QtCore.Signal(object, object)
epatters
Added preliminary editor support to IPythonWidget.
r2793
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 # A command for invoking a system text editor. If the string contains a
# {filename} format specifier, it will be used. Otherwise, the filename will
# be appended to the end the command.
MinRK
fix at least some command-line unicode options
r3464 editor = Unicode('default', config=True)
epatters
Made IPythonWidget and its subclasses Configurable.
r2884
# The editor command to use when a specific line number is requested. The
# string should contain two format specifiers: {line} and {filename}. If
# this parameter is not specified, the line number option to the %edit magic
# will be ignored.
MinRK
fix at least some command-line unicode options
r3464 editor_line = Unicode(config=True)
epatters
Made IPythonWidget and its subclasses Configurable.
r2884
# A CSS stylesheet. The stylesheet can contain classes for:
# 1. Qt: QPlainTextEdit, QFrame, QWidget, etc
# 2. Pygments: .c, .k, .o, etc (see PygmentsHighlighter)
# 3. IPython: .error, .in-prompt, .out-prompt, etc
MinRK
fix at least some command-line unicode options
r3464 style_sheet = Unicode(config=True)
epatters
Made IPythonWidget and its subclasses Configurable.
r2884
# If not empty, use this Pygments style for syntax highlighting. Otherwise,
# the style sheet is queried for Pygments style information.
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916 syntax_style = Str(config=True)
epatters
Added machinery to IPythonWidget for updating the previous prompt number.
r2733
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 # Prompts.
in_prompt = Str(default_in_prompt, config=True)
out_prompt = Str(default_out_prompt, config=True)
Fernando Perez
Rework messaging to better conform to our spec....
r2926 input_sep = Str(default_input_sep, config=True)
output_sep = Str(default_output_sep, config=True)
output_sep2 = Str(default_output_sep2, config=True)
epatters
Replaced internal storage object with namedtuple.
r2883
epatters
* Refactored payload handling mechanism....
r2835 # FrontendWidget protected class variables.
Fernando Perez
Fix bug with IPythonInputSplitter in block input mode.
r2861 _input_splitter_class = IPythonInputSplitter
epatters
* Fixed bug where syntax highlighting was lost after updating a prompt with a bad number....
r2800
epatters
* Refactored payload handling mechanism....
r2835 # IPythonWidget protected class variables.
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 _PromptBlock = namedtuple('_PromptBlock', ['block', 'length', 'number'])
epatters
Minor cleanup in IPythonWidget (fix long lines, method order, etc).
r3041 _payload_source_edit = zmq_shell_source + '.edit_magic'
_payload_source_exit = zmq_shell_source + '.ask_exit'
_payload_source_loadpy = zmq_shell_source + '.magic_loadpy'
epatters
* Refactored payload handling mechanism....
r2835 _payload_source_page = 'IPython.zmq.page.page'
epatters
* Created an IPythonWidget subclass of FrontendWidget to contain IPython specific functionality....
r2627 #---------------------------------------------------------------------------
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
* Created an IPythonWidget subclass of FrontendWidget to contain IPython specific functionality....
r2627 #---------------------------------------------------------------------------
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(IPythonWidget, self).__init__(*args, **kw)
epatters
* Created an IPythonWidget subclass of FrontendWidget to contain IPython specific functionality....
r2627
epatters
Integrated new IPythonInputSplitter into IPythonWidget.
r2789 # IPythonWidget protected variables.
epatters
Minor cleanup in IPythonWidget (fix long lines, method order, etc).
r3041 self._code_to_load = None
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961 self._payload_handlers = {
Fernando Perez
Implement exit/quit/Exit/Quit recognition....
r2950 self._payload_source_edit : self._handle_payload_edit,
self._payload_source_exit : self._handle_payload_exit,
Brian Granger
Implemented %loadpy magic for loading .py scripts into Qt console.
r3036 self._payload_source_page : self._handle_payload_page,
self._payload_source_loadpy : self._handle_payload_loadpy }
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961 self._previous_prompt_obj = None
Erik Tollerud
Expanded %exit magic in qtconsole to not exit without prompting and...
r3183 self._keep_kernel_on_exit = None
epatters
* IPythonWidget now has IPython-style prompts that are futher stylabla via CSS...
r2715
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 # Initialize widget styling.
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916 if self.style_sheet:
self._style_sheet_changed()
self._syntax_style_changed()
else:
self.set_default_style()
epatters
* Refactored ConsoleWidget execution API for greater flexibility and clarity....
r2688
#---------------------------------------------------------------------------
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
Fixed regressions in the pure Python kernel.
r2867 def _handle_complete_reply(self, rep):
""" Reimplemented to support IPython's improved completion machinery.
"""
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 bug with terminal-style tab completion for multi-line input....
r2920 matches = rep['content']['matches']
epatters
Fixed regressions in the pure Python kernel.
r2867 text = rep['content']['matched_text']
epatters
Fixed numerous bugs with tab completion, including the one recently reported by fperez.
r2939 offset = len(text)
# Clean up matches with period and path separators if the matched
# text has not been transformed. This is done by truncating all
# but the last component and then suitably decreasing the offset
# between the current cursor position and the start of completion.
if len(matches) > 1 and matches[0][:offset] == text:
parts = re.split(r'[./\\]', text)
sep_count = len(parts) - 1
if sep_count:
chop_length = sum(map(len, parts[:sep_count])) + sep_count
matches = [ match[chop_length:] for match in matches ]
offset -= chop_length
epatters
* Fixed bug with terminal-style tab completion for multi-line input....
r2920
# Move the cursor to the start of the match and complete.
epatters
Fixed numerous bugs with tab completion, including the one recently reported by fperez.
r2939 cursor.movePosition(QtGui.QTextCursor.Left, n=offset)
epatters
* Fixed bug with terminal-style tab completion for multi-line input....
r2920 self._complete_with_items(cursor, matches)
epatters
Fixed regressions in the pure Python kernel.
r2867
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 def _handle_execute_reply(self, msg):
""" Reimplemented to support prompt requests.
"""
info = self._request_info.get('execute')
if info and info.id == msg['parent_header']['msg_id']:
if info.kind == 'prompt':
number = msg['content']['execution_count'] + 1
self._show_interpreter_prompt(number)
else:
super(IPythonWidget, self)._handle_execute_reply(msg)
Thomas Kluyver
ipython-qtconsole now calls the right function.
r3397 def _handle_history_tail_reply(self, msg):
""" Implemented to handle history tail replies, which are only supported
by the IPython kernel.
epatters
* Added support for prompt and history requests to the kernel manager and Qt console frontend....
r2844 """
Thomas Kluyver
ipython-qtconsole now calls the right function.
r3397 history_items = msg['content']['history']
items = [ line.rstrip() for _, _, line in history_items ]
epatters
* Added support for prompt and history requests to the kernel manager and Qt console frontend....
r2844 self._set_history(items)
epatters
IPythonWidget now supports 'input_sep'.
r2806 def _handle_pyout(self, 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 """ Reimplemented for IPython-style "display hook".
"""
epatters
* The Qt console frontend now ignores cross chatter from other frontends....
r2824 if not self._hidden and self._is_from_this_session(msg):
content = msg['content']
Fernando Perez
Rework messaging to better conform to our spec....
r2926 prompt_number = content['execution_count']
Brian Granger
Display system is fully working now....
r3278 data = content['data']
if data.has_key('text/html'):
self._append_plain_text(self.output_sep)
self._append_html(self._make_out_prompt(prompt_number))
html = data['text/html']
self._append_plain_text('\n')
self._append_html(html + self.output_sep2)
elif data.has_key('text/plain'):
self._append_plain_text(self.output_sep)
self._append_html(self._make_out_prompt(prompt_number))
text = data['text/plain']
self._append_plain_text(text + self.output_sep2)
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
Brian Granger
Mostly final version of display data....
r3277 def _handle_display_data(self, msg):
""" The base handler for the ``display_data`` message.
"""
# For now, we don't display data from other frontends, but we
# eventually will as this allows all frontends to monitor the display
# data. But we need to figure out how to handle this in the GUI.
if not self._hidden and self._is_from_this_session(msg):
source = msg['content']['source']
data = msg['content']['data']
metadata = msg['content']['metadata']
# In the regular IPythonWidget, we simply print the plain text
# representation.
Brian Granger
Display system is fully working now....
r3278 if data.has_key('text/html'):
html = data['text/html']
self._append_html(html)
elif data.has_key('text/plain'):
text = data['text/plain']
self._append_plain_text(text)
Brian Granger
More improvements to the display system....
r3279 # This newline seems to be needed for text and html output.
self._append_plain_text(u'\n')
Brian Granger
Mostly final version of display data....
r3277
epatters
* Added support for prompt and history requests to the kernel manager and Qt console frontend....
r2844 def _started_channels(self):
""" Reimplemented to make a history request.
"""
super(IPythonWidget, self)._started_channels()
Thomas Kluyver
ipython-qtconsole now calls the right function.
r3397 self.kernel_manager.xreq_channel.history_tail(1000)
epatters
* Added support for prompt and history requests to the kernel manager and Qt console frontend....
r2844
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 # 'ConsoleWidget' public interface
#---------------------------------------------------------------------------
def copy(self):
""" Copy the currently selected text to the clipboard, removing prompts
if possible.
"""
Evan Patterson
Paved the way for PySide support....
r3304 text = self._control.textCursor().selection().toPlainText()
epatters
* Added "smart copy" support to FrontendWidget and ConsoleWidget. Tabs are expanded and prompts are stripped....
r2971 if text:
lines = map(transform_ipy_prompt, text.splitlines())
text = '\n'.join(lines)
epatters
Removed use of hard tabs in FrontendWidget and implemented "smart" backspace.
r3022 QtGui.QApplication.clipboard().setText(text)
epatters
* Added "smart copy" support to FrontendWidget and ConsoleWidget. Tabs are expanded and prompts are stripped....
r2971
#---------------------------------------------------------------------------
# 'FrontendWidget' public interface
epatters
* Refactored ConsoleWidget execution API for greater flexibility and clarity....
r2688 #---------------------------------------------------------------------------
def execute_file(self, path, hidden=False):
""" Reimplemented to use the 'run' magic.
"""
Fernando Perez
Improvements to exception handling to transport structured tracebacks....
r2838 self.execute('%%run %s' % path, hidden=hidden)
epatters
* Created an IPythonWidget subclass of FrontendWidget to contain IPython specific functionality....
r2627
#---------------------------------------------------------------------------
epatters
Added banners to FrontendWidget and IPythonWidget.
r2714 # 'FrontendWidget' protected interface
#---------------------------------------------------------------------------
epatters
Fixed regressions in the pure Python kernel.
r2867 def _complete(self):
""" Reimplemented to support IPython's improved completion machinery.
"""
# We let the kernel split the input line, so we *always* send an empty
# text field. Readline-based frontends do get a real text field which
# they can use.
text = ''
# 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 text, # 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
Fixed regressions in the pure Python kernel.
r2867
epatters
Added banners to FrontendWidget and IPythonWidget.
r2714 def _get_banner(self):
epatters
* IPythonWidget now has IPython-style prompts that are futher stylabla via CSS...
r2715 """ Reimplemented to return IPython's default banner.
epatters
Added banners to FrontendWidget and IPythonWidget.
r2714 """
Fernando Perez
Add %guiref to give a quick reference to the GUI console.
r3008 return default_gui_banner
epatters
Added banners to FrontendWidget and IPythonWidget.
r2714
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):
""" Reimplemented for IPython-style traceback formatting.
"""
content = msg['content']
epatters
* Tab completion now uses the correct cursor position....
r2841 traceback = '\n'.join(content['traceback']) + '\n'
if False:
# FIXME: For now, tracebacks come as plain text, so we can't use
Fernando Perez
Improvements to exception handling to transport structured tracebacks....
r2838 # the html renderer yet. Once we refactor ultratb to produce
# properly styled tracebacks, this branch should be the default
traceback = traceback.replace(' ', '&nbsp;')
traceback = traceback.replace('\n', '<br/>')
ename = content['ename']
ename_styled = '<span class="error">%s</span>' % ename
traceback = traceback.replace(ename, ename_styled)
self._append_html(traceback)
else:
# This is the fallback for now, using plain text with ansi escapes
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961 self._append_plain_text(traceback)
Fernando Perez
Implement exit/quit/Exit/Quit recognition....
r2950
epatters
* Refactored payload handling mechanism....
r2835 def _process_execute_payload(self, item):
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961 """ Reimplemented to dispatch payloads to handler methods.
epatters
* Refactored payload handling mechanism....
r2835 """
Fernando Perez
Implement exit/quit/Exit/Quit recognition....
r2950 handler = self._payload_handlers.get(item['source'])
if handler is None:
# We have no handler for this type of payload, simply ignore it
epatters
* Refactored payload handling mechanism....
r2835 return False
Fernando Perez
Implement exit/quit/Exit/Quit recognition....
r2950 else:
handler(item)
return True
Fernando Perez
Rework messaging to better conform to our spec....
r2926 def _show_interpreter_prompt(self, number=None):
epatters
* IPythonWidget now has IPython-style prompts that are futher stylabla via CSS...
r2715 """ Reimplemented for IPython-style prompts.
"""
epatters
* Added support for prompt and history requests to the kernel manager and Qt console frontend....
r2844 # If a number was not specified, make a prompt number request.
epatters
Updated IPythonWidget to use new prompt information. Initial prompt requests are not implemented.
r2797 if number is None:
epatters
* Updated prompt request code to support the new silent execution mechanism....
r2934 msg_id = self.kernel_manager.xreq_channel.execute('', silent=True)
info = self._ExecutionRequest(msg_id, 'prompt')
self._request_info['execute'] = info
return
epatters
Updated IPythonWidget to use new prompt information. Initial prompt requests are not implemented.
r2797
epatters
IPythonWidget now supports 'input_sep'.
r2806 # Show a new prompt and save information about it so that it can be
# updated later if the prompt number turns out to be wrong.
Fernando Perez
Rework messaging to better conform to our spec....
r2926 self._prompt_sep = self.input_sep
epatters
Updated IPythonWidget to use new prompt information. Initial prompt requests are not implemented.
r2797 self._show_prompt(self._make_in_prompt(number), html=True)
epatters
IPythonWidget now supports 'input_sep'.
r2806 block = self._control.document().lastBlock()
length = len(self._prompt)
epatters
Replaced internal storage object with namedtuple.
r2883 self._previous_prompt_obj = self._PromptBlock(block, length, number)
epatters
* IPythonWidget now has IPython-style prompts that are futher stylabla via CSS...
r2715
# Update continuation prompt to reflect (possibly) new prompt length.
epatters
Added machinery to IPythonWidget for updating the previous prompt number.
r2733 self._set_continuation_prompt(
self._make_continuation_prompt(self._prompt), html=True)
epatters
* IPythonWidget now has IPython-style prompts that are futher stylabla via CSS...
r2715
epatters
Minor cleanup in IPythonWidget (fix long lines, method order, etc).
r3041 # Load code from the %loadpy magic, if necessary.
Brian Granger
Implemented %loadpy magic for loading .py scripts into Qt console.
r3036 if self._code_to_load is not None:
Evan Patterson
Paved the way for PySide support....
r3304 self.input_buffer = dedent(self._code_to_load.rstrip())
Brian Granger
Implemented %loadpy magic for loading .py scripts into Qt console.
r3036 self._code_to_load = None
epatters
Updated IPythonWidget to use new prompt information. Initial prompt requests are not implemented.
r2797 def _show_interpreter_prompt_for_reply(self, msg):
""" Reimplemented for IPython-style prompts.
"""
# Update the old prompt number if necessary.
content = msg['content']
Fernando Perez
Rework messaging to better conform to our spec....
r2926 previous_prompt_number = content['execution_count']
epatters
Updated IPythonWidget to use new prompt information. Initial prompt requests are not implemented.
r2797 if self._previous_prompt_obj and \
self._previous_prompt_obj.number != previous_prompt_number:
block = self._previous_prompt_obj.block
epatters
Fixed bug introduced by the recent payload processing refactor.
r2846
# Make sure the prompt block has not been erased.
epatters
Yet more PySide compatibility fixes.
r3307 if block.isValid() and block.text():
epatters
* Fixed bug where syntax highlighting was lost after updating a prompt with a bad number....
r2800
# Remove the old prompt and insert a new prompt.
epatters
Updated IPythonWidget to use new prompt information. Initial prompt requests are not implemented.
r2797 cursor = QtGui.QTextCursor(block)
cursor.movePosition(QtGui.QTextCursor.Right,
QtGui.QTextCursor.KeepAnchor,
self._previous_prompt_obj.length)
prompt = self._make_in_prompt(previous_prompt_number)
epatters
* Fixed bug where syntax highlighting was lost after updating a prompt with a bad number....
r2800 self._prompt = self._insert_html_fetching_plain_text(
cursor, prompt)
epatters
Minor cleanup.
r2825 # When the HTML is inserted, Qt blows away the syntax
# highlighting for the line, so we need to rehighlight it.
epatters
* Fixed bug where syntax highlighting was lost after updating a prompt with a bad number....
r2800 self._highlighter.rehighlightBlock(cursor.block())
epatters
Updated IPythonWidget to use new prompt information. Initial prompt requests are not implemented.
r2797 self._previous_prompt_obj = None
# Show a new prompt with the kernel's estimated prompt number.
epatters
Minor cleanup in IPythonWidget (fix long lines, method order, etc).
r3041 self._show_interpreter_prompt(previous_prompt_number + 1)
epatters
Updated IPythonWidget to use new prompt information. Initial prompt requests are not implemented.
r2797
epatters
Added banners to FrontendWidget and IPythonWidget.
r2714 #---------------------------------------------------------------------------
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916 # 'IPythonWidget' interface
#---------------------------------------------------------------------------
MinRK
color settings from ipythonqt propagate down to the ZMQInteractiveShell in the Kernel
r3173 def set_default_style(self, colors='lightbg'):
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916 """ Sets the widget style to the class defaults.
Parameters:
-----------
MinRK
color settings from ipythonqt propagate down to the ZMQInteractiveShell in the Kernel
r3173 colors : str, optional (default lightbg)
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916 Whether to use the default IPython light background or dark
MinRK
added --colors flag to ipythonqt
r3171 background or B&W style.
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916 """
MinRK
color settings from ipythonqt propagate down to the ZMQInteractiveShell in the Kernel
r3173 colors = colors.lower()
if colors=='lightbg':
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916 self.style_sheet = default_light_style_sheet
self.syntax_style = default_light_syntax_style
MinRK
color settings from ipythonqt propagate down to the ZMQInteractiveShell in the Kernel
r3173 elif colors=='linux':
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916 self.style_sheet = default_dark_style_sheet
self.syntax_style = default_dark_syntax_style
MinRK
color settings from ipythonqt propagate down to the ZMQInteractiveShell in the Kernel
r3173 elif colors=='nocolor':
MinRK
added --colors flag to ipythonqt
r3171 self.style_sheet = default_bw_style_sheet
self.syntax_style = default_bw_syntax_style
MinRK
color settings from ipythonqt propagate down to the ZMQInteractiveShell in the Kernel
r3173 else:
raise KeyError("No such color scheme: %s"%colors)
epatters
Added a method on IPythonWidget for setting the style to the IPython defaults.
r2916
#---------------------------------------------------------------------------
epatters
Added machinery to IPythonWidget for updating the previous prompt number.
r2733 # 'IPythonWidget' protected interface
#---------------------------------------------------------------------------
epatters
Reimplemented IPythonWidget's edit magic handling to support line numbers. Also, removed the code path for launching the file with the system default Python application, as this is too dangerous.
r2850 def _edit(self, filename, line=None):
""" Opens a Python script for editing.
Parameters:
-----------
filename : str
A path to a local system file.
line : int, optional
A line of interest in the file.
"""
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 if self.custom_edit:
epatters
Reimplemented IPythonWidget's edit magic handling to support line numbers. Also, removed the code path for launching the file with the system default Python application, as this is too dangerous.
r2850 self.custom_edit_requested.emit(filename, line)
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 elif self.editor == 'default':
epatters
Reimplemented IPythonWidget's edit magic handling to support line numbers. Also, removed the code path for launching the file with the system default Python application, as this is too dangerous.
r2850 self._append_plain_text('No default editor available.\n')
else:
try:
filename = '"%s"' % filename
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 if line and self.editor_line:
command = self.editor_line.format(filename=filename,
line=line)
epatters
Reimplemented IPythonWidget's edit magic handling to support line numbers. Also, removed the code path for launching the file with the system default Python application, as this is too dangerous.
r2850 else:
try:
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 command = self.editor.format()
epatters
Reimplemented IPythonWidget's edit magic handling to support line numbers. Also, removed the code path for launching the file with the system default Python application, as this is too dangerous.
r2850 except KeyError:
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 command = self.editor.format(filename=filename)
epatters
Reimplemented IPythonWidget's edit magic handling to support line numbers. Also, removed the code path for launching the file with the system default Python application, as this is too dangerous.
r2850 else:
command += ' ' + filename
except KeyError:
self._append_plain_text('Invalid editor command.\n')
else:
try:
Popen(command, shell=True)
except OSError:
msg = 'Opening editor with command "%s" failed.\n'
self._append_plain_text(msg % command)
epatters
Added machinery to IPythonWidget for updating the previous prompt number.
r2733 def _make_in_prompt(self, number):
""" Given a prompt number, returns an HTML In prompt.
"""
body = self.in_prompt % number
return '<span class="in-prompt">%s</span>' % body
def _make_continuation_prompt(self, prompt):
""" Given a plain text version of an In prompt, returns an HTML
continuation prompt.
"""
end_chars = '...: '
space_count = len(prompt.lstrip('\n')) - len(end_chars)
body = '&nbsp;' * space_count + end_chars
return '<span class="in-prompt">%s</span>' % body
def _make_out_prompt(self, number):
""" Given a prompt number, returns an HTML Out prompt.
"""
body = self.out_prompt % number
return '<span class="out-prompt">%s</span>' % body
epatters
Made IPythonWidget and its subclasses Configurable.
r2884
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961 #------ Payload handlers --------------------------------------------------
# Payload handlers with a generic interface: each takes the opaque payload
# dict, unpacks it and calls the underlying functions with the necessary
# arguments.
def _handle_payload_edit(self, item):
self._edit(item['filename'], item['line_number'])
def _handle_payload_exit(self, item):
Erik Tollerud
Expanded %exit magic in qtconsole to not exit without prompting and...
r3183 self._keep_kernel_on_exit = item['keepkernel']
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961 self.exit_requested.emit()
epatters
Minor cleanup in IPythonWidget (fix long lines, method order, etc).
r3041 def _handle_payload_loadpy(self, item):
# Simple save the text of the .py file for later. The text is written
# to the buffer when _prompt_started_hook is called.
self._code_to_load = item['text']
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961 def _handle_payload_page(self, item):
epatters
Added support for HTML paging and HTML page payloads.
r3014 # Since the plain text widget supports only a very small subset of HTML
# and we have no control over the HTML source, we only page HTML
# payloads in the rich text widget.
if item['html'] and self.kind == 'rich':
self._page(item['html'], html=True)
else:
self._page(item['text'], html=False)
epatters
* Moved shutdown_kernel method from FrontendWidget to KernelManager....
r2961
Brian Granger
Mostly final version of display data....
r3277 #------ Trait change handlers --------------------------------------------
epatters
Made IPythonWidget and its subclasses Configurable.
r2884
def _style_sheet_changed(self):
""" Set the style sheets of the underlying widgets.
"""
self.setStyleSheet(self.style_sheet)
self._control.document().setDefaultStyleSheet(self.style_sheet)
if self._page_control:
self._page_control.document().setDefaultStyleSheet(self.style_sheet)
Evan Patterson
More PySide compatibility fixes.
r3305 bg_color = self._control.palette().window().color()
epatters
Made IPythonWidget and its subclasses Configurable.
r2884 self._ansi_processor.set_background_color(bg_color)
def _syntax_style_changed(self):
""" Set the style for the syntax highlighter.
"""
if self.syntax_style:
self._highlighter.set_style(self.syntax_style)
else:
self._highlighter.set_style_sheet(self.style_sheet)
Brian Granger
Mostly final version of display data....
r3277