##// END OF EJS Templates
add kernel banner to terminal and qt frontends
MinRK -
Show More
@@ -32,6 +32,7 b' from IPython.core.error import UsageError'
32 32 from IPython.core.magics import MacroToEdit, CodeMagics
33 33 from IPython.core.magic import magics_class, line_magic, Magics
34 34 from IPython.core.payloadpage import install_payload_page
35 from IPython.core.usage import default_gui_banner
35 36 from IPython.display import display, Javascript
36 37 from IPython.kernel.inprocess.socket import SocketABC
37 38 from IPython.kernel import (
@@ -422,6 +423,9 b' class ZMQInteractiveShell(InteractiveShell):'
422 423 data_pub_class = Type(ZMQDataPublisher)
423 424 kernel = Any()
424 425 parent_header = Any()
426
427 def _banner1_default(self):
428 return default_gui_banner
425 429
426 430 # Override the traitlet in the parent class, because there's no point using
427 431 # readline for the kernel. Can be removed when the readline code is moved
@@ -82,6 +82,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
82 82
83 83 # The text to show when the kernel is (re)started.
84 84 banner = Unicode(config=True)
85 kernel_banner = Unicode()
85 86
86 87 # An option and corresponding signal for overriding the default kernel
87 88 # interrupt behavior.
@@ -639,6 +640,9 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
639 640 if clear:
640 641 self._control.clear()
641 642 self._append_plain_text(self.banner)
643 if self.kernel_banner:
644 self._append_plain_text(self.kernel_banner)
645
642 646 # update output marker for stdout/stderr, so that startup
643 647 # messages appear after banner:
644 648 self._append_before_prompt_pos = self._get_cursor().position()
@@ -17,6 +17,7 b' from textwrap import dedent'
17 17 from IPython.external.qt import QtCore, QtGui
18 18
19 19 from IPython.core.inputsplitter import IPythonInputSplitter
20 from IPython.core.release import version
20 21 from IPython.core.inputtransformer import ipy_prompt
21 22 from IPython.utils.traitlets import Bool, Unicode
22 23 from .frontend_widget import FrontendWidget
@@ -107,6 +108,7 b' class IPythonWidget(FrontendWidget):'
107 108 _payload_source_next_input = 'set_next_input'
108 109 _payload_source_page = 'page'
109 110 _retrying_history_request = False
111 _starting = False
110 112
111 113 #---------------------------------------------------------------------------
112 114 # 'object' interface
@@ -253,31 +255,28 b' class IPythonWidget(FrontendWidget):'
253 255 self._append_plain_text(u'\n', True)
254 256
255 257 def _handle_kernel_info_reply(self, rep):
256 """ Handle kernel info replies.
257 """
258 """Handle kernel info replies."""
259 content = rep['content']
258 260 if not self._guiref_loaded:
259 if rep['content'].get('language') == 'python':
261 if content.get('language') == 'python':
260 262 self._load_guiref_magic()
261 263 self._guiref_loaded = True
264
265 self.kernel_banner = content.get('banner', '')
266 if self._starting:
267 # finish handling started channels
268 self._starting = False
269 super(IPythonWidget, self)._started_channels()
262 270
263 271 def _started_channels(self):
264 272 """Reimplemented to make a history request and load %guiref."""
265 super(IPythonWidget, self)._started_channels()
266
273 self._starting = True
267 274 # The reply will trigger %guiref load provided language=='python'
268 275 self.kernel_client.kernel_info()
269 276
270 277 self.kernel_client.shell_channel.history(hist_access_type='tail',
271 278 n=1000)
272 279
273 def _started_kernel(self):
274 """Load %guiref when the kernel starts (if channels are also started).
275
276 Principally triggered by kernel restart.
277 """
278 if self.kernel_client.shell_channel is not None:
279 self._load_guiref_magic()
280
281 280 def _load_guiref_magic(self):
282 281 """Load %guiref magic."""
283 282 self.kernel_client.shell_channel.execute('\n'.join([
@@ -568,5 +567,4 b' class IPythonWidget(FrontendWidget):'
568 567 #------ Trait default initializers -----------------------------------------
569 568
570 569 def _banner_default(self):
571 from IPython.core.usage import default_gui_banner
572 return default_gui_banner
570 return "IPython QtConsole {version}\n".format(version=version)
@@ -22,6 +22,7 b' except ImportError:'
22 22 from Queue import Empty # Py 2
23 23
24 24 from IPython.core import page
25 from IPython.core import release
25 26 from IPython.utils.warn import warn, error
26 27 from IPython.utils import io
27 28 from IPython.utils.py3compat import string_types, input
@@ -37,6 +38,7 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):'
37 38 _executing = False
38 39 _execution_state = Unicode('')
39 40 _pending_clearoutput = False
41 kernel_banner = Unicode('')
40 42 kernel_timeout = Float(60, config=True,
41 43 help="""Timeout for giving up on a kernel (in seconds).
42 44
@@ -366,7 +368,7 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):'
366 368 while True:
367 369 try:
368 370 self.interact(display_banner=display_banner)
369 #self.interact_with_readline()
371 #self.interact_with_readline()
370 372 # XXX for testing of a readline-decoupled repl loop, call
371 373 # interact_with_readline above
372 374 break
@@ -375,6 +377,24 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):'
375 377 # handling seems rather unpredictable...
376 378 self.write("\nKeyboardInterrupt in interact()\n")
377 379
380 def _banner1_default(self):
381 return "IPython Console {version}\n".format(version=release.version)
382
383 def compute_banner(self):
384 super(ZMQTerminalInteractiveShell, self).compute_banner()
385 if self.client and not self.kernel_banner:
386 msg_id = self.client.kernel_info()
387 while True:
388 try:
389 reply = self.client.get_shell_msg(timeout=1)
390 except Empty:
391 break
392 else:
393 if reply['parent_header'].get('msg_id') == msg_id:
394 self.kernel_banner = reply['content'].get('banner', '')
395 break
396 self.banner += self.kernel_banner
397
378 398 def wait_for_kernel(self, timeout=None):
379 399 """method to wait for a kernel to be ready"""
380 400 tic = time.time()
General Comments 0
You need to be logged in to leave comments. Login now