Show More
@@ -1,58 +1,55 b'' | |||
|
1 | 1 | #----------------------------------------------------------------------------- |
|
2 | 2 | # Imports |
|
3 | 3 | #----------------------------------------------------------------------------- |
|
4 | 4 | |
|
5 | 5 | import sys |
|
6 | 6 | |
|
7 | 7 | from IPython.lib.kernel import connect_qtconsole |
|
8 | 8 | from IPython.kernel.zmq.kernelapp import IPKernelApp |
|
9 | 9 | |
|
10 | 10 | #----------------------------------------------------------------------------- |
|
11 | 11 | # Functions and classes |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 |
def p |
|
|
14 |
"""Launch and return an IPython kernel with |
|
|
13 | def mpl_kernel(gui): | |
|
14 | """Launch and return an IPython kernel with matplotlib support for the desired gui | |
|
15 | 15 | """ |
|
16 | 16 | kernel = IPKernelApp.instance() |
|
17 |
kernel.initialize(['python', '-- |
|
|
17 | kernel.initialize(['python', '--matplotlib=%s' % gui, | |
|
18 | 18 | #'--log-level=10' |
|
19 | 19 | ]) |
|
20 | 20 | return kernel |
|
21 | 21 | |
|
22 | 22 | |
|
23 | 23 | class InternalIPKernel(object): |
|
24 | 24 | |
|
25 | 25 | def init_ipkernel(self, backend): |
|
26 |
# Start IPython kernel with GUI event loop and p |
|
|
27 |
self.ipkernel = p |
|
|
26 | # Start IPython kernel with GUI event loop and mpl support | |
|
27 | self.ipkernel = mpl_kernel(backend) | |
|
28 | 28 | # To create and track active qt consoles |
|
29 | 29 | self.consoles = [] |
|
30 | 30 | |
|
31 | 31 | # This application will also act on the shell user namespace |
|
32 | 32 | self.namespace = self.ipkernel.shell.user_ns |
|
33 | # Keys present at startup so we don't print the entire pylab/numpy | |
|
34 | # namespace when the user clicks the 'namespace' button | |
|
35 | self._init_keys = set(self.namespace.keys()) | |
|
36 | 33 | |
|
37 | 34 | # Example: a variable that will be seen by the user in the shell, and |
|
38 | 35 | # that the GUI modifies (the 'Counter++' button increments it): |
|
39 | 36 | self.namespace['app_counter'] = 0 |
|
40 | 37 | #self.namespace['ipkernel'] = self.ipkernel # dbg |
|
41 | 38 | |
|
42 | 39 | def print_namespace(self, evt=None): |
|
43 | 40 | print("\n***Variables in User namespace***") |
|
44 | 41 | for k, v in self.namespace.items(): |
|
45 |
if |
|
|
42 | if not k.startswith('_'): | |
|
46 | 43 | print('%s -> %r' % (k, v)) |
|
47 | 44 | sys.stdout.flush() |
|
48 | 45 | |
|
49 | 46 | def new_qt_console(self, evt=None): |
|
50 | 47 | """start a new qtconsole connected to our kernel""" |
|
51 | 48 | return connect_qtconsole(self.ipkernel.connection_file, profile=self.ipkernel.profile) |
|
52 | 49 | |
|
53 | 50 | def count(self, evt=None): |
|
54 | 51 | self.namespace['app_counter'] += 1 |
|
55 | 52 | |
|
56 | 53 | def cleanup_consoles(self, evt=None): |
|
57 | 54 | for c in self.consoles: |
|
58 | 55 | c.kill() |
General Comments 0
You need to be logged in to leave comments.
Login now