##// END OF EJS Templates
add ConsoleWidget.include_other_output...
MinRK -
Show More
@@ -136,15 +136,23 b' class BaseFrontendMixin(object):'
136 136 handler = getattr(self, '_handle_' + msg_type, None)
137 137 if handler:
138 138 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:
148 155 return True
149 156 else:
150 return parent.get('session') == session
157 return from_here
158
@@ -519,7 +519,15 b" class ConsoleWidget(MetaQObjectHasTraits('NewBase', (LoggingConfigurable, QtGui."
519 519 #---------------------------------------------------------------------------
520 520 # 'ConsoleWidget' public interface
521 521 #---------------------------------------------------------------------------
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
523 531 def can_copy(self):
524 532 """ Returns whether text can be copied to the clipboard.
525 533 """
@@ -350,7 +350,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
350 350 #---------------------------------------------------------------------------
351 351 def _handle_clear_output(self, msg):
352 352 """Handle clear output messages."""
353 if not self._hidden and self._is_from_this_session(msg):
353 if include_output(msg):
354 354 wait = msg['content'].get('wait', True)
355 355 if wait:
356 356 self._pending_clearoutput = True
@@ -523,7 +523,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
523 523 """ Handle display hook output.
524 524 """
525 525 self.log.debug("execute_result: %s", msg.get('content', ''))
526 if not self._hidden and self._is_from_this_session(msg):
526 if self.include_output(msg):
527 527 self.flush_clearoutput()
528 528 text = msg['content']['data']
529 529 self._append_plain_text(text + '\n', before_prompt=True)
@@ -532,7 +532,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
532 532 """ Handle stdout, stderr, and stdin.
533 533 """
534 534 self.log.debug("stream: %s", msg.get('content', ''))
535 if not self._hidden and self._is_from_this_session(msg):
535 if self.include_output(msg):
536 536 self.flush_clearoutput()
537 537 self.append_stream(msg['content']['text'])
538 538
@@ -541,7 +541,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
541 541 """
542 542 self.log.info("shutdown: %s", msg.get('content', ''))
543 543 restart = msg.get('content', {}).get('restart', False)
544 if not self._hidden and not self._is_from_this_session(msg):
544 if not self._hidden and not self.from_here(msg):
545 545 # got shutdown reply, request came from session other than ours
546 546 if restart:
547 547 # someone restarted the kernel, handle it
@@ -220,11 +220,21 b' class IPythonWidget(FrontendWidget):'
220 220 last_cell = cell
221 221 self._set_history(items)
222 222
223 def _handle_execute_input(self, msg):
224 """Handle an execute_input message"""
225 self.log.debug("execute_input: %s", msg.get('content', ''))
226 if self.include_output(msg):
227 content = msg['content']
228 prompt_number = content.get('execution_count', 0)
229 self._append_html(self._make_in_prompt(prompt_number), True)
230 self._append_plain_text(content['code'], True)
231
232
223 233 def _handle_execute_result(self, msg):
224 234 """ Reimplemented for IPython-style "display hook".
225 235 """
226 236 self.log.debug("execute_result: %s", msg.get('content', ''))
227 if not self._hidden and self._is_from_this_session(msg):
237 if self.include_output(msg):
228 238 self.flush_clearoutput()
229 239 content = msg['content']
230 240 prompt_number = content.get('execution_count', 0)
@@ -246,7 +256,7 b' class IPythonWidget(FrontendWidget):'
246 256 # For now, we don't display data from other frontends, but we
247 257 # eventually will as this allows all frontends to monitor the display
248 258 # data. But we need to figure out how to handle this in the GUI.
249 if not self._hidden and self._is_from_this_session(msg):
259 if self.include_output(msg):
250 260 self.flush_clearoutput()
251 261 data = msg['content']['data']
252 262 metadata = msg['content']['metadata']
@@ -107,7 +107,7 b' class RichIPythonWidget(IPythonWidget):'
107 107 def _handle_execute_result(self, msg):
108 108 """ Overridden to handle rich data types, like SVG.
109 109 """
110 if not self._hidden and self._is_from_this_session(msg):
110 if self.include_output(msg):
111 111 self.flush_clearoutput()
112 112 content = msg['content']
113 113 prompt_number = content.get('execution_count', 0)
@@ -146,7 +146,7 b' class RichIPythonWidget(IPythonWidget):'
146 146 def _handle_display_data(self, msg):
147 147 """ Overridden to handle rich data types, like SVG.
148 148 """
149 if not self._hidden and self._is_from_this_session(msg):
149 if self.include_output(msg):
150 150 self.flush_clearoutput()
151 151 data = msg['content']['data']
152 152 metadata = msg['content']['metadata']
General Comments 0
You need to be logged in to leave comments. Login now