Show More
@@ -1,4 +1,5 | |||
|
1 | 1 | # Standard library imports |
|
2 | from collections import namedtuple | |
|
2 | 3 | import signal |
|
3 | 4 | import sys |
|
4 | 5 | |
@@ -90,6 +91,9 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
90 | 91 | executed = QtCore.pyqtSignal(object) |
|
91 | 92 | |
|
92 | 93 | # Protected class variables. |
|
94 | _CallTipRequest = namedtuple('_CallTipRequest', ['id', 'pos']) | |
|
95 | _CompletionRequest = namedtuple('_CompletionRequest', ['id', 'pos']) | |
|
96 | _ExecutionRequest = namedtuple('_ExecutionRequest', ['id', 'kind']) | |
|
93 | 97 | _input_splitter_class = InputSplitter |
|
94 | 98 | |
|
95 | 99 | #--------------------------------------------------------------------------- |
@@ -108,6 +112,7 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
108 | 112 | self._input_splitter = self._input_splitter_class(input_mode='block') |
|
109 | 113 | self._kernel_manager = None |
|
110 | 114 | self._possible_kernel_restart = False |
|
115 | self._request_info = {} | |
|
111 | 116 | |
|
112 | 117 | # Configure the ConsoleWidget. |
|
113 | 118 | self.tab_width = 4 |
@@ -149,9 +154,10 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
149 | 154 | # /end tmp code |
|
150 | 155 | |
|
151 | 156 | # FIXME - user_variables/expressions are not visible in API above us. |
|
152 | self.kernel_manager.xreq_channel.execute(source, hidden, | |
|
153 | user_variables, | |
|
154 | user_expressions) | |
|
157 | msg_id = self.kernel_manager.xreq_channel.execute(source, hidden, | |
|
158 | user_variables, | |
|
159 | user_expressions) | |
|
160 | self._request_info['execute'] = self._ExecutionRequest(msg_id, 'user') | |
|
155 | 161 | self._hidden = hidden |
|
156 | 162 | |
|
157 | 163 | def _prompt_started_hook(self): |
@@ -216,8 +222,9 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
216 | 222 | """ Handle replies for tab completion. |
|
217 | 223 | """ |
|
218 | 224 | cursor = self._get_cursor() |
|
219 | if rep['parent_header']['msg_id'] == self._complete_id and \ | |
|
220 | cursor.position() == self._complete_pos: | |
|
225 | info = self._request_info.get('complete') | |
|
226 | if info and info.id == rep['parent_header']['msg_id'] and \ | |
|
227 | info.pos == cursor.position(): | |
|
221 | 228 | text = '.'.join(self._get_context()) |
|
222 | 229 | cursor.movePosition(QtGui.QTextCursor.Left, n=len(text)) |
|
223 | 230 | self._complete_with_items(cursor, rep['content']['matches']) |
@@ -225,7 +232,9 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
225 | 232 | def _handle_execute_reply(self, msg): |
|
226 | 233 | """ Handles replies for code execution. |
|
227 | 234 | """ |
|
228 | if not self._hidden: | |
|
235 | info = self._request_info.get('execute') | |
|
236 | if info and info.id == msg['parent_header']['msg_id'] and \ | |
|
237 | not self._hidden: | |
|
229 | 238 | # Make sure that all output from the SUB channel has been processed |
|
230 | 239 | # before writing a new prompt. |
|
231 | 240 | self.kernel_manager.sub_channel.flush() |
@@ -272,8 +281,9 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
272 | 281 | """ Handle replies for call tips. |
|
273 | 282 | """ |
|
274 | 283 | cursor = self._get_cursor() |
|
275 | if rep['parent_header']['msg_id'] == self._call_tip_id and \ | |
|
276 | cursor.position() == self._call_tip_pos: | |
|
284 | info = self._request_info.get('call_tip') | |
|
285 | if info and info.id == rep['parent_header']['msg_id'] and \ | |
|
286 | info.pos == cursor.position(): | |
|
277 | 287 | doc = rep['content']['docstring'] |
|
278 | 288 | if doc: |
|
279 | 289 | self._call_tip_widget.show_docstring(doc) |
@@ -378,8 +388,9 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
378 | 388 | |
|
379 | 389 | # Send the metadata request to the kernel |
|
380 | 390 | name = '.'.join(context) |
|
381 |
|
|
|
382 |
|
|
|
391 | msg_id = self.kernel_manager.xreq_channel.object_info(name) | |
|
392 | pos = self._get_cursor().position() | |
|
393 | self._request_info['call_tip'] = self._CallTipRequest(msg_id, pos) | |
|
383 | 394 | return True |
|
384 | 395 | |
|
385 | 396 | def _complete(self): |
@@ -388,12 +399,14 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
388 | 399 | context = self._get_context() |
|
389 | 400 | if context: |
|
390 | 401 | # Send the completion request to the kernel |
|
391 |
|
|
|
402 | msg_id = self.kernel_manager.xreq_channel.complete( | |
|
392 | 403 | '.'.join(context), # text |
|
393 | 404 | self._get_input_buffer_cursor_line(), # line |
|
394 | 405 | self._get_input_buffer_cursor_column(), # cursor_pos |
|
395 | 406 | self.input_buffer) # block |
|
396 |
|
|
|
407 | pos = self._get_cursor().position() | |
|
408 | info = self._CompletionRequest(msg_id, pos) | |
|
409 | self._request_info['complete'] = info | |
|
397 | 410 | |
|
398 | 411 | def _get_banner(self): |
|
399 | 412 | """ Gets a banner to display at the beginning of a session. |
@@ -21,7 +21,6 from PyQt4 import QtCore, QtGui | |||
|
21 | 21 | # Local imports |
|
22 | 22 | from IPython.core.inputsplitter import IPythonInputSplitter |
|
23 | 23 | from IPython.core.usage import default_banner |
|
24 | from IPython.utils import io | |
|
25 | 24 | from IPython.utils.traitlets import Bool, Str |
|
26 | 25 | from frontend_widget import FrontendWidget |
|
27 | 26 | |
@@ -134,8 +133,9 class IPythonWidget(FrontendWidget): | |||
|
134 | 133 | """ Reimplemented to support IPython's improved completion machinery. |
|
135 | 134 | """ |
|
136 | 135 | cursor = self._get_cursor() |
|
137 | if rep['parent_header']['msg_id'] == self._complete_id and \ | |
|
138 | cursor.position() == self._complete_pos: | |
|
136 | info = self._request_info.get('complete') | |
|
137 | if info and info.id == rep['parent_header']['msg_id'] and \ | |
|
138 | info.pos == cursor.position(): | |
|
139 | 139 | matches = rep['content']['matches'] |
|
140 | 140 | text = rep['content']['matched_text'] |
|
141 | 141 | |
@@ -151,6 +151,17 class IPythonWidget(FrontendWidget): | |||
|
151 | 151 | cursor.movePosition(QtGui.QTextCursor.Left, n=len(text)) |
|
152 | 152 | self._complete_with_items(cursor, matches) |
|
153 | 153 | |
|
154 | def _handle_execute_reply(self, msg): | |
|
155 | """ Reimplemented to support prompt requests. | |
|
156 | """ | |
|
157 | info = self._request_info.get('execute') | |
|
158 | if info and info.id == msg['parent_header']['msg_id']: | |
|
159 | if info.kind == 'prompt': | |
|
160 | number = msg['content']['execution_count'] + 1 | |
|
161 | self._show_interpreter_prompt(number) | |
|
162 | else: | |
|
163 | super(IPythonWidget, self)._handle_execute_reply(msg) | |
|
164 | ||
|
154 | 165 | def _handle_history_reply(self, msg): |
|
155 | 166 | """ Implemented to handle history replies, which are only supported by |
|
156 | 167 | the IPython kernel. |
@@ -159,12 +170,6 class IPythonWidget(FrontendWidget): | |||
|
159 | 170 | items = [ history_dict[key] for key in sorted(history_dict.keys()) ] |
|
160 | 171 | self._set_history(items) |
|
161 | 172 | |
|
162 | def _handle_prompt_reply(self, msg): | |
|
163 | """ Implemented to handle prompt number replies, which are only | |
|
164 | supported by the IPython kernel. | |
|
165 | """ | |
|
166 | self._show_interpreter_prompt(msg['content']['execution_count']) | |
|
167 | ||
|
168 | 173 | def _handle_pyout(self, msg): |
|
169 | 174 | """ Reimplemented for IPython-style "display hook". |
|
170 | 175 | """ |
@@ -204,12 +209,14 class IPythonWidget(FrontendWidget): | |||
|
204 | 209 | text = '' |
|
205 | 210 | |
|
206 | 211 | # Send the completion request to the kernel |
|
207 |
|
|
|
212 | msg_id = self.kernel_manager.xreq_channel.complete( | |
|
208 | 213 | text, # text |
|
209 | 214 | self._get_input_buffer_cursor_line(), # line |
|
210 | 215 | self._get_input_buffer_cursor_column(), # cursor_pos |
|
211 | 216 | self.input_buffer) # block |
|
212 |
|
|
|
217 | pos = self._get_cursor().position() | |
|
218 | info = self._CompletionRequest(msg_id, pos) | |
|
219 | self._request_info['complete'] = info | |
|
213 | 220 | |
|
214 | 221 | def _get_banner(self): |
|
215 | 222 | """ Reimplemented to return IPython's default banner. |
@@ -254,10 +261,10 class IPythonWidget(FrontendWidget): | |||
|
254 | 261 | """ |
|
255 | 262 | # If a number was not specified, make a prompt number request. |
|
256 | 263 | if number is None: |
|
257 | # FIXME - fperez: this should be a silent code request | |
|
258 | number = 1 | |
|
259 | ##self.kernel_manager.xreq_channel.prompt() | |
|
260 |
|
|
|
264 | msg_id = self.kernel_manager.xreq_channel.execute('', silent=True) | |
|
265 | info = self._ExecutionRequest(msg_id, 'prompt') | |
|
266 | self._request_info['execute'] = info | |
|
267 | return | |
|
261 | 268 | |
|
262 | 269 | # Show a new prompt and save information about it so that it can be |
|
263 | 270 | # updated later if the prompt number turns out to be wrong. |
@@ -276,7 +283,6 class IPythonWidget(FrontendWidget): | |||
|
276 | 283 | """ |
|
277 | 284 | # Update the old prompt number if necessary. |
|
278 | 285 | content = msg['content'] |
|
279 | ##io.rprint('_show_interpreter_prompt_for_reply\n', content) # dbg | |
|
280 | 286 | previous_prompt_number = content['execution_count'] |
|
281 | 287 | if self._previous_prompt_obj and \ |
|
282 | 288 | self._previous_prompt_obj.number != previous_prompt_number: |
@@ -206,7 +206,6 class XReqSocketChannel(ZmqSocketChannel): | |||
|
206 | 206 | If set, the kernel will execute the code as quietly possible. |
|
207 | 207 | |
|
208 | 208 | user_variables : list, optional |
|
209 | ||
|
210 | 209 | A list of variable names to pull from the user's namespace. They |
|
211 | 210 | will come back as a dict with these names as keys and their |
|
212 | 211 | :func:`repr` as values. |
General Comments 0
You need to be logged in to leave comments.
Login now