Show More
@@ -57,6 +57,7 b' from IPython.core.payload import PayloadManager' | |||||
57 | from IPython.core.prefilter import PrefilterManager |
|
57 | from IPython.core.prefilter import PrefilterManager | |
58 | from IPython.core.profiledir import ProfileDir |
|
58 | from IPython.core.profiledir import ProfileDir | |
59 | from IPython.core.prompts import PromptManager |
|
59 | from IPython.core.prompts import PromptManager | |
|
60 | from IPython.core.usage import default_banner | |||
60 | from IPython.lib.latextools import LaTeXTool |
|
61 | from IPython.lib.latextools import LaTeXTool | |
61 | from IPython.testing.skipdoctest import skip_doctest |
|
62 | from IPython.testing.skipdoctest import skip_doctest | |
62 | from IPython.utils import PyColorize |
|
63 | from IPython.utils import PyColorize | |
@@ -233,6 +234,16 b' class InteractiveShell(SingletonConfigurable):' | |||||
233 | Enable magic commands to be called without the leading %. |
|
234 | Enable magic commands to be called without the leading %. | |
234 | """ |
|
235 | """ | |
235 | ) |
|
236 | ) | |
|
237 | ||||
|
238 | banner = Unicode('') | |||
|
239 | ||||
|
240 | banner1 = Unicode(default_banner, config=True, | |||
|
241 | help="""The part of the banner to be printed before the profile""" | |||
|
242 | ) | |||
|
243 | banner2 = Unicode('', config=True, | |||
|
244 | help="""The part of the banner to be printed after the profile""" | |||
|
245 | ) | |||
|
246 | ||||
236 | cache_size = Integer(1000, config=True, help= |
|
247 | cache_size = Integer(1000, config=True, help= | |
237 | """ |
|
248 | """ | |
238 | Set the size of the output cache. The default is 1000, you can |
|
249 | Set the size of the output cache. The default is 1000, you can | |
@@ -442,6 +453,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
442 | self.init_profile_dir(profile_dir) |
|
453 | self.init_profile_dir(profile_dir) | |
443 | self.init_instance_attrs() |
|
454 | self.init_instance_attrs() | |
444 | self.init_environment() |
|
455 | self.init_environment() | |
|
456 | self.compute_banner() | |||
445 |
|
457 | |||
446 | # Check if we're in a virtualenv, and set up sys.path. |
|
458 | # Check if we're in a virtualenv, and set up sys.path. | |
447 | self.init_virtualenv() |
|
459 | self.init_virtualenv() | |
@@ -773,6 +785,28 b' class InteractiveShell(SingletonConfigurable):' | |||||
773 | sys.modules[self._orig_sys_modules_main_name] = self._orig_sys_modules_main_mod |
|
785 | sys.modules[self._orig_sys_modules_main_name] = self._orig_sys_modules_main_mod | |
774 |
|
786 | |||
775 | #------------------------------------------------------------------------- |
|
787 | #------------------------------------------------------------------------- | |
|
788 | # Things related to the banner | |||
|
789 | #------------------------------------------------------------------------- | |||
|
790 | ||||
|
791 | def _banner1_changed(self): | |||
|
792 | self.compute_banner() | |||
|
793 | ||||
|
794 | def _banner2_changed(self): | |||
|
795 | self.compute_banner() | |||
|
796 | ||||
|
797 | def compute_banner(self): | |||
|
798 | self.banner = self.banner1 | |||
|
799 | if self.profile and self.profile != 'default': | |||
|
800 | self.banner += '\nIPython profile: %s\n' % self.profile | |||
|
801 | if self.banner2: | |||
|
802 | self.banner += '\n' + self.banner2 | |||
|
803 | ||||
|
804 | def show_banner(self, banner=None): | |||
|
805 | if banner is None: | |||
|
806 | banner = self.banner | |||
|
807 | self.write(banner) | |||
|
808 | ||||
|
809 | #------------------------------------------------------------------------- | |||
776 | # Things related to hooks |
|
810 | # Things related to hooks | |
777 | #------------------------------------------------------------------------- |
|
811 | #------------------------------------------------------------------------- | |
778 |
|
812 |
@@ -75,24 +75,17 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||||
75 | # Like the base class display_banner is not configurable, but here it |
|
75 | # Like the base class display_banner is not configurable, but here it | |
76 | # is True by default. |
|
76 | # is True by default. | |
77 | display_banner = CBool(True) |
|
77 | display_banner = CBool(True) | |
|
78 | exit_msg = Unicode() | |||
|
79 | ||||
78 |
|
80 | |||
79 | def __init__(self, config=None, ipython_dir=None, user_ns=None, |
|
81 | def __init__(self, **kw): | |
80 | user_module=None, custom_exceptions=((),None), |
|
82 | ||
81 | usage=None, banner1=None, banner2=None, |
|
|||
82 | display_banner=None, exit_msg=u'', user_global_ns=None): |
|
|||
83 |
|
83 | |||
84 | if user_global_ns is not None: |
|
84 | if kw.get('user_global_ns', None) is not None: | |
85 | warnings.warn("user_global_ns has been replaced by user_module. The\ |
|
85 | warnings.warn("user_global_ns has been replaced by user_module. The\ | |
86 | parameter will be ignored.", DeprecationWarning) |
|
86 | parameter will be ignored.", DeprecationWarning) | |
87 |
|
87 | |||
88 | super(InteractiveShellEmbed,self).__init__( |
|
88 | super(InteractiveShellEmbed,self).__init__(**kw) | |
89 | config=config, ipython_dir=ipython_dir, user_ns=user_ns, |
|
|||
90 | user_module=user_module, custom_exceptions=custom_exceptions, |
|
|||
91 | usage=usage, banner1=banner1, banner2=banner2, |
|
|||
92 | display_banner=display_banner |
|
|||
93 | ) |
|
|||
94 |
|
||||
95 | self.exit_msg = exit_msg |
|
|||
96 |
|
89 | |||
97 | # don't use the ipython crash handler so that user exceptions aren't |
|
90 | # don't use the ipython crash handler so that user exceptions aren't | |
98 | # trapped |
|
91 | # trapped |
@@ -20,7 +20,7 b' import os' | |||||
20 | import sys |
|
20 | import sys | |
21 |
|
21 | |||
22 | from IPython.core.error import TryNext, UsageError |
|
22 | from IPython.core.error import TryNext, UsageError | |
23 |
from IPython.core.usage import interactive_usage |
|
23 | from IPython.core.usage import interactive_usage | |
24 | from IPython.core.inputsplitter import IPythonInputSplitter |
|
24 | from IPython.core.inputsplitter import IPythonInputSplitter | |
25 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC |
|
25 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC | |
26 | from IPython.core.magic import Magics, magics_class, line_magic |
|
26 | from IPython.core.magic import Magics, magics_class, line_magic | |
@@ -258,13 +258,6 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
258 |
|
258 | |||
259 | autoedit_syntax = CBool(False, config=True, |
|
259 | autoedit_syntax = CBool(False, config=True, | |
260 | help="auto editing of files with syntax errors.") |
|
260 | help="auto editing of files with syntax errors.") | |
261 | banner = Unicode('') |
|
|||
262 | banner1 = Unicode(default_banner, config=True, |
|
|||
263 | help="""The part of the banner to be printed before the profile""" |
|
|||
264 | ) |
|
|||
265 | banner2 = Unicode('', config=True, |
|
|||
266 | help="""The part of the banner to be printed after the profile""" |
|
|||
267 | ) |
|
|||
268 | confirm_exit = CBool(True, config=True, |
|
261 | confirm_exit = CBool(True, config=True, | |
269 | help=""" |
|
262 | help=""" | |
270 | Set to confirm when you try to exit IPython with an EOF (Control-D |
|
263 | Set to confirm when you try to exit IPython with an EOF (Control-D | |
@@ -274,8 +267,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
274 | # This display_banner only controls whether or not self.show_banner() |
|
267 | # This display_banner only controls whether or not self.show_banner() | |
275 | # is called when mainloop/interact are called. The default is False |
|
268 | # is called when mainloop/interact are called. The default is False | |
276 | # because for the terminal based application, the banner behavior |
|
269 | # because for the terminal based application, the banner behavior | |
277 | # is controlled by Global.display_banner, which IPythonApp looks at |
|
270 | # is controlled by the application. | |
278 | # to determine if *it* should call show_banner() by hand or not. |
|
|||
279 | display_banner = CBool(False) # This isn't configurable! |
|
271 | display_banner = CBool(False) # This isn't configurable! | |
280 | embedded = CBool(False) |
|
272 | embedded = CBool(False) | |
281 | embedded_active = CBool(False) |
|
273 | embedded_active = CBool(False) | |
@@ -300,6 +292,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
300 | term_title = CBool(False, config=True, |
|
292 | term_title = CBool(False, config=True, | |
301 | help="Enable auto setting the terminal title." |
|
293 | help="Enable auto setting the terminal title." | |
302 | ) |
|
294 | ) | |
|
295 | usage = Unicode(interactive_usage) | |||
303 |
|
296 | |||
304 | # This `using_paste_magics` is used to detect whether the code is being |
|
297 | # This `using_paste_magics` is used to detect whether the code is being | |
305 | # executed via paste magics functions |
|
298 | # executed via paste magics functions | |
@@ -317,23 +310,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
317 | except ValueError as e: |
|
310 | except ValueError as e: | |
318 | raise UsageError("%s" % e) |
|
311 | raise UsageError("%s" % e) | |
319 |
|
312 | |||
320 | def __init__(self, config=None, ipython_dir=None, profile_dir=None, |
|
313 | system = InteractiveShell.system_raw | |
321 | user_ns=None, user_module=None, custom_exceptions=((),None), |
|
|||
322 | usage=None, banner1=None, banner2=None, display_banner=None, |
|
|||
323 | **kwargs): |
|
|||
324 |
|
||||
325 | super(TerminalInteractiveShell, self).__init__( |
|
|||
326 | config=config, ipython_dir=ipython_dir, profile_dir=profile_dir, user_ns=user_ns, |
|
|||
327 | user_module=user_module, custom_exceptions=custom_exceptions, |
|
|||
328 | **kwargs |
|
|||
329 | ) |
|
|||
330 | # use os.system instead of utils.process.system by default, |
|
|||
331 | # because piped system doesn't make sense in the Terminal: |
|
|||
332 | self.system = self.system_raw |
|
|||
333 |
|
||||
334 | self.init_term_title() |
|
|||
335 | self.init_usage(usage) |
|
|||
336 | self.init_banner(banner1, banner2, display_banner) |
|
|||
337 |
|
314 | |||
338 | #------------------------------------------------------------------------- |
|
315 | #------------------------------------------------------------------------- | |
339 | # Overrides of init stages |
|
316 | # Overrides of init stages | |
@@ -356,6 +333,9 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
356 | num_lines_bot = self.separate_in.count('\n')+1 |
|
333 | num_lines_bot = self.separate_in.count('\n')+1 | |
357 | return self.screen_length - num_lines_bot |
|
334 | return self.screen_length - num_lines_bot | |
358 |
|
335 | |||
|
336 | def _term_title_changed(self, name, new_value): | |||
|
337 | self.init_term_title() | |||
|
338 | ||||
359 | def init_term_title(self): |
|
339 | def init_term_title(self): | |
360 | # Enable or disable the terminal title. |
|
340 | # Enable or disable the terminal title. | |
361 | if self.term_title: |
|
341 | if self.term_title: | |
@@ -386,46 +366,6 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
386 | self.alias_manager.soft_define_alias(name, cmd) |
|
366 | self.alias_manager.soft_define_alias(name, cmd) | |
387 |
|
367 | |||
388 | #------------------------------------------------------------------------- |
|
368 | #------------------------------------------------------------------------- | |
389 | # Things related to the banner and usage |
|
|||
390 | #------------------------------------------------------------------------- |
|
|||
391 |
|
||||
392 | def _banner1_changed(self): |
|
|||
393 | self.compute_banner() |
|
|||
394 |
|
||||
395 | def _banner2_changed(self): |
|
|||
396 | self.compute_banner() |
|
|||
397 |
|
||||
398 | def _term_title_changed(self, name, new_value): |
|
|||
399 | self.init_term_title() |
|
|||
400 |
|
||||
401 | def init_banner(self, banner1, banner2, display_banner): |
|
|||
402 | if banner1 is not None: |
|
|||
403 | self.banner1 = banner1 |
|
|||
404 | if banner2 is not None: |
|
|||
405 | self.banner2 = banner2 |
|
|||
406 | if display_banner is not None: |
|
|||
407 | self.display_banner = display_banner |
|
|||
408 | self.compute_banner() |
|
|||
409 |
|
||||
410 | def show_banner(self, banner=None): |
|
|||
411 | if banner is None: |
|
|||
412 | banner = self.banner |
|
|||
413 | self.write(banner) |
|
|||
414 |
|
||||
415 | def compute_banner(self): |
|
|||
416 | self.banner = self.banner1 |
|
|||
417 | if self.profile and self.profile != 'default': |
|
|||
418 | self.banner += '\nIPython profile: %s\n' % self.profile |
|
|||
419 | if self.banner2: |
|
|||
420 | self.banner += '\n' + self.banner2 |
|
|||
421 |
|
||||
422 | def init_usage(self, usage=None): |
|
|||
423 | if usage is None: |
|
|||
424 | self.usage = interactive_usage |
|
|||
425 | else: |
|
|||
426 | self.usage = usage |
|
|||
427 |
|
||||
428 | #------------------------------------------------------------------------- |
|
|||
429 | # Mainloop and code execution logic |
|
369 | # Mainloop and code execution logic | |
430 | #------------------------------------------------------------------------- |
|
370 | #------------------------------------------------------------------------- | |
431 |
|
371 |
General Comments 0
You need to be logged in to leave comments.
Login now