Show More
@@ -197,6 +197,9 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
197 | self._local_kernel = kw.get('local_kernel', |
|
197 | self._local_kernel = kw.get('local_kernel', | |
198 | FrontendWidget._local_kernel) |
|
198 | FrontendWidget._local_kernel) | |
199 |
|
199 | |||
|
200 | # Whether or not a clear_output call is pending new output. | |||
|
201 | self._pending_clearoutput = False | |||
|
202 | ||||
200 | #--------------------------------------------------------------------------- |
|
203 | #--------------------------------------------------------------------------- | |
201 | # 'ConsoleWidget' public interface |
|
204 | # 'ConsoleWidget' public interface | |
202 | #--------------------------------------------------------------------------- |
|
205 | #--------------------------------------------------------------------------- | |
@@ -339,6 +342,14 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
339 | #--------------------------------------------------------------------------- |
|
342 | #--------------------------------------------------------------------------- | |
340 | # 'BaseFrontendMixin' abstract interface |
|
343 | # 'BaseFrontendMixin' abstract interface | |
341 | #--------------------------------------------------------------------------- |
|
344 | #--------------------------------------------------------------------------- | |
|
345 | def _handle_clear_output(self, msg): | |||
|
346 | """Handle clear output messages.""" | |||
|
347 | if not self._hidden and self._is_from_this_session(msg): | |||
|
348 | wait = msg['content'].get('wait', True) | |||
|
349 | if wait: | |||
|
350 | self._pending_clearoutput = True | |||
|
351 | else: | |||
|
352 | self.clear_output() | |||
342 |
|
353 | |||
343 | def _handle_complete_reply(self, rep): |
|
354 | def _handle_complete_reply(self, rep): | |
344 | """ Handle replies for tab completion. |
|
355 | """ Handle replies for tab completion. | |
@@ -520,6 +531,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
520 | """ |
|
531 | """ | |
521 | self.log.debug("pyout: %s", msg.get('content', '')) |
|
532 | self.log.debug("pyout: %s", msg.get('content', '')) | |
522 | if not self._hidden and self._is_from_this_session(msg): |
|
533 | if not self._hidden and self._is_from_this_session(msg): | |
|
534 | self.flush_clearoutput() | |||
523 | text = msg['content']['data'] |
|
535 | text = msg['content']['data'] | |
524 | self._append_plain_text(text + '\n', before_prompt=True) |
|
536 | self._append_plain_text(text + '\n', before_prompt=True) | |
525 |
|
537 | |||
@@ -528,13 +540,8 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
528 | """ |
|
540 | """ | |
529 | self.log.debug("stream: %s", msg.get('content', '')) |
|
541 | self.log.debug("stream: %s", msg.get('content', '')) | |
530 | if not self._hidden and self._is_from_this_session(msg): |
|
542 | if not self._hidden and self._is_from_this_session(msg): | |
531 | # Most consoles treat tabs as being 8 space characters. Convert tabs |
|
543 | self.flush_clearoutput() | |
532 | # to spaces so that output looks as expected regardless of this |
|
544 | self.append_stream(msg['content']['data']) | |
533 | # widget's tab width. |
|
|||
534 | text = msg['content']['data'].expandtabs(8) |
|
|||
535 |
|
||||
536 | self._append_plain_text(text, before_prompt=True) |
|
|||
537 | self._control.moveCursor(QtGui.QTextCursor.End) |
|
|||
538 |
|
545 | |||
539 | def _handle_shutdown_reply(self, msg): |
|
546 | def _handle_shutdown_reply(self, msg): | |
540 | """ Handle shutdown signal, only if from other console. |
|
547 | """ Handle shutdown signal, only if from other console. | |
@@ -685,6 +692,31 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
685 | before_prompt=True |
|
692 | before_prompt=True | |
686 | ) |
|
693 | ) | |
687 |
|
694 | |||
|
695 | def append_stream(self, text): | |||
|
696 | """Appends text to the output stream.""" | |||
|
697 | # Most consoles treat tabs as being 8 space characters. Convert tabs | |||
|
698 | # to spaces so that output looks as expected regardless of this | |||
|
699 | # widget's tab width. | |||
|
700 | text = text.expandtabs(8) | |||
|
701 | ||||
|
702 | print([ord(c) for c in text]) | |||
|
703 | self._append_plain_text(text, before_prompt=True) | |||
|
704 | self._control.moveCursor(QtGui.QTextCursor.End) | |||
|
705 | ||||
|
706 | def flush_clearoutput(self): | |||
|
707 | """If a clearoutput is pending, execute it.""" | |||
|
708 | if self._pending_clearoutput: | |||
|
709 | self._pending_clearoutput = False | |||
|
710 | self.clear_output() | |||
|
711 | ||||
|
712 | def clear_output(self): | |||
|
713 | """Clear the output area.""" | |||
|
714 | cursor = self._control.textCursor() | |||
|
715 | cursor.beginEditBlock() | |||
|
716 | cursor.movePosition(cursor.StartOfLine, cursor.KeepAnchor) | |||
|
717 | cursor.insertText('') | |||
|
718 | cursor.endEditBlock() | |||
|
719 | ||||
688 | #--------------------------------------------------------------------------- |
|
720 | #--------------------------------------------------------------------------- | |
689 | # 'FrontendWidget' protected interface |
|
721 | # 'FrontendWidget' protected interface | |
690 | #--------------------------------------------------------------------------- |
|
722 | #--------------------------------------------------------------------------- |
@@ -140,7 +140,6 b' class IPythonWidget(FrontendWidget):' | |||||
140 | #--------------------------------------------------------------------------- |
|
140 | #--------------------------------------------------------------------------- | |
141 | # 'BaseFrontendMixin' abstract interface |
|
141 | # 'BaseFrontendMixin' abstract interface | |
142 | #--------------------------------------------------------------------------- |
|
142 | #--------------------------------------------------------------------------- | |
143 |
|
||||
144 | def _handle_complete_reply(self, rep): |
|
143 | def _handle_complete_reply(self, rep): | |
145 | """ Reimplemented to support IPython's improved completion machinery. |
|
144 | """ Reimplemented to support IPython's improved completion machinery. | |
146 | """ |
|
145 | """ | |
@@ -223,6 +222,7 b' class IPythonWidget(FrontendWidget):' | |||||
223 | """ |
|
222 | """ | |
224 | self.log.debug("pyout: %s", msg.get('content', '')) |
|
223 | self.log.debug("pyout: %s", msg.get('content', '')) | |
225 | if not self._hidden and self._is_from_this_session(msg): |
|
224 | if not self._hidden and self._is_from_this_session(msg): | |
|
225 | self.flush_clearoutput() | |||
226 | content = msg['content'] |
|
226 | content = msg['content'] | |
227 | prompt_number = content.get('execution_count', 0) |
|
227 | prompt_number = content.get('execution_count', 0) | |
228 | data = content['data'] |
|
228 | data = content['data'] | |
@@ -250,6 +250,7 b' class IPythonWidget(FrontendWidget):' | |||||
250 | # eventually will as this allows all frontends to monitor the display |
|
250 | # eventually will as this allows all frontends to monitor the display | |
251 | # data. But we need to figure out how to handle this in the GUI. |
|
251 | # data. But we need to figure out how to handle this in the GUI. | |
252 | if not self._hidden and self._is_from_this_session(msg): |
|
252 | if not self._hidden and self._is_from_this_session(msg): | |
|
253 | self.flush_clearoutput() | |||
253 | source = msg['content']['source'] |
|
254 | source = msg['content']['source'] | |
254 | data = msg['content']['data'] |
|
255 | data = msg['content']['data'] | |
255 | metadata = msg['content']['metadata'] |
|
256 | metadata = msg['content']['metadata'] |
@@ -114,6 +114,7 b' class RichIPythonWidget(IPythonWidget):' | |||||
114 | """ Overridden to handle rich data types, like SVG. |
|
114 | """ Overridden to handle rich data types, like SVG. | |
115 | """ |
|
115 | """ | |
116 | if not self._hidden and self._is_from_this_session(msg): |
|
116 | if not self._hidden and self._is_from_this_session(msg): | |
|
117 | self.flush_clearoutput() | |||
117 | content = msg['content'] |
|
118 | content = msg['content'] | |
118 | prompt_number = content.get('execution_count', 0) |
|
119 | prompt_number = content.get('execution_count', 0) | |
119 | data = content['data'] |
|
120 | data = content['data'] | |
@@ -140,6 +141,7 b' class RichIPythonWidget(IPythonWidget):' | |||||
140 | """ Overridden to handle rich data types, like SVG. |
|
141 | """ Overridden to handle rich data types, like SVG. | |
141 | """ |
|
142 | """ | |
142 | if not self._hidden and self._is_from_this_session(msg): |
|
143 | if not self._hidden and self._is_from_this_session(msg): | |
|
144 | self.flush_clearoutput() | |||
143 | source = msg['content']['source'] |
|
145 | source = msg['content']['source'] | |
144 | data = msg['content']['data'] |
|
146 | data = msg['content']['data'] | |
145 | metadata = msg['content']['metadata'] |
|
147 | metadata = msg['content']['metadata'] |
General Comments 0
You need to be logged in to leave comments.
Login now