diff --git a/IPython/qt/console/mainwindow.py b/IPython/qt/console/mainwindow.py index 3824f1f..07bd9be 100644 --- a/IPython/qt/console/mainwindow.py +++ b/IPython/qt/console/mainwindow.py @@ -47,8 +47,6 @@ class MainWindow(QtGui.QMainWindow): # 'object' interface #--------------------------------------------------------------------------- - _magic_menu_dict = {} - def __init__(self, app, confirm_exit=True, new_frontend_factory=None, slave_frontend_factory=None, @@ -584,128 +582,15 @@ class MainWindow(QtGui.QMainWindow): self.add_menu_action(self.kernel_menu, self.confirm_restart_kernel_action) self.tab_widget.currentChanged.connect(self.update_restart_checkbox) - - def _make_dynamic_magic(self,magic): - """Return a function `fun` that will execute `magic` on active frontend. - - Parameters - ---------- - magic : string - string that will be executed as is when the returned function is called - - Returns - ------- - fun : function - function with no parameters, when called will execute `magic` on the - current active frontend at call time - - See Also - -------- - populate_all_magic_menu : generate the "All Magics..." menu - - Notes - ----- - `fun` executes `magic` in active frontend at the moment it is triggered, - not the active frontend at the moment it was created. - - This function is mostly used to create the "All Magics..." Menu at run time. - """ - # need two level nested function to be sure to pass magic - # to active frontend **at run time**. - def inner_dynamic_magic(): - self.active_frontend.execute(magic) - inner_dynamic_magic.__name__ = "dynamics_magic_s" - return inner_dynamic_magic - - def populate_all_magic_menu(self, display_data=None): - """Clean "All Magics..." menu and repopulate it with `display_data` - - Parameters - ---------- - display_data : dict, - dict of display_data for the magics dict of a MagicsManager. - Expects json data, as the result of %lsmagic - - """ - for k,v in self._magic_menu_dict.items(): - v.clear() - self.all_magic_menu.clear() - - if not display_data: - return - - if display_data['status'] != 'ok': - self.log.warn("%%lsmagic user-expression failed: %s" % display_data) - return - - mdict = json.loads(display_data['data'].get('application/json', {})) - - for mtype in sorted(mdict): - subdict = mdict[mtype] - prefix = magic_escapes[mtype] - for name in sorted(subdict): - mclass = subdict[name] - magic_menu = self._get_magic_menu(mclass) - pmagic = prefix + name - - # Adding seperate QActions is needed for some window managers - xaction = QtGui.QAction(pmagic, - self, - triggered=self._make_dynamic_magic(pmagic) - ) - magic_menu.addAction(xaction) - self.all_magic_menu.addAction(xaction) - - def update_all_magic_menu(self): - """ Update the list of magics in the "All Magics..." Menu - - Request the kernel with the list of available magics and populate the - menu with the list received back - - """ - self.active_frontend._silent_exec_callback('get_ipython().magic("lsmagic")', - self.populate_all_magic_menu) - - def _get_magic_menu(self,menuidentifier, menulabel=None): - """return a submagic menu by name, and create it if needed - - Parameters - ---------- - - menulabel : str - Label for the menu - - Will infere the menu name from the identifier at creation if menulabel not given. - To do so you have too give menuidentifier as a CamelCassedString - """ - menu = self._magic_menu_dict.get(menuidentifier,None) - if not menu : - if not menulabel: - menulabel = re.sub("([a-zA-Z]+)([A-Z][a-z])","\g<1> \g<2>",menuidentifier) - menu = QtGui.QMenu(menulabel,self.magic_menu) - self._magic_menu_dict[menuidentifier]=menu - self.magic_menu.insertMenu(self.magic_menu_separator,menu) - return menu - - def init_magic_menu(self): self.magic_menu = self.menuBar().addMenu("&Magic") + + self.add_menu_action(self.magic_menu, + self.magic_helper.toggleViewAction()) + self.magic_menu_separator = self.magic_menu.addSeparator() - self.all_magic_menu = self._get_magic_menu("AllMagics", menulabel="&All Magics...") - - # This action should usually not appear as it will be cleared when menu - # is updated at first kernel response. Though, it is necessary when - # connecting through X-forwarding, as in this case, the menu is not - # auto updated, SO DO NOT DELETE. - self.pop = QtGui.QAction("&Update All Magic Menu ", - self, triggered=self.update_all_magic_menu) - self.add_menu_action(self.all_magic_menu, self.pop) - # we need to populate the 'Magic Menu' once the kernel has answer at - # least once let's do it immediately, but it's assured to works - self.pop.trigger() - self.reset_action = QtGui.QAction("&Reset", self, statusTip="Clear all variables from workspace", @@ -815,7 +700,7 @@ class MainWindow(QtGui.QMainWindow): def init_magic_helper(self): self.magic_helper_data = None - self.magic_helper = QtGui.QDockWidget("Magics", self) + self.magic_helper = QtGui.QDockWidget("Show Magics", self) self.magic_helper.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea) self.magic_helper.setVisible(False) @@ -870,8 +755,6 @@ class MainWindow(QtGui.QMainWindow): ) self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.magic_helper) - self.add_menu_action(self.magic_menu, - self.magic_helper.toggleViewAction()) def update_magic_helper(self, visible): if not visible or self.magic_helper_data != None: diff --git a/IPython/qt/console/qtconsoleapp.py b/IPython/qt/console/qtconsoleapp.py index fc5a8f8..3a9aa84 100644 --- a/IPython/qt/console/qtconsoleapp.py +++ b/IPython/qt/console/qtconsoleapp.py @@ -271,8 +271,8 @@ class IPythonQtConsoleApp(BaseIPythonApplication, IPythonConsoleApp): ) self.window.log = self.log self.window.add_tab_with_frontend(self.widget) - self.window.init_menu_bar() self.window.init_magic_helper() + self.window.init_menu_bar() # Ignore on OSX, where there is always a menu bar if sys.platform != 'darwin' and self.hide_menubar: