##// END OF EJS Templates
fix in process qt and in process examples
MinRK -
Show More
@@ -1,34 +1,40 b''
1 """ Defines an in-process KernelManager with signals and slots.
1 """ Defines an in-process KernelManager with signals and slots.
2 """
2 """
3
3
4 # Local imports.
4 # Local imports.
5 from IPython.kernel.inprocess import (
5 from IPython.kernel.inprocess import (
6 InProcessShellChannel, InProcessIOPubChannel, InProcessStdInChannel,
6 InProcessShellChannel, InProcessIOPubChannel, InProcessStdInChannel,
7 InProcessHBChannel, InProcessKernelClient
7 InProcessHBChannel, InProcessKernelClient, InProcessKernelManager,
8 )
8 )
9
9
10 from IPython.utils.traitlets import Type
10 from IPython.utils.traitlets import Type
11 from kernel_mixins import QtShellChannelMixin, QtIOPubChannelMixin, \
11 from .kernel_mixins import (
12 QtStdInChannelMixin, QtHBChannelMixin, QtKernelClientMixin
12 QtShellChannelMixin, QtIOPubChannelMixin,
13 QtStdInChannelMixin, QtHBChannelMixin, QtKernelClientMixin,
14 QtKernelManagerMixin,
15 )
13
16
14
17
15 class QtInProcessShellChannel(QtShellChannelMixin, InProcessShellChannel):
18 class QtInProcessShellChannel(QtShellChannelMixin, InProcessShellChannel):
16 pass
19 pass
17
20
18 class QtInProcessIOPubChannel(QtIOPubChannelMixin, InProcessIOPubChannel):
21 class QtInProcessIOPubChannel(QtIOPubChannelMixin, InProcessIOPubChannel):
19 pass
22 pass
20
23
21 class QtInProcessStdInChannel(QtStdInChannelMixin, InProcessStdInChannel):
24 class QtInProcessStdInChannel(QtStdInChannelMixin, InProcessStdInChannel):
22 pass
25 pass
23
26
24 class QtInProcessHBChannel(QtHBChannelMixin, InProcessHBChannel):
27 class QtInProcessHBChannel(QtHBChannelMixin, InProcessHBChannel):
25 pass
28 pass
26
29
27 class QtInProcessKernelClient(QtKernelClientMixin, InProcessKernelClient):
30 class QtInProcessKernelClient(QtKernelClientMixin, InProcessKernelClient):
28 """ An in-process KernelManager with signals and slots.
31 """ An in-process KernelManager with signals and slots.
29 """
32 """
30
33
31 iopub_channel_class = Type(QtInProcessIOPubChannel)
34 iopub_channel_class = Type(QtInProcessIOPubChannel)
32 shell_channel_class = Type(QtInProcessShellChannel)
35 shell_channel_class = Type(QtInProcessShellChannel)
33 stdin_channel_class = Type(QtInProcessStdInChannel)
36 stdin_channel_class = Type(QtInProcessStdInChannel)
34 hb_channel_class = Type(QtInProcessHBChannel)
37 hb_channel_class = Type(QtInProcessHBChannel)
38
39 class QtInProcessKernelManager(QtKernelManagerMixin, InProcessKernelManager):
40 client_class = __module__ + '.QtInProcessKernelClient'
@@ -1,46 +1,45 b''
1 import os
1 import os
2
2
3 from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
3 from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
4 from IPython.frontend.qt.inprocess import QtInProcessKernelClient
4 from IPython.frontend.qt.inprocess import QtInProcessKernelManager
5 from IPython.kernel.inprocess import InProcessKernelManager
6 from IPython.lib import guisupport
5 from IPython.lib import guisupport
7
6
8
7
9 def print_process_id():
8 def print_process_id():
10 print 'Process ID is:', os.getpid()
9 print 'Process ID is:', os.getpid()
11
10
12
11
13 def main():
12 def main():
14 # Print the ID of the main process
13 # Print the ID of the main process
15 print_process_id()
14 print_process_id()
16
15
17 app = guisupport.get_app_qt4()
16 app = guisupport.get_app_qt4()
18
17
19 # Create an in-process kernel
18 # Create an in-process kernel
20 # >>> print_process_id()
19 # >>> print_process_id()
21 # will print the same process ID as the main process
20 # will print the same process ID as the main process
22 kernel_manager = InProcessKernelManager()
21 kernel_manager = QtInProcessKernelManager()
23 kernel_manager.start_kernel()
22 kernel_manager.start_kernel()
24 kernel = kernel_manager.kernel
23 kernel = kernel_manager.kernel
25 kernel.gui = 'qt4'
24 kernel.gui = 'qt4'
26 kernel.shell.push({'foo': 43, 'print_process_id': print_process_id})
25 kernel.shell.push({'foo': 43, 'print_process_id': print_process_id})
27
26
28 kernel_client = QtInProcessKernelClient(kernel=kernel)
27 kernel_client = kernel_manager.client()
29 kernel_client.start_channels()
28 kernel_client.start_channels()
30
29
31 def stop():
30 def stop():
32 kernel_client.stop_channels()
31 kernel_client.stop_channels()
33 kernel_manager.shutdown_kernel()
32 kernel_manager.shutdown_kernel()
34 app.exit()
33 app.exit()
35
34
36 control = RichIPythonWidget()
35 control = RichIPythonWidget()
37 control.kernel_manager = kernel_manager
36 control.kernel_manager = kernel_manager
38 control.kernel_client = kernel_client
37 control.kernel_client = kernel_client
39 control.exit_requested.connect(stop)
38 control.exit_requested.connect(stop)
40 control.show()
39 control.show()
41
40
42 guisupport.start_event_loop_qt4(app)
41 guisupport.start_event_loop_qt4(app)
43
42
44
43
45 if __name__ == '__main__':
44 if __name__ == '__main__':
46 main()
45 main()
@@ -1,30 +1,30 b''
1 import os
1 import os
2
2
3 from IPython.kernel.inprocess import InProcessKernelManager
3 from IPython.kernel.inprocess import InProcessKernelManager
4 from IPython.frontend.terminal.console.interactiveshell import ZMQTerminalInteractiveShell
4 from IPython.frontend.terminal.console.interactiveshell import ZMQTerminalInteractiveShell
5
5
6
6
7 def print_process_id():
7 def print_process_id():
8 print 'Process ID is:', os.getpid()
8 print 'Process ID is:', os.getpid()
9
9
10
10
11 def main():
11 def main():
12 print_process_id()
12 print_process_id()
13
13
14 # Create an in-process kernel
14 # Create an in-process kernel
15 # >>> print_process_id()
15 # >>> print_process_id()
16 # will print the same process ID as the main process
16 # will print the same process ID as the main process
17 kernel_manager = InProcessKernelManager()
17 kernel_manager = InProcessKernelManager()
18 kernel_manager.start_kernel()
18 kernel_manager.start_kernel()
19 kernel = kernel_manager.kernel
19 kernel = kernel_manager.kernel
20 kernel.gui = 'qt4'
20 kernel.gui = 'qt4'
21 kernel.shell.push({'foo': 43, 'print_process_id': print_process_id})
21 kernel.shell.push({'foo': 43, 'print_process_id': print_process_id})
22 client = kernel_manager.client()
22 client = kernel_manager.client()
23 client.start_channels()
23 client.start_channels()
24
24
25 shell = ZMQTerminalInteractiveShell(kernel_manager=kernel_manager, kernel_client=client)
25 shell = ZMQTerminalInteractiveShell(manager=kernel_manager, client=client)
26 shell.mainloop()
26 shell.mainloop()
27
27
28
28
29 if __name__ == '__main__':
29 if __name__ == '__main__':
30 main()
30 main()
General Comments 0
You need to be logged in to leave comments. Login now