Show More
@@ -316,11 +316,25 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||
|
316 | 316 | def _silent_exec_callback(self, expr, callback): |
|
317 | 317 | """Silently execute `expr` in the kernel and call `callback` with reply |
|
318 | 318 | |
|
319 | `expr` : valid string to be executed by the kernel. | |
|
320 | `callback` : function accepting one string as argument. | |
|
319 | the `expr` is evaluated silently in the kernel (without) output in | |
|
320 | the frontend. Call `callback` with the | |
|
321 | `repr <http://docs.python.org/library/functions.html#repr> `_ as first argument | |
|
322 | ||
|
323 | Parameters | |
|
324 | ---------- | |
|
325 | expr : string | |
|
326 | valid string to be executed by the kernel. | |
|
327 | callback : function | |
|
328 | function accepting one arguement, as a string. The string will be | |
|
329 | the `repr` of the result of evaluating `expr` | |
|
321 | 330 | |
|
322 | 331 | The `callback` is called with the 'repr()' of the result of `expr` as |
|
323 |
first argument. To get the object, do 'eval()' on |
|
|
332 | first argument. To get the object, do 'eval()' onthe passed value. | |
|
333 | ||
|
334 | See Also | |
|
335 | -------- | |
|
336 | _handle_exec_callback : private method, deal with calling callback with reply | |
|
337 | ||
|
324 | 338 | """ |
|
325 | 339 | |
|
326 | 340 | # generate uuid, which would be used as a indication of wether or not |
@@ -334,23 +348,26 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||
|
334 | 348 | def _handle_exec_callback(self, msg): |
|
335 | 349 | """Execute `callback` corresonding to `msg` reply, after ``_silent_exec_callback`` |
|
336 | 350 | |
|
337 | `msg` : raw message send by the kernel containing an `user_expressions` | |
|
351 | Parameters | |
|
352 | ---------- | |
|
353 | msg : raw message send by the kernel containing an `user_expressions` | |
|
338 | 354 | and having a 'silent_exec_callback' kind. |
|
339 | 355 | |
|
356 | Notes | |
|
357 | ----- | |
|
340 | 358 | This fonction will look for a `callback` associated with the |
|
341 | 359 | corresponding message id. Association has been made by |
|
342 |
` |
|
|
360 | `_silent_exec_callback`. `callback` is then called with the `repr()` | |
|
343 | 361 | of the value of corresponding `user_expressions` as argument. |
|
344 | 362 | `callback` is then removed from the known list so that any message |
|
345 | 363 | coming again with the same id won't trigger it. |
|
364 | ||
|
346 | 365 | """ |
|
347 | 366 | |
|
348 |
|
|
|
349 | ue = cnt['user_expressions'] | |
|
350 | for i in ue.keys(): | |
|
351 |
|
|
|
352 | self._callback_dict[i](ue[i]) | |
|
353 | self._callback_dict.pop(i) | |
|
367 | user_exp = msg['content']['user_expressions'] | |
|
368 | for expression in user_exp: | |
|
369 | if expression in self._callback_dict: | |
|
370 | self._callback_dict.pop(expression)(user_exp[expression]) | |
|
354 | 371 | |
|
355 | 372 | def _handle_execute_reply(self, msg): |
|
356 | 373 | """ Handles replies for code execution. |
@@ -20,6 +20,7 b' Authors:' | |||
|
20 | 20 | |
|
21 | 21 | # stdlib imports |
|
22 | 22 | import sys |
|
23 | import re | |
|
23 | 24 | import webbrowser |
|
24 | 25 | from threading import Thread |
|
25 | 26 | |
@@ -547,10 +548,23 b' class MainWindow(QtGui.QMainWindow):' | |||
|
547 | 548 | def _make_dynamic_magic(self,magic): |
|
548 | 549 | """Return a function `fun` that will execute `magic` on active frontend. |
|
549 | 550 | |
|
550 | `magic` : valid python string | |
|
551 | Parameters | |
|
552 | ---------- | |
|
553 | magic : string | |
|
554 | string that will be executed as is when the returned function is called | |
|
555 | ||
|
556 | Returns | |
|
557 | ------- | |
|
558 | fun : function | |
|
559 | function with no parameters, when called will execute `magic` on the | |
|
560 | current active frontend at call time | |
|
551 | 561 | |
|
552 | return `fun`, function with no parameters | |
|
562 | See Also | |
|
563 | -------- | |
|
564 | populate_all_magic_menu : generate the "All Magics..." menu | |
|
553 | 565 | |
|
566 | Notes | |
|
567 | ----- | |
|
554 | 568 | `fun` execute `magic` an active frontend at the moment it is triggerd, |
|
555 | 569 | not the active frontend at the moment it has been created. |
|
556 | 570 | |
@@ -566,8 +580,13 b' class MainWindow(QtGui.QMainWindow):' | |||
|
566 | 580 | def populate_all_magic_menu(self, listofmagic=None): |
|
567 | 581 | """Clean "All Magics..." menu and repopulate it with `listofmagic` |
|
568 | 582 | |
|
569 | `listofmagic` : string, repr() of a list of strings. | |
|
583 | Parameters | |
|
584 | ---------- | |
|
585 | listofmagic : string, | |
|
586 | repr() of a list of strings, send back by the kernel | |
|
570 | 587 | |
|
588 | Notes | |
|
589 | ----- | |
|
571 | 590 | `listofmagic`is a repr() of list because it is fed with the result of |
|
572 | 591 | a 'user_expression' |
|
573 | 592 | """ |
@@ -577,8 +596,8 b' class MainWindow(QtGui.QMainWindow):' | |||
|
577 | 596 | # list of protected magic that don't like to be called without argument |
|
578 | 597 | # append '?' to the end to print the docstring when called from the menu |
|
579 | 598 | protected_magic = set(["more","less","load_ext","pycat","loadpy","save"]) |
|
580 | ||
|
581 |
for magic in |
|
|
599 | magics=re.findall('\w+', listofmagic) | |
|
600 | for magic in magics: | |
|
582 | 601 | if magic in protected_magic: |
|
583 | 602 | pmagic = '%s%s%s'%('%',magic,'?') |
|
584 | 603 | else: |
@@ -590,8 +609,14 b' class MainWindow(QtGui.QMainWindow):' | |||
|
590 | 609 | alm_magic_menu.addAction(xaction) |
|
591 | 610 | |
|
592 | 611 | def update_all_magic_menu(self): |
|
612 | """ Update the list on magic in the "All Magics..." Menu | |
|
613 | ||
|
614 | Request the kernel with the list of availlable magic and populate the | |
|
615 | menu with the list received back | |
|
616 | ||
|
617 | """ | |
|
593 | 618 | # first define a callback which will get the list of all magic and put it in the menu. |
|
594 | self.active_frontend._silent_exec_callback('get_ipython().lsmagic()',self.populate_all_magic_menu) | |
|
619 | self.active_frontend._silent_exec_callback('get_ipython().lsmagic()', self.populate_all_magic_menu) | |
|
595 | 620 | |
|
596 | 621 | def init_magic_menu(self): |
|
597 | 622 | self.magic_menu = self.menuBar().addMenu("&Magic") |
@@ -638,7 +663,7 b' class MainWindow(QtGui.QMainWindow):' | |||
|
638 | 663 | statusTip="List interactive variable with detail", |
|
639 | 664 | triggered=self.whos_magic_active_frontend) |
|
640 | 665 | self.add_menu_action(self.magic_menu, self.whos_action) |
|
641 | ||
|
666 | ||
|
642 | 667 | def init_window_menu(self): |
|
643 | 668 | self.window_menu = self.menuBar().addMenu("&Window") |
|
644 | 669 | if sys.platform == 'darwin': |
General Comments 0
You need to be logged in to leave comments.
Login now