##// END OF EJS Templates
Merge pull request #1782 from Carreau/magiclistinfo...
Bussonnier Matthias -
r7316:8b00a30d merge
parent child Browse files
Show More
@@ -321,6 +321,16 b' class MagicsManager(Configurable):'
321 def auto_status(self):
321 def auto_status(self):
322 """Return descriptive string with automagic status."""
322 """Return descriptive string with automagic status."""
323 return self._auto_status[self.auto_magic]
323 return self._auto_status[self.auto_magic]
324
325 def lsmagic_info(self):
326 magic_list = []
327 for m_type in self.magics :
328 for m_name,mgc in self.magics[m_type].items():
329 try :
330 magic_list.append({'name':m_name,'type':m_type,'class':mgc.im_class.__name__})
331 except AttributeError :
332 magic_list.append({'name':m_name,'type':m_type,'class':'Other'})
333 return magic_list
324
334
325 def lsmagic(self):
335 def lsmagic(self):
326 """Return a dict of currently available magic functions.
336 """Return a dict of currently available magic functions.
@@ -22,6 +22,7 b' Authors:'
22 import sys
22 import sys
23 import re
23 import re
24 import webbrowser
24 import webbrowser
25 import ast
25 from threading import Thread
26 from threading import Thread
26
27
27 # System library imports
28 # System library imports
@@ -43,6 +44,8 b' class MainWindow(QtGui.QMainWindow):'
43 # 'object' interface
44 # 'object' interface
44 #---------------------------------------------------------------------------
45 #---------------------------------------------------------------------------
45
46
47 _magic_menu_dict = {}
48
46 def __init__(self, app,
49 def __init__(self, app,
47 confirm_exit=True,
50 confirm_exit=True,
48 new_frontend_factory=None, slave_frontend_factory=None,
51 new_frontend_factory=None, slave_frontend_factory=None,
@@ -592,23 +595,35 b' class MainWindow(QtGui.QMainWindow):'
592 `listofmagic`is a repr() of list because it is fed with the result of
595 `listofmagic`is a repr() of list because it is fed with the result of
593 a 'user_expression'
596 a 'user_expression'
594 """
597 """
595 alm_magic_menu = self.all_magic_menu
598 for k,v in self._magic_menu_dict.items():
596 alm_magic_menu.clear()
599 v.clear()
597
600 self.all_magic_menu.clear()
598 # list of protected magic that don't like to be called without argument
601
599 # append '?' to the end to print the docstring when called from the menu
602
600 protected_magic = set(["more","less","load_ext","pycat","loadpy","load","save"])
603 protected_magic = set(["more","less","load_ext","pycat","loadpy","load","save","psource"])
601 magics=re.findall('\w+', listofmagic)
604 mlist=ast.literal_eval(listofmagic)
602 for magic in magics:
605 for magic in mlist:
603 if magic in protected_magic:
606 cell = (magic['type'] == 'cell')
604 pmagic = '%s%s%s'%('%',magic,'?')
607 name = magic['name']
605 else:
608 mclass = magic['class']
606 pmagic = '%s%s'%('%',magic)
609 if cell :
610 prefix='%%'
611 else :
612 prefix='%'
613 magic_menu = self._get_magic_menu(mclass)
614
615 if name in protected_magic:
616 suffix = '?'
617 else :
618 suffix = ''
619 pmagic = '%s%s%s'%(prefix,name,suffix)
620
607 xaction = QtGui.QAction(pmagic,
621 xaction = QtGui.QAction(pmagic,
608 self,
622 self,
609 triggered=self._make_dynamic_magic(pmagic)
623 triggered=self._make_dynamic_magic(pmagic)
610 )
624 )
611 alm_magic_menu.addAction(xaction)
625 magic_menu.addAction(xaction)
626 self.all_magic_menu.addAction(xaction)
612
627
613 def update_all_magic_menu(self):
628 def update_all_magic_menu(self):
614 """ Update the list on magic in the "All Magics..." Menu
629 """ Update the list on magic in the "All Magics..." Menu
@@ -617,12 +632,37 b' class MainWindow(QtGui.QMainWindow):'
617 menu with the list received back
632 menu with the list received back
618
633
619 """
634 """
620 # first define a callback which will get the list of all magic and put it in the menu.
635 self.active_frontend._silent_exec_callback('get_ipython().magics_manager.lsmagic_info()',
621 self.active_frontend._silent_exec_callback('get_ipython().lsmagic()', self.populate_all_magic_menu)
636 self.populate_all_magic_menu)
637
638 def _get_magic_menu(self,menuidentifier, menulabel=None):
639 """return a submagic menu by name, and create it if needed
640
641 parameters:
642 -----------
643
644 menulabel : str
645 Label for the menu
646
647 Will infere the menu name from the identifier at creation if menulabel not given.
648 To do so you have too give menuidentifier as a CamelCassedString
649 """
650 menu = self._magic_menu_dict.get(menuidentifier,None)
651 if not menu :
652 if not menulabel:
653 menulabel = re.sub("([a-zA-Z]+)([A-Z][a-z])","\g<1> \g<2>",menuidentifier)
654 menu = QtGui.QMenu(menulabel,self.magic_menu)
655 self._magic_menu_dict[menuidentifier]=menu
656 self.magic_menu.insertMenu(self.magic_menu_separator,menu)
657 return menu
658
622
659
660
623 def init_magic_menu(self):
661 def init_magic_menu(self):
624 self.magic_menu = self.menuBar().addMenu("&Magic")
662 self.magic_menu = self.menuBar().addMenu("&Magic")
625 self.all_magic_menu = self.magic_menu.addMenu("&All Magics")
663 self.magic_menu_separator = self.magic_menu.addSeparator()
664
665 self.all_magic_menu = self._get_magic_menu("AllMagics", menulabel="&All Magics...")
626
666
627 # This action should usually not appear as it will be cleared when menu
667 # This action should usually not appear as it will be cleared when menu
628 # is updated at first kernel response. Though, it is necessary when
668 # is updated at first kernel response. Though, it is necessary when
General Comments 0
You need to be logged in to leave comments. Login now