##// END OF EJS Templates
Merge pull request #8552 from SylvainCorlay/Backport_ipython_ipywidgets#60...
Merge pull request #8552 from SylvainCorlay/Backport_ipython_ipywidgets#60 Backport ipython/ipywidgets#60

File last commit:

r16113:87737521
r21470:518f4b92 merge
Show More
internal_ipkernel.py
55 lines | 2.0 KiB | text/x-python | PythonLexer
Fernando Perez
Add two examples of GUI applications that can summon Qt consoles....
r4489 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import sys
MinRK
update internal_ipkernel example to use connection files
r5267 from IPython.lib.kernel import connect_qtconsole
Martin Spacek
Fix typo
r11346 from IPython.kernel.zmq.kernelapp import IPKernelApp
Fernando Perez
Add two examples of GUI applications that can summon Qt consoles....
r4489
#-----------------------------------------------------------------------------
# Functions and classes
#-----------------------------------------------------------------------------
MinRK
remove pylab from internal_ipkernel example
r15184 def mpl_kernel(gui):
"""Launch and return an IPython kernel with matplotlib support for the desired gui
Fernando Perez
Add two examples of GUI applications that can summon Qt consoles....
r4489 """
MinRK
update internal_ipkernel example to use connection files
r5267 kernel = IPKernelApp.instance()
MinRK
remove pylab from internal_ipkernel example
r15184 kernel.initialize(['python', '--matplotlib=%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):
MinRK
remove pylab from internal_ipkernel example
r15184 # Start IPython kernel with GUI event loop and mpl support
self.ipkernel = mpl_kernel(backend)
Fernando Perez
Add two examples of GUI applications that can summon Qt consoles....
r4489 # 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
# 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***")
Thomas Kluyver
Improve Python 3 compatibility for example scripts.
r13991 for k, v in self.namespace.items():
MinRK
remove pylab from internal_ipkernel example
r15184 if 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()