Show More
@@ -4,6 +4,7 b' from __future__ import print_function' | |||
|
4 | 4 | from collections import namedtuple |
|
5 | 5 | import sys |
|
6 | 6 | import time |
|
7 | import uuid | |
|
7 | 8 | |
|
8 | 9 | # System library imports |
|
9 | 10 | from pygments.lexers import PythonLexer |
@@ -137,6 +138,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||
|
137 | 138 | self._input_splitter = self._input_splitter_class(input_mode='cell') |
|
138 | 139 | self._kernel_manager = None |
|
139 | 140 | self._request_info = {} |
|
141 | self._callback_dict=dict([]) | |
|
140 | 142 | |
|
141 | 143 | # Configure the ConsoleWidget. |
|
142 | 144 | self.tab_width = 4 |
@@ -311,6 +313,42 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||
|
311 | 313 | cursor.movePosition(QtGui.QTextCursor.Left, n=len(text)) |
|
312 | 314 | self._complete_with_items(cursor, rep['content']['matches']) |
|
313 | 315 | |
|
316 | def _silent_exec_callback(self,expr,callback): | |
|
317 | """ silently execute a function in the kernel and send the reply to the callback | |
|
318 | ||
|
319 | expr should be a valid string to be executed by the kernel. | |
|
320 | ||
|
321 | callback a function accepting one argument (str) | |
|
322 | ||
|
323 | the callback is called with the 'repr()' of the result as first argument. | |
|
324 | to get the object, do 'eval()' on the passed value. | |
|
325 | """ | |
|
326 | ||
|
327 | # generate uuid, which would be used as a indication of wether or not | |
|
328 | # the unique request originate from here (can use msg id ?) | |
|
329 | local_uuid = str(uuid.uuid1()) | |
|
330 | msg_id = self.kernel_manager.shell_channel.execute('', | |
|
331 | silent=True, | |
|
332 | user_expressions={ local_uuid:expr, | |
|
333 | } | |
|
334 | ) | |
|
335 | self._callback_dict[local_uuid]=callback | |
|
336 | self._request_info['execute'] = self._ExecutionRequest(msg_id, 'silent_exec_callback') | |
|
337 | ||
|
338 | def _handle_exec_callback(self,msg): | |
|
339 | """ Called when _silent_exec_callback message comme back from the kernel. | |
|
340 | ||
|
341 | Strip the message comming back from the kernel and send it to the | |
|
342 | corresponding callback function. | |
|
343 | """ | |
|
344 | cnt=msg['content'] | |
|
345 | ue=cnt['user_expressions'] | |
|
346 | for i in ue.keys(): | |
|
347 | if i in self._callback_dict.keys(): | |
|
348 | f= self._callback_dict[i] | |
|
349 | f(ue[i]) | |
|
350 | self._callback_dict.pop(i) | |
|
351 | ||
|
314 | 352 | def _handle_execute_reply(self, msg): |
|
315 | 353 | """ Handles replies for code execution. |
|
316 | 354 | """ |
@@ -342,6 +380,9 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||
|
342 | 380 | |
|
343 | 381 | self._show_interpreter_prompt_for_reply(msg) |
|
344 | 382 | self.executed.emit(msg) |
|
383 | elif info and info.id == msg['parent_header']['msg_id'] and \ | |
|
384 | info.kind == 'silent_exec_callback' and not self._hidden: | |
|
385 | self._handle_exec_callback(msg) | |
|
345 | 386 | else: |
|
346 | 387 | super(FrontendWidget, self)._handle_execute_reply(msg) |
|
347 | 388 |
@@ -544,10 +544,35 b' class MainWindow(QtGui.QMainWindow):' | |||
|
544 | 544 | |
|
545 | 545 | self.kernel_menu.addSeparator() |
|
546 | 546 | |
|
547 | def update_all_magic_menu(self): | |
|
548 | # first define a callback which will get the list of all magic and put it in the menu. | |
|
549 | def populate_all_magic_menu(val=None): | |
|
550 | alm_magic_menu = self.magic_menu.addMenu("&All Magics...") | |
|
551 | def make_dynamic_magic(i): | |
|
552 | def inner_dynamic_magic(): | |
|
553 | self.active_frontend.execute(i) | |
|
554 | inner_dynamic_magic.__name__ = "dynamics_magic_s" | |
|
555 | return inner_dynamic_magic | |
|
556 | ||
|
557 | for magic in eval(val): | |
|
558 | pmagic = '%s%s'%('%',magic) | |
|
559 | xaction = QtGui.QAction(pmagic, | |
|
560 | self, | |
|
561 | triggered=make_dynamic_magic(pmagic) | |
|
562 | ) | |
|
563 | alm_magic_menu.addAction(xaction) | |
|
564 | self.active_frontend._silent_exec_callback('get_ipython().lsmagic()',populate_all_magic_menu) | |
|
565 | ||
|
547 | 566 | def init_magic_menu(self): |
|
548 | 567 | self.magic_menu = self.menuBar().addMenu("&Magic") |
|
549 | 568 | self.all_magic_menu = self.magic_menu.addMenu("&All Magics") |
|
550 | 569 | |
|
570 | self.pop = QtGui.QAction("&Populate All Magic Menu", | |
|
571 | self, | |
|
572 | statusTip="Clear all varible from workspace", | |
|
573 | triggered=self.update_all_magic_menu) | |
|
574 | self.add_menu_action(self.magic_menu, self.pop) | |
|
575 | ||
|
551 | 576 | self.reset_action = QtGui.QAction("&Reset", |
|
552 | 577 | self, |
|
553 | 578 | statusTip="Clear all varible from workspace", |
General Comments 0
You need to be logged in to leave comments.
Login now