##// END OF EJS Templates
This feature was discussed in #6123, but it doesn't look like anything was ever incorporated into the IPython Notebook....
This feature was discussed in #6123, but it doesn't look like anything was ever incorporated into the IPython Notebook. Here's a brief overview of the changes: - Display of messages from other clients can be toggled on and off from within a notebook, either using the ``<M-m>e`` keyboard shortcut in the web UI, or through the option in the "Kernel" menu. - notebook.js controls whether messages are displayed through a callback that is invoked from kernel.js when no callbacks are available for a message. - The UI displays ``execute_input`` messages originating from an other clients in new cells at the end of the notebook. Output messages (``execute_result`` et al.) will only be displayed if a cell exists with a matching message ID. Pending design questions: - Should each ``execute_input`` message cause a new cell to be created? - Should new cells be placed at the end of the notebook, or elsewhere? If the latter, what criteria should be followed?

File last commit:

r11585:7814ebf2
r19164:17ac8ca3
Show More
frontend.py
79 lines | 3.1 KiB | text/x-python | PythonLexer
Fernando Perez
Add proper warnings on use of the backwards compatibility shim.
r11015 """
Shim to maintain backwards compatibility with old frontend imports.
We have moved all contents of the old `frontend` subpackage into top-level
MinRK
note notebook move in frontend.py docstring
r11037 subpackages (`html`, `qt` and `terminal`), and flattened the notebook into
just `IPython.html`, formerly `IPython.frontend.html.notebook`.
Fernando Perez
Fix all remaining imports that used `IPython.frontend`.
r11024
This will let code that was making `from IPython.frontend...` calls continue
working, though a warning will be printed.
Fernando Perez
Add proper warnings on use of the backwards compatibility shim.
r11015 """
#-----------------------------------------------------------------------------
# Copyright (c) 2013, IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from __future__ import print_function
Fernando Perez
Replace exec/eval with proper __import__....
r11019
# Stdlib
Fernando Perez
Add shim module to allow flattening of namespace.
r11008 import sys
import types
Fernando Perez
Fix imports for plain terminal ipython and use a proper warn() call.
r11020 from warnings import warn
Fernando Perez
Add shim module to allow flattening of namespace.
r11008
Fernando Perez
Fix imports for plain terminal ipython and use a proper warn() call.
r11020 warn("The top-level `frontend` package has been deprecated. "
"All its subpackages have been moved to the top `IPython` level.")
Fernando Perez
Replace exec/eval with proper __import__....
r11019
Fernando Perez
Add proper warnings on use of the backwards compatibility shim.
r11015 #-----------------------------------------------------------------------------
# Class declarations
#-----------------------------------------------------------------------------
Fernando Perez
Add shim module to allow flattening of namespace.
r11008
class ShimModule(types.ModuleType):
MinRK
update shim to support .frontend.html.notebook->.html
r11036
def __init__(self, *args, **kwargs):
self._mirror = kwargs.pop("mirror")
super(ShimModule, self).__init__(*args, **kwargs)
Fernando Perez
Add shim module to allow flattening of namespace.
r11008
MinRK
update shim to support .frontend.html.notebook->.html
r11036 def __getattr__(self, key):
Fernando Perez
Replace exec/eval with proper __import__....
r11019 # Use the equivalent of import_item(name), see below
MinRK
update shim to support .frontend.html.notebook->.html
r11036 name = "%s.%s" % (self._mirror, key)
Fernando Perez
Replace exec/eval with proper __import__....
r11019
# NOTE: the code below is copied *verbatim* from
# importstring.import_item. For some very strange reason that makes no
# sense to me, if we call it *as a function*, it doesn't work. This
# has something to do with the deep bowels of the import machinery and
# I couldn't find a way to make the code work as a standard function
# call. But at least since it's an unmodified copy of import_item,
# which is used extensively and has a test suite, we can be reasonably
# confident this is OK. If anyone finds how to call the function, all
# the below could be replaced simply with:
#
# from IPython.utils.importstring import import_item
MinRK
update shim to support .frontend.html.notebook->.html
r11036 # return import_item('MIRROR.' + key)
Fernando Perez
Add proper warnings on use of the backwards compatibility shim.
r11015
Fernando Perez
Replace exec/eval with proper __import__....
r11019 parts = name.rsplit('.', 1)
if len(parts) == 2:
# called with 'foo.bar....'
package, obj = parts
module = __import__(package, fromlist=[obj])
try:
pak = module.__dict__[obj]
except KeyError:
MinRK
raise AttributeError on missing attribute in ShimModule...
r11585 raise AttributeError(obj)
Fernando Perez
Replace exec/eval with proper __import__....
r11019 return pak
else:
# called with un-dotted string
return __import__(parts[0])
Fernando Perez
Add shim module to allow flattening of namespace.
r11008
Fernando Perez
Add proper warnings on use of the backwards compatibility shim.
r11015
# Unconditionally insert the shim into sys.modules so that further import calls
# trigger the custom attribute access above
MinRK
update shim to support .frontend.html.notebook->.html
r11036 sys.modules['IPython.frontend.html.notebook'] = ShimModule('notebook', mirror='IPython.html')
sys.modules['IPython.frontend'] = ShimModule('frontend', mirror='IPython')