Show More
@@ -1,70 +1,75 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.external.qt import QtCore |
|
5 | from IPython.external.qt import QtCore | |
6 | from IPython.kernel.inprocess import ( |
|
6 | from IPython.kernel.inprocess import ( | |
7 | InProcessHBChannel, InProcessKernelClient, InProcessKernelManager, |
|
7 | InProcessHBChannel, InProcessKernelClient, InProcessKernelManager, | |
8 | ) |
|
8 | ) | |
9 | from IPython.kernel.inprocess.channels import InProcessChannel |
|
9 | from IPython.kernel.inprocess.channels import InProcessChannel | |
10 |
|
10 | |||
11 | from IPython.utils.traitlets import Type |
|
11 | from IPython.utils.traitlets import Type | |
12 | from .util import SuperQObject |
|
12 | from .util import SuperQObject | |
13 | from .kernel_mixins import ( |
|
13 | from .kernel_mixins import ( | |
14 | QtKernelClientMixin, QtKernelManagerMixin, |
|
14 | QtKernelClientMixin, QtKernelManagerMixin, | |
15 | ) |
|
15 | ) | |
16 |
|
16 | |||
17 | class QtInProcessChannel(SuperQObject, InProcessChannel): |
|
17 | class QtInProcessChannel(SuperQObject, InProcessChannel): | |
18 | # Emitted when the channel is started. |
|
18 | # Emitted when the channel is started. | |
19 | started = QtCore.Signal() |
|
19 | started = QtCore.Signal() | |
20 |
|
20 | |||
21 | # Emitted when the channel is stopped. |
|
21 | # Emitted when the channel is stopped. | |
22 | stopped = QtCore.Signal() |
|
22 | stopped = QtCore.Signal() | |
23 |
|
23 | |||
24 | # Emitted when any message is received. |
|
24 | # Emitted when any message is received. | |
25 | message_received = QtCore.Signal(object) |
|
25 | message_received = QtCore.Signal(object) | |
26 |
|
26 | |||
27 | def start(self): |
|
27 | def start(self): | |
28 | """ Reimplemented to emit signal. |
|
28 | """ Reimplemented to emit signal. | |
29 | """ |
|
29 | """ | |
30 | super(QtInProcessChannel, self).start() |
|
30 | super(QtInProcessChannel, self).start() | |
31 | self.started.emit() |
|
31 | self.started.emit() | |
32 |
|
32 | |||
33 | def stop(self): |
|
33 | def stop(self): | |
34 | """ Reimplemented to emit signal. |
|
34 | """ Reimplemented to emit signal. | |
35 | """ |
|
35 | """ | |
36 | super(QtInProcessChannel, self).stop() |
|
36 | super(QtInProcessChannel, self).stop() | |
37 | self.stopped.emit() |
|
37 | self.stopped.emit() | |
38 |
|
38 | |||
39 | def call_handlers_later(self, *args, **kwds): |
|
39 | def call_handlers_later(self, *args, **kwds): | |
40 | """ Call the message handlers later. |
|
40 | """ Call the message handlers later. | |
41 | """ |
|
41 | """ | |
42 | do_later = lambda: self.call_handlers(*args, **kwds) |
|
42 | do_later = lambda: self.call_handlers(*args, **kwds) | |
43 | QtCore.QTimer.singleShot(0, do_later) |
|
43 | QtCore.QTimer.singleShot(0, do_later) | |
44 |
|
44 | |||
45 | def call_handlers(self, msg): |
|
45 | def call_handlers(self, msg): | |
46 | self.message_received.emit(msg) |
|
46 | self.message_received.emit(msg) | |
47 |
|
47 | |||
48 | def process_events(self): |
|
48 | def process_events(self): | |
49 | """ Process any pending GUI events. |
|
49 | """ Process any pending GUI events. | |
50 | """ |
|
50 | """ | |
51 | QtCore.QCoreApplication.instance().processEvents() |
|
51 | QtCore.QCoreApplication.instance().processEvents() | |
52 |
|
52 | |||
53 | def flush(self, timeout=1.0): |
|
53 | def flush(self, timeout=1.0): | |
54 | """ Reimplemented to ensure that signals are dispatched immediately. |
|
54 | """ Reimplemented to ensure that signals are dispatched immediately. | |
55 | """ |
|
55 | """ | |
56 | super(QtInProcessChannel, self).flush() |
|
56 | super(QtInProcessChannel, self).flush() | |
57 | self.process_events() |
|
57 | self.process_events() | |
58 |
|
58 | |||
|
59 | ||||
|
60 | class QtInProcessHBChannel(SuperQObject, InProcessHBChannel): | |||
|
61 | # This signal will never be fired, but it needs to exist | |||
|
62 | kernel_died = QtCore.Signal() | |||
|
63 | ||||
59 |
|
64 | |||
60 | class QtInProcessKernelClient(QtKernelClientMixin, InProcessKernelClient): |
|
65 | class QtInProcessKernelClient(QtKernelClientMixin, InProcessKernelClient): | |
61 | """ An in-process KernelManager with signals and slots. |
|
66 | """ An in-process KernelManager with signals and slots. | |
62 | """ |
|
67 | """ | |
63 |
|
68 | |||
64 | iopub_channel_class = Type(QtInProcessChannel) |
|
69 | iopub_channel_class = Type(QtInProcessChannel) | |
65 | shell_channel_class = Type(QtInProcessChannel) |
|
70 | shell_channel_class = Type(QtInProcessChannel) | |
66 | stdin_channel_class = Type(QtInProcessChannel) |
|
71 | stdin_channel_class = Type(QtInProcessChannel) | |
67 | hb_channel_class = Type(InProcessHBChannel) |
|
72 | hb_channel_class = Type(QtInProcessHBChannel) | |
68 |
|
73 | |||
69 | class QtInProcessKernelManager(QtKernelManagerMixin, InProcessKernelManager): |
|
74 | class QtInProcessKernelManager(QtKernelManagerMixin, InProcessKernelManager): | |
70 | client_class = __module__ + '.QtInProcessKernelClient' |
|
75 | client_class = __module__ + '.QtInProcessKernelClient' |
General Comments 0
You need to be logged in to leave comments.
Login now