Show More
@@ -15,6 +15,7 b'' | |||||
15 | # Imports |
|
15 | # Imports | |
16 | #----------------------------------------------------------------------------- |
|
16 | #----------------------------------------------------------------------------- | |
17 | # Stdlib |
|
17 | # Stdlib | |
|
18 | import json | |||
18 | import os |
|
19 | import os | |
19 | import re |
|
20 | import re | |
20 | import sys |
|
21 | import sys | |
@@ -327,14 +328,20 b' class MagicsManager(Configurable):' | |||||
327 | return self._auto_status[self.auto_magic] |
|
328 | return self._auto_status[self.auto_magic] | |
328 |
|
329 | |||
329 | def lsmagic_info(self): |
|
330 | def lsmagic_info(self): | |
|
331 | """Return the magics as a list of dicts""" | |||
330 | magic_list = [] |
|
332 | magic_list = [] | |
331 |
for m_type in self.magics |
|
333 | for m_type in self.magics: | |
332 | for m_name,mgc in self.magics[m_type].items(): |
|
334 | for m_name,mgc in self.magics[m_type].items(): | |
333 |
try |
|
335 | try: | |
334 | magic_list.append({'name':m_name,'type':m_type,'class':mgc.im_class.__name__}) |
|
336 | magic_list.append({'name':m_name,'type':m_type,'class':mgc.im_class.__name__}) | |
335 |
except AttributeError |
|
337 | except AttributeError: | |
336 | magic_list.append({'name':m_name,'type':m_type,'class':'Other'}) |
|
338 | magic_list.append({'name':m_name,'type':m_type,'class':'Other'}) | |
337 | return magic_list |
|
339 | return magic_list | |
|
340 | ||||
|
341 | def lsmagic_json(self): | |||
|
342 | """Wrap lsmagic_info() in a JSON object""" | |||
|
343 | from IPython.display import JSON | |||
|
344 | return JSON(json.dumps(self.lsmagic_info())) | |||
338 |
|
345 | |||
339 | def lsmagic(self): |
|
346 | def lsmagic(self): | |
340 | """Return a dict of currently available magic functions. |
|
347 | """Return a dict of currently available magic functions. |
@@ -241,7 +241,9 b' class HistoryConsoleWidget(ConsoleWidget):' | |||||
241 | content = msg['content'] |
|
241 | content = msg['content'] | |
242 | status = content['status'] |
|
242 | status = content['status'] | |
243 | if status == 'ok': |
|
243 | if status == 'ok': | |
244 |
self._max_session_history= |
|
244 | self._max_session_history = int( | |
|
245 | content['user_expressions']['hlen']['data']['text/plain'] | |||
|
246 | ) | |||
245 |
|
247 | |||
246 | def save_magic(self): |
|
248 | def save_magic(self): | |
247 | # update the session history length |
|
249 | # update the session history length |
@@ -20,10 +20,10 b' Authors:' | |||||
20 | #----------------------------------------------------------------------------- |
|
20 | #----------------------------------------------------------------------------- | |
21 |
|
21 | |||
22 | # stdlib imports |
|
22 | # stdlib imports | |
23 |
import |
|
23 | import json | |
24 | import re |
|
24 | import re | |
|
25 | import sys | |||
25 | import webbrowser |
|
26 | import webbrowser | |
26 | import ast |
|
|||
27 | from threading import Thread |
|
27 | from threading import Thread | |
28 |
|
28 | |||
29 | # System library imports |
|
29 | # System library imports | |
@@ -615,25 +615,25 b' class MainWindow(QtGui.QMainWindow):' | |||||
615 | inner_dynamic_magic.__name__ = "dynamics_magic_s" |
|
615 | inner_dynamic_magic.__name__ = "dynamics_magic_s" | |
616 | return inner_dynamic_magic |
|
616 | return inner_dynamic_magic | |
617 |
|
617 | |||
618 |
def populate_all_magic_menu(self, |
|
618 | def populate_all_magic_menu(self, display_data=None): | |
619 |
"""Clean "All Magics..." menu and repopulate it with ` |
|
619 | """Clean "All Magics..." menu and repopulate it with `display_data` | |
620 |
|
620 | |||
621 | Parameters |
|
621 | Parameters | |
622 | ---------- |
|
622 | ---------- | |
623 | listofmagic : string, |
|
623 | display_data : dict, | |
624 | repr() of a list of strings, send back by the kernel |
|
624 | dict of display_data for the magics list. | |
|
625 | Expects json data, as the result of MagicsManager.lsmagic_json() | |||
625 |
|
626 | |||
626 | Notes |
|
|||
627 | ----- |
|
|||
628 | `listofmagic`is a repr() of list because it is fed with the result of |
|
|||
629 | a 'user_expression' |
|
|||
630 | """ |
|
627 | """ | |
631 | for k,v in self._magic_menu_dict.items(): |
|
628 | for k,v in self._magic_menu_dict.items(): | |
632 | v.clear() |
|
629 | v.clear() | |
633 | self.all_magic_menu.clear() |
|
630 | self.all_magic_menu.clear() | |
|
631 | ||||
|
632 | if not display_data: | |||
|
633 | return | |||
634 |
|
634 | |||
|
635 | mlist = json.loads(display_data['data'].get('application/json', [])) | |||
635 |
|
636 | |||
636 | mlist=ast.literal_eval(listofmagic) |
|
|||
637 | for magic in mlist: |
|
637 | for magic in mlist: | |
638 | cell = (magic['type'] == 'cell') |
|
638 | cell = (magic['type'] == 'cell') | |
639 | name = magic['name'] |
|
639 | name = magic['name'] | |
@@ -660,7 +660,7 b' class MainWindow(QtGui.QMainWindow):' | |||||
660 | menu with the list received back |
|
660 | menu with the list received back | |
661 |
|
661 | |||
662 | """ |
|
662 | """ | |
663 |
self.active_frontend._silent_exec_callback('get_ipython().magics_manager.lsmagic_ |
|
663 | self.active_frontend._silent_exec_callback('get_ipython().magics_manager.lsmagic_json()', | |
664 | self.populate_all_magic_menu) |
|
664 | self.populate_all_magic_menu) | |
665 |
|
665 | |||
666 | def _get_magic_menu(self,menuidentifier, menulabel=None): |
|
666 | def _get_magic_menu(self,menuidentifier, menulabel=None): |
General Comments 0
You need to be logged in to leave comments.
Login now