Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update gui-qt.py example file so it works with the new Qt GUI support.

  • Loading branch information...
commit 5a20bad79b1814bb7543c0c804993884e2c75ba4 1 parent bbe178a
@takluyver authored
Showing with 4 additions and 1 deletion.
  1. +4 −1 docs/examples/lib/gui-qt.py
View
5 docs/examples/lib/gui-qt.py
@@ -35,6 +35,9 @@ def __init__(self, parent=None):
sw.show()
try:
- from IPython import enable_qt4; enable_qt4(app)
+ from IPython.lib.inputhook import enable_qt4
+ enable_qt4()
+ from IPython.lib.guisupport import start_event_loop_qt4
+ start_event_loop_qt4(app)
except ImportError:
app.exec_()

10 comments on commit 5a20bad

@code-affinity

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.

@code-affinity

I have tried to run this example three ways:

  1. From ipython qtconsole --gui-qt: The result is, the SimpleWindow is not rendered unless app.exec_() is explicitly invoked at the console, at which point the console stops being interactive until the window is closed.

  2. From ipython --gui-qt: Same result.

  3. From ipython: The SimpleWindow is rendered properly, but only because the except clause was executed, causing app.exec_() to be invoked. Again, the console stops being interactive until the SimpleWindow is closed.

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.)

@takluyver
Owner

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.

@code-affinity

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".)

@takluyver
Owner

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.

@code-affinity

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.

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.

@takluyver
Owner
@code-affinity

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.

@code-affinity

I get the same results as you (almost) if I use PyQt4 instead of PySide.

  1. From ipython qtconsole --gui-qt: The SimpleWindow is not rendered unless app.exec_() is explicitly invoked at the console, at which point the console stops being interactive until the window is closed. You mentioned that you never saw the window at all. I immediately see a window frame, and then after I invoke exec_ I see the complete window.

  2. From ipython --gui-qt: The fully-rendered window immediately appears. The console continues to be interactive, although performance is very bad, and it stays that way even after the SimpleWindow is closed. I guess this is the pyreadline interaction that was warned about.

  3. From ipython: Same result as 2.

So, I concur that the problem must be related to PySide vs. PyQt.

@takluyver
Owner
Please sign in to comment.
Something went wrong with that request. Please try again.