##// END OF EJS Templates
Remove some big unhelpful comment blocks
Thomas Kluyver -
Show More
@@ -1,217 +1,196 b''
1 1 """Defines a KernelManager that provides signals and slots."""
2 2
3 3 # Copyright (c) IPython Development Team.
4 4 # Distributed under the terms of the Modified BSD License.
5 5
6 6 from IPython.external.qt import QtCore
7 7
8 8 from IPython.utils.traitlets import HasTraits, Type
9 9 from .util import MetaQObjectHasTraits, SuperQObject
10 10
11 11
12 12 class ChannelQObject(SuperQObject):
13 13
14 14 # Emitted when the channel is started.
15 15 started = QtCore.Signal()
16 16
17 17 # Emitted when the channel is stopped.
18 18 stopped = QtCore.Signal()
19 19
20 #---------------------------------------------------------------------------
21 # Channel interface
22 #---------------------------------------------------------------------------
23
24 20 def start(self):
25 21 """ Reimplemented to emit signal.
26 22 """
27 23 super(ChannelQObject, self).start()
28 24 self.started.emit()
29 25
30 26 def stop(self):
31 27 """ Reimplemented to emit signal.
32 28 """
33 29 super(ChannelQObject, self).stop()
34 30 self.stopped.emit()
35 31
36 32 #---------------------------------------------------------------------------
37 33 # InProcessChannel interface
38 34 #---------------------------------------------------------------------------
39 35
40 36 def call_handlers_later(self, *args, **kwds):
41 37 """ Call the message handlers later.
42 38 """
43 39 do_later = lambda: self.call_handlers(*args, **kwds)
44 40 QtCore.QTimer.singleShot(0, do_later)
45 41
46 42 def process_events(self):
47 43 """ Process any pending GUI events.
48 44 """
49 45 QtCore.QCoreApplication.instance().processEvents()
50 46
51 47
52 48 class QtShellChannelMixin(ChannelQObject):
53 49
54 50 # Emitted when any message is received.
55 51 message_received = QtCore.Signal(object)
56 52
57 53 # Emitted when a reply has been received for the corresponding request type.
58 54 execute_reply = QtCore.Signal(object)
59 55 complete_reply = QtCore.Signal(object)
60 56 inspect_reply = QtCore.Signal(object)
61 57 history_reply = QtCore.Signal(object)
62 58 kernel_info_reply = QtCore.Signal(object)
63 59
64 #---------------------------------------------------------------------------
65 # 'ShellChannel' interface
66 #---------------------------------------------------------------------------
67
68 60 def call_handlers(self, msg):
69 61 """ Reimplemented to emit signals instead of making callbacks.
70 62 """
71 63 # Emit the generic signal.
72 64 self.message_received.emit(msg)
73 65
74 66 # Emit signals for specialized message types.
75 67 msg_type = msg['header']['msg_type']
76 68 if msg_type == 'kernel_info_reply':
77 69 self._handle_kernel_info_reply(msg)
78 70
79 71 signal = getattr(self, msg_type, None)
80 72 if signal:
81 73 signal.emit(msg)
82 74
83 75
84 76 class QtIOPubChannelMixin(ChannelQObject):
85 77
86 78 # Emitted when any message is received.
87 79 message_received = QtCore.Signal(object)
88 80
89 81 # Emitted when a message of type 'stream' is received.
90 82 stream_received = QtCore.Signal(object)
91 83
92 84 # Emitted when a message of type 'execute_input' is received.
93 85 execute_input_received = QtCore.Signal(object)
94 86
95 87 # Emitted when a message of type 'execute_result' is received.
96 88 execute_result_received = QtCore.Signal(object)
97 89
98 90 # Emitted when a message of type 'error' is received.
99 91 error_received = QtCore.Signal(object)
100 92
101 93 # Emitted when a message of type 'display_data' is received
102 94 display_data_received = QtCore.Signal(object)
103 95
104 96 # Emitted when a crash report message is received from the kernel's
105 97 # last-resort sys.excepthook.
106 98 crash_received = QtCore.Signal(object)
107 99
108 100 # Emitted when a shutdown is noticed.
109 101 shutdown_reply_received = QtCore.Signal(object)
110 102
111 #---------------------------------------------------------------------------
112 # 'IOPubChannel' interface
113 #---------------------------------------------------------------------------
114
115 103 def call_handlers(self, msg):
116 104 """ Reimplemented to emit signals instead of making callbacks.
117 105 """
118 106 # Emit the generic signal.
119 107 self.message_received.emit(msg)
120 108 # Emit signals for specialized message types.
121 109 msg_type = msg['header']['msg_type']
122 110 signal = getattr(self, msg_type + '_received', None)
123 111 if signal:
124 112 signal.emit(msg)
125 113
126 114 def flush(self):
127 115 """ Reimplemented to ensure that signals are dispatched immediately.
128 116 """
129 117 super(QtIOPubChannelMixin, self).flush()
130 118 QtCore.QCoreApplication.instance().processEvents()
131 119
132 120
133 121 class QtStdInChannelMixin(ChannelQObject):
134 122
135 123 # Emitted when any message is received.
136 124 message_received = QtCore.Signal(object)
137 125
138 126 # Emitted when an input request is received.
139 127 input_requested = QtCore.Signal(object)
140 128
141 #---------------------------------------------------------------------------
142 # 'StdInChannel' interface
143 #---------------------------------------------------------------------------
144
145 129 def call_handlers(self, msg):
146 130 """ Reimplemented to emit signals instead of making callbacks.
147 131 """
148 132 # Emit the generic signal.
149 133 self.message_received.emit(msg)
150 134
151 135 # Emit signals for specialized message types.
152 136 msg_type = msg['header']['msg_type']
153 137 if msg_type == 'input_request':
154 138 self.input_requested.emit(msg)
155 139
156 140
157 141 class QtHBChannelMixin(ChannelQObject):
158 142
159 143 # Emitted when the kernel has died.
160 144 kernel_died = QtCore.Signal(object)
161 145
162 #---------------------------------------------------------------------------
163 # 'HBChannel' interface
164 #---------------------------------------------------------------------------
165
166 146 def call_handlers(self, since_last_heartbeat):
167 147 """ Reimplemented to emit signals instead of making callbacks.
168 148 """
169 # Emit the generic signal.
170 149 self.kernel_died.emit(since_last_heartbeat)
171 150
172 151
173 152 class QtKernelRestarterMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})):
174 153
175 154 _timer = None
176 155
177 156
178 157 class QtKernelManagerMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})):
179 158 """ A KernelClient that provides signals and slots.
180 159 """
181 160
182 161 kernel_restarted = QtCore.Signal()
183 162
184 163
185 164 class QtKernelClientMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})):
186 165 """ A KernelClient that provides signals and slots.
187 166 """
188 167
189 168 # Emitted when the kernel client has started listening.
190 169 started_channels = QtCore.Signal()
191 170
192 171 # Emitted when the kernel client has stopped listening.
193 172 stopped_channels = QtCore.Signal()
194 173
195 174 # Use Qt-specific channel classes that emit signals.
196 175 iopub_channel_class = Type(QtIOPubChannelMixin)
197 176 shell_channel_class = Type(QtShellChannelMixin)
198 177 stdin_channel_class = Type(QtStdInChannelMixin)
199 178 hb_channel_class = Type(QtHBChannelMixin)
200 179
201 180 #---------------------------------------------------------------------------
202 181 # 'KernelClient' interface
203 182 #---------------------------------------------------------------------------
204 183
205 184 #------ Channel management -------------------------------------------------
206 185
207 186 def start_channels(self, *args, **kw):
208 187 """ Reimplemented to emit signal.
209 188 """
210 189 super(QtKernelClientMixin, self).start_channels(*args, **kw)
211 190 self.started_channels.emit()
212 191
213 192 def stop_channels(self):
214 193 """ Reimplemented to emit signal.
215 194 """
216 195 super(QtKernelClientMixin, self).stop_channels()
217 196 self.stopped_channels.emit()
General Comments 0
You need to be logged in to leave comments. Login now