Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add ConsoleWidget.include_other_output
matches zmq console. Doesn't include `[remote] ` prefix,
because true async output makes it less important.
  • Loading branch information
minrk committed Oct 16, 2014
commit 3b0d8c07032e67cd7e438a88410647a8c78063c7
28 changes: 18 additions & 10 deletions IPython/qt/base_frontend_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,23 @@ def _dispatch(self, msg):
handler = getattr(self, '_handle_' + msg_type, None)
if handler:
handler(msg)

def _is_from_this_session(self, msg):
""" Returns whether a reply from the kernel originated from a request
from this frontend.
"""
session = self._kernel_client.session.session
parent = msg['parent_header']
if not parent:
# if the message has no parent, assume it is meant for all frontends

def from_here(self, msg):
"""Return whether a message is from this session"""
session_id = self._kernel_client.session.session
return msg['parent_header'].get("session", session_id) == session_id

def include_output(self, msg):
"""Return whether we should include a given output message"""
if self._hidden:
return False
from_here = self.from_here(msg)
if msg['msg_type'] == 'execute_input':
# only echo inputs not from here
return self.include_other_output and not from_here

if self.include_other_output:
return True
else:
return parent.get('session') == session
return from_here

10 changes: 9 additions & 1 deletion IPython/qt/console/console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,15 @@ def sizeHint(self):
#---------------------------------------------------------------------------
# 'ConsoleWidget' public interface
#---------------------------------------------------------------------------


include_other_output = Bool(False, config=True,
help="""Whether to include output from clients
other than this one sharing the same kernel.

Outputs are not displayed until enter is pressed.
"""
)

def can_copy(self):
""" Returns whether text can be copied to the clipboard.
"""
Expand Down
8 changes: 4 additions & 4 deletions IPython/qt/console/frontend_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def _insert_continuation_prompt(self, cursor):
#---------------------------------------------------------------------------
def _handle_clear_output(self, msg):
"""Handle clear output messages."""
if not self._hidden and self._is_from_this_session(msg):
if include_output(msg):
wait = msg['content'].get('wait', True)
if wait:
self._pending_clearoutput = True
Expand Down Expand Up @@ -523,7 +523,7 @@ def _handle_execute_result(self, msg):
""" Handle display hook output.
"""
self.log.debug("execute_result: %s", msg.get('content', ''))
if not self._hidden and self._is_from_this_session(msg):
if self.include_output(msg):
self.flush_clearoutput()
text = msg['content']['data']
self._append_plain_text(text + '\n', before_prompt=True)
Expand All @@ -532,7 +532,7 @@ def _handle_stream(self, msg):
""" Handle stdout, stderr, and stdin.
"""
self.log.debug("stream: %s", msg.get('content', ''))
if not self._hidden and self._is_from_this_session(msg):
if self.include_output(msg):
self.flush_clearoutput()
self.append_stream(msg['content']['text'])

Expand All @@ -541,7 +541,7 @@ def _handle_shutdown_reply(self, msg):
"""
self.log.info("shutdown: %s", msg.get('content', ''))
restart = msg.get('content', {}).get('restart', False)
if not self._hidden and not self._is_from_this_session(msg):
if not self._hidden and not self.from_here(msg):
# got shutdown reply, request came from session other than ours
if restart:
# someone restarted the kernel, handle it
Expand Down
14 changes: 12 additions & 2 deletions IPython/qt/console/ipython_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,21 @@ def _handle_history_reply(self, msg):
last_cell = cell
self._set_history(items)

def _handle_execute_input(self, msg):
"""Handle an execute_input message"""
self.log.debug("execute_input: %s", msg.get('content', ''))
if self.include_output(msg):
content = msg['content']
prompt_number = content.get('execution_count', 0)
self._append_html(self._make_in_prompt(prompt_number), True)
self._append_plain_text(content['code'], True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this will display the code without highlighting. Is it easy to highlight it? I'm happy to leave it plain if not.



def _handle_execute_result(self, msg):
""" Reimplemented for IPython-style "display hook".
"""
self.log.debug("execute_result: %s", msg.get('content', ''))
if not self._hidden and self._is_from_this_session(msg):
if self.include_output(msg):
self.flush_clearoutput()
content = msg['content']
prompt_number = content.get('execution_count', 0)
Expand All @@ -246,7 +256,7 @@ def _handle_display_data(self, msg):
# 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):
if self.include_output(msg):
self.flush_clearoutput()
data = msg['content']['data']
metadata = msg['content']['metadata']
Expand Down
4 changes: 2 additions & 2 deletions IPython/qt/console/rich_ipython_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _pre_image_append(self, msg, prompt_number):
def _handle_execute_result(self, msg):
""" Overridden to handle rich data types, like SVG.
"""
if not self._hidden and self._is_from_this_session(msg):
if self.include_output(msg):
self.flush_clearoutput()
content = msg['content']
prompt_number = content.get('execution_count', 0)
Expand Down Expand Up @@ -146,7 +146,7 @@ def _handle_execute_result(self, msg):
def _handle_display_data(self, msg):
""" Overridden to handle rich data types, like SVG.
"""
if not self._hidden and self._is_from_this_session(msg):
if self.include_output(msg):
self.flush_clearoutput()
data = msg['content']['data']
metadata = msg['content']['metadata']
Expand Down