Updates to example code and docs - should land before 0.11, but I wanted someone else to give this a once over, because I don't know much about this code.
Update gui-qt.py example file so it works with the new Qt GUI support.
Corrections to documentation of GUI event loop support.
Various corrections to interactive reference docs; removed informatio…
…n on shadow history.
N.B. There's now also some unrelated corrections to the docs lumped in with this. I know that's bad practice, but the other changes should be straightforward.
The import at the top of the example unconditionally uses PyQt4, while IPython itself has been refactored to honor the QT_API setting. Is IPython.external.qt_for_kernel meant for application-level use? If so, it could be used instead of the direct PyQt4 import. If not, a comment above the PyQt4 import might be helpful.
I have tried to run this example three ways:
ipython qtconsole --gui-qt
In all of these cases, I don't think that start_event_loop_qt4 has any effect if enable_qt4 has already been invoked. inputhook.enable_qt4 unconditionally sets the _in_event_loop flag to True for the current QApplication instance, even though it never invoked QApplication.exec_(). (See inputhookd.py, line 211.)
Then, guisupport.start_event_loop_qt4 checks this flag, sees that it is already set, and does nothing except set the flag again. (See guisupport.py, line 139.)
Is your installed version of IPython up to date? 2 and 3 work for me (interactive console etc.), although 1 doesn't show the window at all. You're right that start_event_loop_qt4 has no effect, although I'm not sure what is actually starting the event loop.
I'm running directly from github head, installed and invoked as described at http://ipython.scipy.org/moin/Developer_Zone. (I.E. I ran setupegg.py develop, and I'm invoking its ipython.py directly.) Perhaps it's a PyQt4 vs. PySide difference? (I have the latest stable version of PySide installed, as of yesterday, and QT_API is set to "pyside".)
OK, I'm testing with PyQt. At a guess, we're installing the inputhook in pyside (via qt_for_kernel, which looks at QT_API), and the gui-qt.py example is running with PyQt. I'm not sure what the best way to handle this is. We could get external applications to import from qt_for_kernel and fall back to PyQt/Pyside, but that would require further changes for any code already written with the v1 APIs in PyQt (as Pyside only has v2).
The code does work, but the example doesn't take into account the possible combinations of Qt bindings. For now, you'll need to ensure that your code imports the same bindings as set in QT_API - via qt_for_kernel if it's convenient.
Oh, I already discovered the hard way that the example code doesn't run at all unless I change the import from PyQt4 to import from PySide (hence my request for a comment about that, and several noisy messages on the mail list). So I think I've already got that covered. The results that I described in my second comment here were already in the context of using consistent bindings.
import from PyQt4
import from PySide
Note that import from external.qt_for_kernel throws ImportError for cases 2 or 3. In other words, it seems I can only use it if I'm running from the Qt console. So I modified my copy of the example to directly import from PySide.
import from external.qt_for_kernel
If there's any grunt work I could do that would be helpful, let me know. E.G. I could test, either on Windows or Linux, with either PyQt or PySide.
I get the same results as you (almost) if I use PyQt4 instead of PySide.
So, I concur that the problem must be related to PySide vs. PyQt.
When using the Qt console, %gui throws a NotImplementedError (zmqshell.py line 387). Unless this is a temporary condition, can we have a note in the documentation explaining that --gui=qt must be used instead when starting the Qt console?
@minrk: Do you know anything about this? Is it simple to make the %gui and %pylab commands work from the Qt console?
Based on the results I got from the gui-qt.py example, I don't know if it is proper for line 1215 to imply that GUIs can be used interactively from the IPython console, at least for Qt. I still don't know enough to be able to tell if this is just because the example is still not quite right, or if this is a limitation of the current QT GUI support, or maybe I'm just plain wrong. If this is a temporary limitation of the current code base, could the documentation include a warning message that this is the case? (Such as the warning at the top of the "IPython as a System Shell" section.)
Later in this documentation section, there is a code snippet (wx-specific) that includes a call to enable_wx. Based on your changes to the gui-qt.py example, it appears that at least in the case of Qt, an additional call to start_event_loop_qt4 is also required there. I'm not sure if that is right, but as it stands the example and the documentation are not consistent.
I appreciate the time you have been taking to look at these issues. I do not want to come across as critical.
Remove unnecessary code from gui-qt.py example
Closing because I've merged it into #620, where further discussion/work is taking place until we sort this out completely. Thanks!