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

Skip to content

Commit 8781cc0

Browse files
committed
add ConsoleWidget.include_other_output
matches zmq console. Doesn't include `[remote] ` prefix, because true async output makes it less important.
1 parent d4e3191 commit 8781cc0

5 files changed

Lines changed: 45 additions & 19 deletions

File tree

IPython/qt/base_frontend_mixin.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,23 @@ def _dispatch(self, msg):
136136
handler = getattr(self, '_handle_' + msg_type, None)
137137
if handler:
138138
handler(msg)
139-
140-
def _is_from_this_session(self, msg):
141-
""" Returns whether a reply from the kernel originated from a request
142-
from this frontend.
143-
"""
144-
session = self._kernel_client.session.session
145-
parent = msg['parent_header']
146-
if not parent:
147-
# if the message has no parent, assume it is meant for all frontends
139+
140+
def from_here(self, msg):
141+
"""Return whether a message is from this session"""
142+
session_id = self._kernel_client.session.session
143+
return msg['parent_header'].get("session", session_id) == session_id
144+
145+
def include_output(self, msg):
146+
"""Return whether we should include a given output message"""
147+
if self._hidden:
148+
return False
149+
from_here = self.from_here(msg)
150+
if msg['msg_type'] == 'execute_input':
151+
# only echo inputs not from here
152+
return self.include_other_output and not from_here
153+
154+
if self.include_other_output:
148155
return True
149156
else:
150-
return parent.get('session') == session
157+
return from_here
158+

IPython/qt/console/console_widget.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,15 @@ def sizeHint(self):
519519
#---------------------------------------------------------------------------
520520
# 'ConsoleWidget' public interface
521521
#---------------------------------------------------------------------------
522-
522+
523+
include_other_output = Bool(False, config=True,
524+
help="""Whether to include output from clients
525+
other than this one sharing the same kernel.
526+
527+
Outputs are not displayed until enter is pressed.
528+
"""
529+
)
530+
523531
def can_copy(self):
524532
""" Returns whether text can be copied to the clipboard.
525533
"""

IPython/qt/console/frontend_widget.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def _insert_continuation_prompt(self, cursor):
347347
#---------------------------------------------------------------------------
348348
def _handle_clear_output(self, msg):
349349
"""Handle clear output messages."""
350-
if not self._hidden and self._is_from_this_session(msg):
350+
if not include_output(msg):
351351
wait = msg['content'].get('wait', True)
352352
if wait:
353353
self._pending_clearoutput = True
@@ -520,7 +520,7 @@ def _handle_execute_result(self, msg):
520520
""" Handle display hook output.
521521
"""
522522
self.log.debug("execute_result: %s", msg.get('content', ''))
523-
if not self._hidden and self._is_from_this_session(msg):
523+
if self.include_output(msg):
524524
self.flush_clearoutput()
525525
text = msg['content']['data']
526526
self._append_plain_text(text + '\n', before_prompt=True)
@@ -529,7 +529,7 @@ def _handle_stream(self, msg):
529529
""" Handle stdout, stderr, and stdin.
530530
"""
531531
self.log.debug("stream: %s", msg.get('content', ''))
532-
if not self._hidden and self._is_from_this_session(msg):
532+
if self.include_output(msg):
533533
self.flush_clearoutput()
534534
self.append_stream(msg['content']['data'])
535535

@@ -538,7 +538,7 @@ def _handle_shutdown_reply(self, msg):
538538
"""
539539
self.log.info("shutdown: %s", msg.get('content', ''))
540540
restart = msg.get('content', {}).get('restart', False)
541-
if not self._hidden and not self._is_from_this_session(msg):
541+
if not self._hidden and not self.from_here(msg):
542542
# got shutdown reply, request came from session other than ours
543543
if restart:
544544
# someone restarted the kernel, handle it

IPython/qt/console/ipython_widget.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,21 @@ def _handle_history_reply(self, msg):
205205
last_cell = cell
206206
self._set_history(items)
207207

208+
def _handle_execute_input(self, msg):
209+
"""Handle an execute_input message"""
210+
self.log.debug("execute_input: %s", msg.get('content', ''))
211+
if self.include_output(msg):
212+
content = msg['content']
213+
prompt_number = content.get('execution_count', 0)
214+
self._append_html(self._make_in_prompt(prompt_number), True)
215+
self._append_plain_text(content['code'], True)
216+
217+
208218
def _handle_execute_result(self, msg):
209219
""" Reimplemented for IPython-style "display hook".
210220
"""
211221
self.log.debug("execute_result: %s", msg.get('content', ''))
212-
if not self._hidden and self._is_from_this_session(msg):
222+
if self.include_output(msg):
213223
self.flush_clearoutput()
214224
content = msg['content']
215225
prompt_number = content.get('execution_count', 0)
@@ -231,7 +241,7 @@ def _handle_display_data(self, msg):
231241
# For now, we don't display data from other frontends, but we
232242
# eventually will as this allows all frontends to monitor the display
233243
# data. But we need to figure out how to handle this in the GUI.
234-
if not self._hidden and self._is_from_this_session(msg):
244+
if self.include_output(msg):
235245
self.flush_clearoutput()
236246
data = msg['content']['data']
237247
metadata = msg['content']['metadata']

IPython/qt/console/rich_ipython_widget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _pre_image_append(self, msg, prompt_number):
107107
def _handle_execute_result(self, msg):
108108
""" Overridden to handle rich data types, like SVG.
109109
"""
110-
if not self._hidden and self._is_from_this_session(msg):
110+
if self.include_output(msg):
111111
self.flush_clearoutput()
112112
content = msg['content']
113113
prompt_number = content.get('execution_count', 0)
@@ -146,7 +146,7 @@ def _handle_execute_result(self, msg):
146146
def _handle_display_data(self, msg):
147147
""" Overridden to handle rich data types, like SVG.
148148
"""
149-
if not self._hidden and self._is_from_this_session(msg):
149+
if self.include_output(msg):
150150
self.flush_clearoutput()
151151
data = msg['content']['data']
152152
metadata = msg['content']['metadata']

0 commit comments

Comments
 (0)