From 65546bf8a85a3fdf359d0784204360e9ecdc95ec 2011-11-28 02:46:11
From: Fernando Perez <Fernando.Perez@berkeley.edu>
Date: 2011-11-28 02:46:11
Subject: [PATCH] Temporary fix to work around #1057.

Basically it reverts the effect of #956 and goes back to a static list
for the 'all magics' menu.  I tried to mark very clearly the new code
so we can disable it once a proper fix for #1057 is committed, but we
can't have a broken qt console in master.

---

diff --git a/IPython/frontend/qt/console/mainwindow.py b/IPython/frontend/qt/console/mainwindow.py
index 7257d54..cd0a721 100644
--- a/IPython/frontend/qt/console/mainwindow.py
+++ b/IPython/frontend/qt/console/mainwindow.py
@@ -626,9 +626,17 @@ class MainWindow(QtGui.QMainWindow):
         # 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)
+
+        ########################################################################
+        ## TEMPORARILY DISABLED - see #1057 for details.  Uncomment this
+        ## section when a proper fix is found
+        
+        ## 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)
+
+        ## END TEMPORARY FIX
+        ########################################################################
 
         self.reset_action = QtGui.QAction("&Reset",
             self,
@@ -666,6 +674,49 @@ class MainWindow(QtGui.QMainWindow):
             triggered=self.whos_magic_active_frontend)
         self.add_menu_action(self.magic_menu, self.whos_action)
 
+
+        ########################################################################
+        ## TEMPORARILY ADDED BACK - see #1057 for details.  The magic menu is
+        ## supposed to be dynamic, but the mechanism merged in #1057 has a race
+        ## condition that locks up the console very often.  We're putting back
+        ## the static list temporarily/ Remove this code when a proper fix is
+        ## found.
+        
+        # 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)
+
+        ## END TEMPORARY FIX
+        ########################################################################
+
+
     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 21594e8..727cb93 100644
--- a/IPython/frontend/qt/console/qtconsoleapp.py
+++ b/IPython/frontend/qt/console/qtconsoleapp.py
@@ -452,8 +452,15 @@ class IPythonQtConsoleApp(BaseIPythonApplication):
         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)
+        # we need to populate the 'Magic Menu' once the kernel has answer at
+        # least once 
+
+        ########################################################################
+        ## TEMPORARILY DISABLED - see #1057 for details, uncomment the next
+        ## line when a proper fix is found:
+        ## self.kernel_manager.shell_channel.first_reply.connect(self.window.pop.trigger)
+        ## END TEMPORARY FIX
+        ########################################################################
 
         self.window.setWindowTitle('Python' if self.pure else 'IPython')