From 3b0d8c07032e67cd7e438a88410647a8c78063c7 2014-10-16 19:13:10 From: MinRK Date: 2014-10-16 19:13:10 Subject: [PATCH] add ConsoleWidget.include_other_output matches zmq console. Doesn't include `[remote] ` prefix, because true async output makes it less important. --- diff --git a/IPython/qt/base_frontend_mixin.py b/IPython/qt/base_frontend_mixin.py index d03be9b..d317a9c 100644 --- a/IPython/qt/base_frontend_mixin.py +++ b/IPython/qt/base_frontend_mixin.py @@ -136,15 +136,23 @@ class BaseFrontendMixin(object): 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 + diff --git a/IPython/qt/console/console_widget.py b/IPython/qt/console/console_widget.py index 7a41e5a..f8794df 100644 --- a/IPython/qt/console/console_widget.py +++ b/IPython/qt/console/console_widget.py @@ -519,7 +519,15 @@ class ConsoleWidget(MetaQObjectHasTraits('NewBase', (LoggingConfigurable, QtGui. #--------------------------------------------------------------------------- # '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. """ diff --git a/IPython/qt/console/frontend_widget.py b/IPython/qt/console/frontend_widget.py index 37be0da..87a4b26 100644 --- a/IPython/qt/console/frontend_widget.py +++ b/IPython/qt/console/frontend_widget.py @@ -350,7 +350,7 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): #--------------------------------------------------------------------------- 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 @@ -523,7 +523,7 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): """ 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) @@ -532,7 +532,7 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): """ 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']) @@ -541,7 +541,7 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): """ 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 diff --git a/IPython/qt/console/ipython_widget.py b/IPython/qt/console/ipython_widget.py index e6e5171..37db61e 100644 --- a/IPython/qt/console/ipython_widget.py +++ b/IPython/qt/console/ipython_widget.py @@ -220,11 +220,21 @@ class IPythonWidget(FrontendWidget): 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) + + 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) @@ -246,7 +256,7 @@ class IPythonWidget(FrontendWidget): # 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'] diff --git a/IPython/qt/console/rich_ipython_widget.py b/IPython/qt/console/rich_ipython_widget.py index 60247e7..2105019 100644 --- a/IPython/qt/console/rich_ipython_widget.py +++ b/IPython/qt/console/rich_ipython_widget.py @@ -107,7 +107,7 @@ class RichIPythonWidget(IPythonWidget): 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) @@ -146,7 +146,7 @@ class RichIPythonWidget(IPythonWidget): 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']