##// END OF EJS Templates
Merge Qt*ChannelMixin up into QtInProcess*Channel classes
Thomas Kluyver -
Show More
@@ -2,27 +2,102 b''
2 """
2 """
3
3
4 # Local imports.
4 # Local imports.
5 from IPython.external.qt import QtCore
5 from IPython.kernel.inprocess import (
6 from IPython.kernel.inprocess import (
6 InProcessShellChannel, InProcessIOPubChannel, InProcessStdInChannel,
7 InProcessShellChannel, InProcessIOPubChannel, InProcessStdInChannel,
7 InProcessHBChannel, InProcessKernelClient, InProcessKernelManager,
8 InProcessHBChannel, InProcessKernelClient, InProcessKernelManager,
8 )
9 )
9
10
10 from IPython.utils.traitlets import Type
11 from IPython.utils.traitlets import Type
11 from .kernel_mixins import (
12 from .kernel_mixins import ( ChannelQObject,
12 QtShellChannelMixin, QtIOPubChannelMixin,
13 QtHBChannelMixin, QtKernelClientMixin,
13 QtStdInChannelMixin, QtHBChannelMixin, QtKernelClientMixin,
14 QtKernelManagerMixin,
14 QtKernelManagerMixin,
15 )
15 )
16
16
17
17
18 class QtInProcessShellChannel(QtShellChannelMixin, InProcessShellChannel):
18 class QtInProcessShellChannel(ChannelQObject, InProcessShellChannel):
19 pass
19 # Emitted when a reply has been received for the corresponding request type.
20 execute_reply = QtCore.Signal(object)
21 complete_reply = QtCore.Signal(object)
22 inspect_reply = QtCore.Signal(object)
23 history_reply = QtCore.Signal(object)
24 kernel_info_reply = QtCore.Signal(object)
20
25
21 class QtInProcessIOPubChannel(QtIOPubChannelMixin, InProcessIOPubChannel):
26 def call_handlers(self, msg):
22 pass
27 """ Reimplemented to emit signals instead of making callbacks.
28 """
29 # Emit the generic signal.
30 self.message_received.emit(msg)
23
31
24 class QtInProcessStdInChannel(QtStdInChannelMixin, InProcessStdInChannel):
32 # Emit signals for specialized message types.
25 pass
33 msg_type = msg['header']['msg_type']
34 if msg_type == 'kernel_info_reply':
35 self._handle_kernel_info_reply(msg)
36
37 signal = getattr(self, msg_type, None)
38 if signal:
39 signal.emit(msg)
40
41 class QtInProcessIOPubChannel(ChannelQObject, InProcessIOPubChannel):
42 # Emitted when a message of type 'stream' is received.
43 stream_received = QtCore.Signal(object)
44
45 # Emitted when a message of type 'execute_input' is received.
46 execute_input_received = QtCore.Signal(object)
47
48 # Emitted when a message of type 'execute_result' is received.
49 execute_result_received = QtCore.Signal(object)
50
51 # Emitted when a message of type 'error' is received.
52 error_received = QtCore.Signal(object)
53
54 # Emitted when a message of type 'display_data' is received
55 display_data_received = QtCore.Signal(object)
56
57 # Emitted when a crash report message is received from the kernel's
58 # last-resort sys.excepthook.
59 crash_received = QtCore.Signal(object)
60
61 # Emitted when a shutdown is noticed.
62 shutdown_reply_received = QtCore.Signal(object)
63
64 #---------------------------------------------------------------------------
65 # 'IOPubChannel' interface
66 #---------------------------------------------------------------------------
67
68 def call_handlers(self, msg):
69 """ Reimplemented to emit signals instead of making callbacks.
70 """
71 # Emit the generic signal.
72 self.message_received.emit(msg)
73 # Emit signals for specialized message types.
74 msg_type = msg['header']['msg_type']
75 signal = getattr(self, msg_type + '_received', None)
76 if signal:
77 signal.emit(msg)
78 elif msg_type in ('stdout', 'stderr'):
79 self.stream_received.emit(msg)
80
81 def flush(self):
82 """ Reimplemented to ensure that signals are dispatched immediately.
83 """
84 super(QtInProcessIOPubChannel, self).flush()
85 QtCore.QCoreApplication.instance().processEvents()
86
87 class QtInProcessStdInChannel(ChannelQObject, InProcessStdInChannel):
88 # Emitted when an input request is received.
89 input_requested = QtCore.Signal(object)
90
91 def call_handlers(self, msg):
92 """ Reimplemented to emit signals instead of making callbacks.
93 """
94 # Emit the generic signal.
95 self.message_received.emit(msg)
96
97 # Emit signals for specialized message types.
98 msg_type = msg['header']['msg_type']
99 if msg_type == 'input_request':
100 self.input_requested.emit(msg)
26
101
27 class QtInProcessHBChannel(QtHBChannelMixin, InProcessHBChannel):
102 class QtInProcessHBChannel(QtHBChannelMixin, InProcessHBChannel):
28 pass
103 pass
@@ -17,6 +17,13 b' class ChannelQObject(SuperQObject):'
17 # Emitted when the channel is stopped.
17 # Emitted when the channel is stopped.
18 stopped = QtCore.Signal()
18 stopped = QtCore.Signal()
19
19
20 # Emitted when any message is received.
21 message_received = QtCore.Signal(object)
22
23 #---------------------------------------------------------------------------
24 # Channel interface
25 #---------------------------------------------------------------------------
26
20 def start(self):
27 def start(self):
21 """ Reimplemented to emit signal.
28 """ Reimplemented to emit signal.
22 """
29 """
@@ -45,99 +52,6 b' class ChannelQObject(SuperQObject):'
45 QtCore.QCoreApplication.instance().processEvents()
52 QtCore.QCoreApplication.instance().processEvents()
46
53
47
54
48 class QtShellChannelMixin(ChannelQObject):
49
50 # Emitted when any message is received.
51 message_received = QtCore.Signal(object)
52
53 # Emitted when a reply has been received for the corresponding request type.
54 execute_reply = QtCore.Signal(object)
55 complete_reply = QtCore.Signal(object)
56 inspect_reply = QtCore.Signal(object)
57 history_reply = QtCore.Signal(object)
58 kernel_info_reply = QtCore.Signal(object)
59
60 def call_handlers(self, msg):
61 """ Reimplemented to emit signals instead of making callbacks.
62 """
63 # Emit the generic signal.
64 self.message_received.emit(msg)
65
66 # Emit signals for specialized message types.
67 msg_type = msg['header']['msg_type']
68 if msg_type == 'kernel_info_reply':
69 self._handle_kernel_info_reply(msg)
70
71 signal = getattr(self, msg_type, None)
72 if signal:
73 signal.emit(msg)
74
75
76 class QtIOPubChannelMixin(ChannelQObject):
77
78 # Emitted when any message is received.
79 message_received = QtCore.Signal(object)
80
81 # Emitted when a message of type 'stream' is received.
82 stream_received = QtCore.Signal(object)
83
84 # Emitted when a message of type 'execute_input' is received.
85 execute_input_received = QtCore.Signal(object)
86
87 # Emitted when a message of type 'execute_result' is received.
88 execute_result_received = QtCore.Signal(object)
89
90 # Emitted when a message of type 'error' is received.
91 error_received = QtCore.Signal(object)
92
93 # Emitted when a message of type 'display_data' is received
94 display_data_received = QtCore.Signal(object)
95
96 # Emitted when a crash report message is received from the kernel's
97 # last-resort sys.excepthook.
98 crash_received = QtCore.Signal(object)
99
100 # Emitted when a shutdown is noticed.
101 shutdown_reply_received = QtCore.Signal(object)
102
103 def call_handlers(self, msg):
104 """ Reimplemented to emit signals instead of making callbacks.
105 """
106 # Emit the generic signal.
107 self.message_received.emit(msg)
108 # Emit signals for specialized message types.
109 msg_type = msg['header']['msg_type']
110 signal = getattr(self, msg_type + '_received', None)
111 if signal:
112 signal.emit(msg)
113
114 def flush(self):
115 """ Reimplemented to ensure that signals are dispatched immediately.
116 """
117 super(QtIOPubChannelMixin, self).flush()
118 QtCore.QCoreApplication.instance().processEvents()
119
120
121 class QtStdInChannelMixin(ChannelQObject):
122
123 # Emitted when any message is received.
124 message_received = QtCore.Signal(object)
125
126 # Emitted when an input request is received.
127 input_requested = QtCore.Signal(object)
128
129 def call_handlers(self, msg):
130 """ Reimplemented to emit signals instead of making callbacks.
131 """
132 # Emit the generic signal.
133 self.message_received.emit(msg)
134
135 # Emit signals for specialized message types.
136 msg_type = msg['header']['msg_type']
137 if msg_type == 'input_request':
138 self.input_requested.emit(msg)
139
140
141 class QtHBChannelMixin(ChannelQObject):
55 class QtHBChannelMixin(ChannelQObject):
142
56
143 # Emitted when the kernel has died.
57 # Emitted when the kernel has died.
@@ -171,12 +85,6 b" class QtKernelClientMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObje"
171 # Emitted when the kernel client has stopped listening.
85 # Emitted when the kernel client has stopped listening.
172 stopped_channels = QtCore.Signal()
86 stopped_channels = QtCore.Signal()
173
87
174 # Use Qt-specific channel classes that emit signals.
175 iopub_channel_class = Type(QtIOPubChannelMixin)
176 shell_channel_class = Type(QtShellChannelMixin)
177 stdin_channel_class = Type(QtStdInChannelMixin)
178 hb_channel_class = Type(QtHBChannelMixin)
179
180 #---------------------------------------------------------------------------
88 #---------------------------------------------------------------------------
181 # 'KernelClient' interface
89 # 'KernelClient' interface
182 #---------------------------------------------------------------------------
90 #---------------------------------------------------------------------------
General Comments 0
You need to be logged in to leave comments. Login now