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