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