##// END OF EJS Templates
avoid references to fiel out of directory...
avoid references to fiel out of directory request for packaging, it would be nice for example not to reference files outside of exampel directory copy ../../_static/logo.png in logo/logo.png use subfolder for demo purpose of targetting subfolder in demo notebook

File last commit:

r6453:48b94819
r9992:713f1db0
Show More
internal_ipkernel.py
59 lines | 2.2 KiB | text/x-python | PythonLexer
/ docs / examples / lib / internal_ipkernel.py
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import subprocess
import sys
from IPython.lib.kernel import connect_qtconsole
from IPython.zmq.ipkernel import IPKernelApp
#-----------------------------------------------------------------------------
# Functions and classes
#-----------------------------------------------------------------------------
def pylab_kernel(gui):
"""Launch and return an IPython kernel with pylab support for the desired gui
"""
kernel = IPKernelApp.instance()
kernel.initialize(['python', '--pylab=%s' % gui,
#'--log-level=10'
])
return kernel
class InternalIPKernel(object):
def init_ipkernel(self, backend):
# Start IPython kernel with GUI event loop and pylab support
self.ipkernel = pylab_kernel(backend)
# To create and track active qt consoles
self.consoles = []
# This application will also act on the shell user namespace
self.namespace = self.ipkernel.shell.user_ns
# Keys present at startup so we don't print the entire pylab/numpy
# namespace when the user clicks the 'namespace' button
self._init_keys = set(self.namespace.keys())
# Example: a variable that will be seen by the user in the shell, and
# that the GUI modifies (the 'Counter++' button increments it):
self.namespace['app_counter'] = 0
#self.namespace['ipkernel'] = self.ipkernel # dbg
def print_namespace(self, evt=None):
print("\n***Variables in User namespace***")
for k, v in self.namespace.iteritems():
if k not in self._init_keys and not k.startswith('_'):
print('%s -> %r' % (k, v))
sys.stdout.flush()
def new_qt_console(self, evt=None):
"""start a new qtconsole connected to our kernel"""
return connect_qtconsole(self.ipkernel.connection_file, profile=self.ipkernel.profile)
def count(self, evt=None):
self.namespace['app_counter'] += 1
def cleanup_consoles(self, evt=None):
for c in self.consoles:
c.kill()