Show More
@@ -112,4 +112,13 b' def post_execute():' | |||||
112 | @_collect |
|
112 | @_collect | |
113 | def post_execute_explicit(): |
|
113 | def post_execute_explicit(): | |
114 | """Fires after user-entered code runs.""" |
|
114 | """Fires after user-entered code runs.""" | |
115 | pass No newline at end of file |
|
115 | pass | |
|
116 | ||||
|
117 | @_collect | |||
|
118 | def shell_initialised(ip): | |||
|
119 | """Fires after initialisation of :class:`~IPython.core.interactiveshell.InteractiveShell`. | |||
|
120 | ||||
|
121 | This is before extensions and startup scripts are loaded, so it can only be | |||
|
122 | set by subclassing. | |||
|
123 | """ | |||
|
124 | pass |
@@ -49,6 +49,11 b" __all__ = ['editor', 'fix_error_editor', 'synchronize_with_editor'," | |||||
49 | 'show_in_pager','pre_prompt_hook', |
|
49 | 'show_in_pager','pre_prompt_hook', | |
50 | 'pre_run_code_hook', 'clipboard_get'] |
|
50 | 'pre_run_code_hook', 'clipboard_get'] | |
51 |
|
51 | |||
|
52 | deprecated = {'pre_run_code_hook': "a callback for the 'pre_execute' or 'pre_execute_explicit' event", | |||
|
53 | 'late_startup_hook': "a callback for the 'shell_initialised' event", | |||
|
54 | 'shutdown_hook': "the atexit module", | |||
|
55 | } | |||
|
56 | ||||
52 | def editor(self, filename, linenum=None, wait=True): |
|
57 | def editor(self, filename, linenum=None, wait=True): | |
53 | """Open the default editor at the given filename and linenumber. |
|
58 | """Open the default editor at the given filename and linenumber. | |
54 |
|
59 |
@@ -512,6 +512,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
512 | self.init_payload() |
|
512 | self.init_payload() | |
513 | self.init_comms() |
|
513 | self.init_comms() | |
514 | self.hooks.late_startup_hook() |
|
514 | self.hooks.late_startup_hook() | |
|
515 | self.callbacks.fire('shell_initialised', self) | |||
515 | atexit.register(self.atexit_operations) |
|
516 | atexit.register(self.atexit_operations) | |
516 |
|
517 | |||
517 | def get_ipython(self): |
|
518 | def get_ipython(self): | |
@@ -787,9 +788,10 b' class InteractiveShell(SingletonConfigurable):' | |||||
787 | for hook_name in hooks.__all__: |
|
788 | for hook_name in hooks.__all__: | |
788 | # default hooks have priority 100, i.e. low; user hooks should have |
|
789 | # default hooks have priority 100, i.e. low; user hooks should have | |
789 | # 0-100 priority |
|
790 | # 0-100 priority | |
790 | self.set_hook(hook_name,getattr(hooks,hook_name), 100) |
|
791 | self.set_hook(hook_name,getattr(hooks,hook_name), 100, _warn_deprecated=False) | |
791 |
|
792 | |||
792 |
def set_hook(self,name,hook, priority |
|
793 | def set_hook(self,name,hook, priority=50, str_key=None, re_key=None, | |
|
794 | _warn_deprecated=True): | |||
793 | """set_hook(name,hook) -> sets an internal IPython hook. |
|
795 | """set_hook(name,hook) -> sets an internal IPython hook. | |
794 |
|
796 | |||
795 | IPython exposes some of its internal API as user-modifiable hooks. By |
|
797 | IPython exposes some of its internal API as user-modifiable hooks. By | |
@@ -818,6 +820,11 b' class InteractiveShell(SingletonConfigurable):' | |||||
818 | if name not in IPython.core.hooks.__all__: |
|
820 | if name not in IPython.core.hooks.__all__: | |
819 | print("Warning! Hook '%s' is not one of %s" % \ |
|
821 | print("Warning! Hook '%s' is not one of %s" % \ | |
820 | (name, IPython.core.hooks.__all__ )) |
|
822 | (name, IPython.core.hooks.__all__ )) | |
|
823 | ||||
|
824 | if _warn_deprecated and (name in IPython.core.hooks.deprecated): | |||
|
825 | alternative = IPython.core.hooks.deprecated[name] | |||
|
826 | warn("Hook {} is deprecated. Use {} instead.".format(name, alternative)) | |||
|
827 | ||||
821 | if not dp: |
|
828 | if not dp: | |
822 | dp = IPython.core.hooks.CommandChainDispatcher() |
|
829 | dp = IPython.core.hooks.CommandChainDispatcher() | |
823 |
|
830 |
General Comments 0
You need to be logged in to leave comments.
Login now