ipython/ipython — pull request #2957 by ChrisBeaumont (2013-02-20 20:05:09+00:00)
Title: Refactor qt import logic. Fixes #2955

This PR reorganizes the logic used to transparently import a Qt binding. In addition to extracting logic into smaller functions, there are some extra guards against importing multiple incompatible versions of Qt. With the new availability of in-process QT kernels, it is more likely that user-code may use Qt in a way incompatible with IPython. This PR protects against that.

Most of the logic of which API gets imported is the same. The main changes are:

* IPython will detect and raise an ImportError if Qt has already been imported in an incompatible way.
* After loading Qt, IPython installs an import hook that prevents the import of other Qt apis by user code (with an informative error message)
* Since backend Qt code is apparently compatible with all 3 Qt APIs, `qt_from_kernel.py` will default to use any previously imported Qt module.
* The new code is slightly more strict with regard to raising an ImportError after failed Qt import attempts. The hope is that IPython code will never trigger a crash.

This code also fixes #2955, since the new `qt_from_kernel` handles the case when IPython frontend QT code is imported before backend code.

This has NOT yet been tested on machines missing either PySide or PyQt4.