diff --git a/IPython/frontend/qt/console/mainwindow.py b/IPython/frontend/qt/console/mainwindow.py index 334d9cc..33bcf3e 100644 --- a/IPython/frontend/qt/console/mainwindow.py +++ b/IPython/frontend/qt/console/mainwindow.py @@ -547,15 +547,23 @@ class MainWindow(QtGui.QMainWindow): def update_all_magic_menu(self): # first define a callback which will get the list of all magic and put it in the menu. def populate_all_magic_menu(val=None): - alm_magic_menu = self.magic_menu.addMenu("&All Magics...") + alm_magic_menu = self.all_magic_menu + alm_magic_menu.clear() def make_dynamic_magic(i): def inner_dynamic_magic(): self.active_frontend.execute(i) inner_dynamic_magic.__name__ = "dynamics_magic_s" return inner_dynamic_magic + # list of protected magic that don't like to be called without argument + # append '?' to the end to print the docstring when called from the menu + protected_magic= ["more","less","load_ext","pycat"] + for magic in eval(val): - pmagic = '%s%s'%('%',magic) + if magic in protected_magic: + pmagic = '%s%s%s'%('%',magic,'?') + else: + pmagic = '%s%s'%('%',magic) xaction = QtGui.QAction(pmagic, self, triggered=make_dynamic_magic(pmagic) @@ -566,12 +574,13 @@ class MainWindow(QtGui.QMainWindow): def init_magic_menu(self): self.magic_menu = self.menuBar().addMenu("&Magic") self.all_magic_menu = self.magic_menu.addMenu("&All Magics") - - self.pop = QtGui.QAction("&Populate All Magic Menu", + + # this action should not appear as it will be cleard when menu + # will be updated at first kernel response. + self.pop = QtGui.QAction("&Update All Magic Menu ", self, - statusTip="Clear all varible from workspace", triggered=self.update_all_magic_menu) - self.add_menu_action(self.magic_menu, self.pop) + self.add_menu_action(self.all_magic_menu, self.pop) self.reset_action = QtGui.QAction("&Reset", self, @@ -609,33 +618,6 @@ class MainWindow(QtGui.QMainWindow): triggered=self.whos_magic_active_frontend) self.add_menu_action(self.magic_menu, self.whos_action) - # allmagics submenu: - - #for now this is just a copy and paste, but we should get this dynamically - magiclist=["%alias", "%autocall", "%automagic", "%bookmark", "%cd", "%clear", - "%colors", "%debug", "%dhist", "%dirs", "%doctest_mode", "%ed", "%edit", "%env", "%gui", - "%guiref", "%hist", "%history", "%install_default_config", "%install_profiles", - "%less", "%load_ext", "%loadpy", "%logoff", "%logon", "%logstart", "%logstate", - "%logstop", "%lsmagic", "%macro", "%magic", "%man", "%more", "%notebook", "%page", - "%pastebin", "%pdb", "%pdef", "%pdoc", "%pfile", "%pinfo", "%pinfo2", "%popd", "%pprint", - "%precision", "%profile", "%prun", "%psearch", "%psource", "%pushd", "%pwd", "%pycat", - "%pylab", "%quickref", "%recall", "%rehashx", "%reload_ext", "%rep", "%rerun", - "%reset", "%reset_selective", "%run", "%save", "%sc", "%sx", "%tb", "%time", "%timeit", - "%unalias", "%unload_ext", "%who", "%who_ls", "%whos", "%xdel", "%xmode"] - - def make_dynamic_magic(i): - def inner_dynamic_magic(): - self.active_frontend.execute(i) - inner_dynamic_magic.__name__ = "dynamics_magic_%s" % i - return inner_dynamic_magic - - for magic in magiclist: - xaction = QtGui.QAction(magic, - self, - triggered=make_dynamic_magic(magic) - ) - self.all_magic_menu.addAction(xaction) - def init_window_menu(self): self.window_menu = self.menuBar().addMenu("&Window") if sys.platform == 'darwin': diff --git a/IPython/frontend/qt/console/qtconsoleapp.py b/IPython/frontend/qt/console/qtconsoleapp.py index 0a78aae..95b60a8 100644 --- a/IPython/frontend/qt/console/qtconsoleapp.py +++ b/IPython/frontend/qt/console/qtconsoleapp.py @@ -451,6 +451,10 @@ class IPythonQtConsoleApp(BaseIPythonApplication): self.window.log = self.log self.window.add_tab_with_frontend(self.widget) self.window.init_menu_bar() + + #we need to populate the 'Magic Menu' once the kernel has answer at least once + self.kernel_manager.shell_channel.first_reply.connect(self.window.pop.trigger) + self.window.setWindowTitle('Python' if self.pure else 'IPython') def init_colors(self):