##// END OF EJS Templates
Remove "all magics" menu stuff.
Dimitry Kloper -
Show More
@@ -47,8 +47,6 b' class MainWindow(QtGui.QMainWindow):'
47 # 'object' interface
47 # 'object' interface
48 #---------------------------------------------------------------------------
48 #---------------------------------------------------------------------------
49
49
50 _magic_menu_dict = {}
51
52 def __init__(self, app,
50 def __init__(self, app,
53 confirm_exit=True,
51 confirm_exit=True,
54 new_frontend_factory=None, slave_frontend_factory=None,
52 new_frontend_factory=None, slave_frontend_factory=None,
@@ -584,128 +582,15 b' class MainWindow(QtGui.QMainWindow):'
584
582
585 self.add_menu_action(self.kernel_menu, self.confirm_restart_kernel_action)
583 self.add_menu_action(self.kernel_menu, self.confirm_restart_kernel_action)
586 self.tab_widget.currentChanged.connect(self.update_restart_checkbox)
584 self.tab_widget.currentChanged.connect(self.update_restart_checkbox)
587
588 def _make_dynamic_magic(self,magic):
589 """Return a function `fun` that will execute `magic` on active frontend.
590
591 Parameters
592 ----------
593 magic : string
594 string that will be executed as is when the returned function is called
595
596 Returns
597 -------
598 fun : function
599 function with no parameters, when called will execute `magic` on the
600 current active frontend at call time
601
602 See Also
603 --------
604 populate_all_magic_menu : generate the "All Magics..." menu
605
606 Notes
607 -----
608 `fun` executes `magic` in active frontend at the moment it is triggered,
609 not the active frontend at the moment it was created.
610
611 This function is mostly used to create the "All Magics..." Menu at run time.
612 """
613 # need two level nested function to be sure to pass magic
614 # to active frontend **at run time**.
615 def inner_dynamic_magic():
616 self.active_frontend.execute(magic)
617 inner_dynamic_magic.__name__ = "dynamics_magic_s"
618 return inner_dynamic_magic
619
620 def populate_all_magic_menu(self, display_data=None):
621 """Clean "All Magics..." menu and repopulate it with `display_data`
622
623 Parameters
624 ----------
625 display_data : dict,
626 dict of display_data for the magics dict of a MagicsManager.
627 Expects json data, as the result of %lsmagic
628
629 """
630 for k,v in self._magic_menu_dict.items():
631 v.clear()
632 self.all_magic_menu.clear()
633
634 if not display_data:
635 return
636
637 if display_data['status'] != 'ok':
638 self.log.warn("%%lsmagic user-expression failed: %s" % display_data)
639 return
640
641 mdict = json.loads(display_data['data'].get('application/json', {}))
642
643 for mtype in sorted(mdict):
644 subdict = mdict[mtype]
645 prefix = magic_escapes[mtype]
646 for name in sorted(subdict):
647 mclass = subdict[name]
648 magic_menu = self._get_magic_menu(mclass)
649 pmagic = prefix + name
650
651 # Adding seperate QActions is needed for some window managers
652 xaction = QtGui.QAction(pmagic,
653 self,
654 triggered=self._make_dynamic_magic(pmagic)
655 )
656 magic_menu.addAction(xaction)
657 self.all_magic_menu.addAction(xaction)
658
659 def update_all_magic_menu(self):
660 """ Update the list of magics in the "All Magics..." Menu
661
662 Request the kernel with the list of available magics and populate the
663 menu with the list received back
664
665 """
666 self.active_frontend._silent_exec_callback('get_ipython().magic("lsmagic")',
667 self.populate_all_magic_menu)
668
669 def _get_magic_menu(self,menuidentifier, menulabel=None):
670 """return a submagic menu by name, and create it if needed
671
672 Parameters
673 ----------
674
675 menulabel : str
676 Label for the menu
677
678 Will infere the menu name from the identifier at creation if menulabel not given.
679 To do so you have too give menuidentifier as a CamelCassedString
680 """
681 menu = self._magic_menu_dict.get(menuidentifier,None)
682 if not menu :
683 if not menulabel:
684 menulabel = re.sub("([a-zA-Z]+)([A-Z][a-z])","\g<1> \g<2>",menuidentifier)
685 menu = QtGui.QMenu(menulabel,self.magic_menu)
686 self._magic_menu_dict[menuidentifier]=menu
687 self.magic_menu.insertMenu(self.magic_menu_separator,menu)
688 return menu
689
690
691
585
692 def init_magic_menu(self):
586 def init_magic_menu(self):
693 self.magic_menu = self.menuBar().addMenu("&Magic")
587 self.magic_menu = self.menuBar().addMenu("&Magic")
588
589 self.add_menu_action(self.magic_menu,
590 self.magic_helper.toggleViewAction())
591
694 self.magic_menu_separator = self.magic_menu.addSeparator()
592 self.magic_menu_separator = self.magic_menu.addSeparator()
695
593
696 self.all_magic_menu = self._get_magic_menu("AllMagics", menulabel="&All Magics...")
697
698 # This action should usually not appear as it will be cleared when menu
699 # is updated at first kernel response. Though, it is necessary when
700 # connecting through X-forwarding, as in this case, the menu is not
701 # auto updated, SO DO NOT DELETE.
702 self.pop = QtGui.QAction("&Update All Magic Menu ",
703 self, triggered=self.update_all_magic_menu)
704 self.add_menu_action(self.all_magic_menu, self.pop)
705 # we need to populate the 'Magic Menu' once the kernel has answer at
706 # least once let's do it immediately, but it's assured to works
707 self.pop.trigger()
708
709 self.reset_action = QtGui.QAction("&Reset",
594 self.reset_action = QtGui.QAction("&Reset",
710 self,
595 self,
711 statusTip="Clear all variables from workspace",
596 statusTip="Clear all variables from workspace",
@@ -815,7 +700,7 b' class MainWindow(QtGui.QMainWindow):'
815
700
816 def init_magic_helper(self):
701 def init_magic_helper(self):
817 self.magic_helper_data = None
702 self.magic_helper_data = None
818 self.magic_helper = QtGui.QDockWidget("Magics", self)
703 self.magic_helper = QtGui.QDockWidget("Show Magics", self)
819 self.magic_helper.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea |
704 self.magic_helper.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea |
820 QtCore.Qt.RightDockWidgetArea)
705 QtCore.Qt.RightDockWidgetArea)
821 self.magic_helper.setVisible(False)
706 self.magic_helper.setVisible(False)
@@ -870,8 +755,6 b' class MainWindow(QtGui.QMainWindow):'
870 )
755 )
871
756
872 self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.magic_helper)
757 self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.magic_helper)
873 self.add_menu_action(self.magic_menu,
874 self.magic_helper.toggleViewAction())
875
758
876 def update_magic_helper(self, visible):
759 def update_magic_helper(self, visible):
877 if not visible or self.magic_helper_data != None:
760 if not visible or self.magic_helper_data != None:
@@ -271,8 +271,8 b' class IPythonQtConsoleApp(BaseIPythonApplication, IPythonConsoleApp):'
271 )
271 )
272 self.window.log = self.log
272 self.window.log = self.log
273 self.window.add_tab_with_frontend(self.widget)
273 self.window.add_tab_with_frontend(self.widget)
274 self.window.init_menu_bar()
275 self.window.init_magic_helper()
274 self.window.init_magic_helper()
275 self.window.init_menu_bar()
276
276
277 # Ignore on OSX, where there is always a menu bar
277 # Ignore on OSX, where there is always a menu bar
278 if sys.platform != 'darwin' and self.hide_menubar:
278 if sys.platform != 'darwin' and self.hide_menubar:
General Comments 0
You need to be logged in to leave comments. Login now