Show More
@@ -5,6 +5,7 b'' | |||||
5 | import subprocess |
|
5 | import subprocess | |
6 | import sys |
|
6 | import sys | |
7 |
|
7 | |||
|
8 | from IPython.lib.kernel import connect_qtconsole | |||
8 | from IPython.zmq.ipkernel import IPKernelApp |
|
9 | from IPython.zmq.ipkernel import IPKernelApp | |
9 |
|
10 | |||
10 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
@@ -13,27 +14,19 b' from IPython.zmq.ipkernel import IPKernelApp' | |||||
13 | def pylab_kernel(gui): |
|
14 | def pylab_kernel(gui): | |
14 | """Launch and return an IPython kernel with pylab support for the desired gui |
|
15 | """Launch and return an IPython kernel with pylab support for the desired gui | |
15 | """ |
|
16 | """ | |
16 | kernel = IPKernelApp() |
|
17 | kernel = IPKernelApp.instance() | |
17 | kernel.initialize(['python', '--pylab=%s' % gui, |
|
18 | kernel.initialize(['python', '--pylab=%s' % gui, | |
18 | #'--log-level=10' |
|
19 | #'--log-level=10' | |
19 | ]) |
|
20 | ]) | |
20 | return kernel |
|
21 | return kernel | |
21 |
|
22 | |||
22 |
|
23 | |||
23 | def qtconsole_cmd(kernel): |
|
|||
24 | """Compute the command to connect a qt console to an already running kernel |
|
|||
25 | """ |
|
|||
26 | ports = ['--%s=%d' % (name, port) for name, port in kernel.ports.items()] |
|
|||
27 | return ['ipython', 'qtconsole', '--existing'] + ports |
|
|||
28 |
|
||||
29 |
|
||||
30 | class InternalIPKernel(object): |
|
24 | class InternalIPKernel(object): | |
31 |
|
25 | |||
32 | def init_ipkernel(self, backend): |
|
26 | def init_ipkernel(self, backend): | |
33 | # Start IPython kernel with GUI event loop and pylab support |
|
27 | # Start IPython kernel with GUI event loop and pylab support | |
34 | self.ipkernel = pylab_kernel(backend) |
|
28 | self.ipkernel = pylab_kernel(backend) | |
35 | # To create and track active qt consoles |
|
29 | # To create and track active qt consoles | |
36 | self._qtconsole_cmd = qtconsole_cmd(self.ipkernel) |
|
|||
37 | self.consoles = [] |
|
30 | self.consoles = [] | |
38 |
|
31 | |||
39 | # This application will also act on the shell user namespace |
|
32 | # This application will also act on the shell user namespace | |
@@ -55,7 +48,8 b' class InternalIPKernel(object):' | |||||
55 | sys.stdout.flush() |
|
48 | sys.stdout.flush() | |
56 |
|
49 | |||
57 | def new_qt_console(self, evt=None): |
|
50 | def new_qt_console(self, evt=None): | |
58 | self.consoles.append(subprocess.Popen(self._qtconsole_cmd)) |
|
51 | """start a new qtconsole connected to our kernel""" | |
|
52 | return connect_qtconsole(self.ipkernel.connection_file, profile=self.ipkernel.profile) | |||
59 |
|
53 | |||
60 | def count(self, evt=None): |
|
54 | def count(self, evt=None): | |
61 | self.namespace['app_counter'] += 1 |
|
55 | self.namespace['app_counter'] += 1 |
General Comments 0
You need to be logged in to leave comments.
Login now