Show More
@@ -316,11 +316,25 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
316 | def _silent_exec_callback(self, expr, callback): |
|
316 | def _silent_exec_callback(self, expr, callback): | |
317 | """Silently execute `expr` in the kernel and call `callback` with reply |
|
317 | """Silently execute `expr` in the kernel and call `callback` with reply | |
318 |
|
318 | |||
319 | `expr` : valid string to be executed by the kernel. |
|
319 | the `expr` is evaluated silently in the kernel (without) output in | |
320 | `callback` : function accepting one string as argument. |
|
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 | The `callback` is called with the 'repr()' of the result of `expr` as |
|
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 | # generate uuid, which would be used as a indication of wether or not |
|
340 | # generate uuid, which would be used as a indication of wether or not | |
@@ -334,23 +348,26 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
334 | def _handle_exec_callback(self, msg): |
|
348 | def _handle_exec_callback(self, msg): | |
335 | """Execute `callback` corresonding to `msg` reply, after ``_silent_exec_callback`` |
|
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 | and having a 'silent_exec_callback' kind. |
|
354 | and having a 'silent_exec_callback' kind. | |
339 |
|
355 | |||
|
356 | Notes | |||
|
357 | ----- | |||
340 | This fonction will look for a `callback` associated with the |
|
358 | This fonction will look for a `callback` associated with the | |
341 | corresponding message id. Association has been made by |
|
359 | corresponding message id. Association has been made by | |
342 |
` |
|
360 | `_silent_exec_callback`. `callback` is then called with the `repr()` | |
343 | of the value of corresponding `user_expressions` as argument. |
|
361 | of the value of corresponding `user_expressions` as argument. | |
344 | `callback` is then removed from the known list so that any message |
|
362 | `callback` is then removed from the known list so that any message | |
345 | coming again with the same id won't trigger it. |
|
363 | coming again with the same id won't trigger it. | |
|
364 | ||||
346 | """ |
|
365 | """ | |
347 |
|
366 | |||
348 |
|
|
367 | user_exp = msg['content']['user_expressions'] | |
349 | ue = cnt['user_expressions'] |
|
368 | for expression in user_exp: | |
350 | for i in ue.keys(): |
|
369 | if expression in self._callback_dict: | |
351 |
|
|
370 | self._callback_dict.pop(expression)(user_exp[expression]) | |
352 | self._callback_dict[i](ue[i]) |
|
|||
353 | self._callback_dict.pop(i) |
|
|||
354 |
|
371 | |||
355 | def _handle_execute_reply(self, msg): |
|
372 | def _handle_execute_reply(self, msg): | |
356 | """ Handles replies for code execution. |
|
373 | """ Handles replies for code execution. |
@@ -20,6 +20,7 b' Authors:' | |||||
20 |
|
20 | |||
21 | # stdlib imports |
|
21 | # stdlib imports | |
22 | import sys |
|
22 | import sys | |
|
23 | import re | |||
23 | import webbrowser |
|
24 | import webbrowser | |
24 | from threading import Thread |
|
25 | from threading import Thread | |
25 |
|
26 | |||
@@ -547,10 +548,23 b' class MainWindow(QtGui.QMainWindow):' | |||||
547 | def _make_dynamic_magic(self,magic): |
|
548 | def _make_dynamic_magic(self,magic): | |
548 | """Return a function `fun` that will execute `magic` on active frontend. |
|
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 | `fun` execute `magic` an active frontend at the moment it is triggerd, |
|
568 | `fun` execute `magic` an active frontend at the moment it is triggerd, | |
555 | not the active frontend at the moment it has been created. |
|
569 | not the active frontend at the moment it has been created. | |
556 |
|
570 | |||
@@ -566,8 +580,13 b' class MainWindow(QtGui.QMainWindow):' | |||||
566 | def populate_all_magic_menu(self, listofmagic=None): |
|
580 | def populate_all_magic_menu(self, listofmagic=None): | |
567 | """Clean "All Magics..." menu and repopulate it with `listofmagic` |
|
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 | `listofmagic`is a repr() of list because it is fed with the result of |
|
590 | `listofmagic`is a repr() of list because it is fed with the result of | |
572 | a 'user_expression' |
|
591 | a 'user_expression' | |
573 | """ |
|
592 | """ | |
@@ -577,8 +596,8 b' class MainWindow(QtGui.QMainWindow):' | |||||
577 | # list of protected magic that don't like to be called without argument |
|
596 | # list of protected magic that don't like to be called without argument | |
578 | # append '?' to the end to print the docstring when called from the menu |
|
597 | # append '?' to the end to print the docstring when called from the menu | |
579 | protected_magic = set(["more","less","load_ext","pycat","loadpy","save"]) |
|
598 | protected_magic = set(["more","less","load_ext","pycat","loadpy","save"]) | |
580 |
|
599 | magics=re.findall('\w+', listofmagic) | ||
581 |
for magic in |
|
600 | for magic in magics: | |
582 | if magic in protected_magic: |
|
601 | if magic in protected_magic: | |
583 | pmagic = '%s%s%s'%('%',magic,'?') |
|
602 | pmagic = '%s%s%s'%('%',magic,'?') | |
584 | else: |
|
603 | else: | |
@@ -590,6 +609,12 b' class MainWindow(QtGui.QMainWindow):' | |||||
590 | alm_magic_menu.addAction(xaction) |
|
609 | alm_magic_menu.addAction(xaction) | |
591 |
|
610 | |||
592 | def update_all_magic_menu(self): |
|
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 | # first define a callback which will get the list of all magic and put it in the menu. |
|
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 |
General Comments 0
You need to be logged in to leave comments.
Login now