##// END OF EJS Templates
Strip prompts even if the prompt isn't present on the first line....
Strip prompts even if the prompt isn't present on the first line. Users (including me) often copy and paste examples from just after the first prompt. This checks for prompts in the first two lines of a block, but if they aren't found there, it will ignore prompt-like prefixes in later lines, to minimise interference with multi-line strings etc. Closes gh-3206

File last commit:

r9455:89fe4319
r10652:e3df40cf
Show More
internal_ipkernel.py
59 lines | 2.2 KiB | text/x-python | PythonLexer
/ examples / lib / internal_ipkernel.py
Fernando Perez
Add two examples of GUI applications that can summon Qt consoles....
r4489 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import subprocess
import sys
MinRK
update internal_ipkernel example to use connection files
r5267 from IPython.lib.kernel import connect_qtconsole
Martin Spacek
`IPython.zmq` --> `IPython.kernel.zmq` throughout docs and examples
r9455 from IPython.kernel.zmq.ipkernel import IPKernelApp
Fernando Perez
Add two examples of GUI applications that can summon Qt consoles....
r4489
#-----------------------------------------------------------------------------
# Functions and classes
#-----------------------------------------------------------------------------
def pylab_kernel(gui):
"""Launch and return an IPython kernel with pylab support for the desired gui
"""
MinRK
update internal_ipkernel example to use connection files
r5267 kernel = IPKernelApp.instance()
MinRK
remove hardcoded hb port from internal example...
r4502 kernel.initialize(['python', '--pylab=%s' % gui,
Fernando Perez
Add two examples of GUI applications that can summon Qt consoles....
r4489 #'--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):
Thomas Kluyver
Make print syntax in GUI integration examples Python 3 compatible.
r6453 print("\n***Variables in User namespace***")
Fernando Perez
Add two examples of GUI applications that can summon Qt consoles....
r4489 for k, v in self.namespace.iteritems():
if k not in self._init_keys and not k.startswith('_'):
Thomas Kluyver
Make print syntax in GUI integration examples Python 3 compatible.
r6453 print('%s -> %r' % (k, v))
Fernando Perez
Add two examples of GUI applications that can summon Qt consoles....
r4489 sys.stdout.flush()
def new_qt_console(self, evt=None):
MinRK
update internal_ipkernel example to use connection files
r5267 """start a new qtconsole connected to our kernel"""
return connect_qtconsole(self.ipkernel.connection_file, profile=self.ipkernel.profile)
Fernando Perez
Add two examples of GUI applications that can summon Qt consoles....
r4489
def count(self, evt=None):
self.namespace['app_counter'] += 1
def cleanup_consoles(self, evt=None):
for c in self.consoles:
c.kill()