Skip to content
This repository

qt_for_kernel: use matplotlib rcParams to decide between PyQt4 and PySide #556

Closed
wants to merge 1 commit into from

4 participants

Eric Firing Min RK Evan Patterson Jean-Louis Durrieu
Eric Firing

qt_for_kernel: use matplotlib rcParams to decide between PyQt4 and PySide

This is a companion to a possible change in mpl, adding
rcParams['backend.qt4'], but should work as well with earlier
mpl versions.
(There is still a problem with mpl in the ipython console when
PySide is selected.)

Eric Firing efiring qt_for_kernel: use matplotlib rcParams to decide between PyQt4 and Py…
…Side

This is a companion to a possible change in mpl, adding
rcParams['backend.qt4'], but should work as well with earlier
mpl versions.
(There is still a problem with mpl in the ipython console when
PySide is selected.)
3177632
Min RK
Owner
minrk commented

Thanks, there are a few problems when matplotlib is imported:

  • QT_API is ignored, even if set (ETS will be unhappy)
  • PyQt4 is the default, even if PySide is the only Qt available

It also doesn't address the larger issue of working with other (non-matplotlib) code. As I understand it, the current model plays fine with matplotlib itself in both current master and release, so it's the absence of matplotlib that seems the bigger issue to address.

Our internal qt import does:

if QT_API unset:
    try:
        use_pyside
    except:
        use_pyqt_with_v2
elif QT_API='pyside':
    use_pyside
elif QT_API='pyqt':
    use_pyqt_with_v2

It seems like for the kernel-side all we want to do is change the behavior if QT_API is unset, and do:

if QT_API unset:
    try:
        use_pyqt_with_v1
    except:
        use_pyside

Since if QT_API is set, that means the user probably does use ETS (that's where we got the variable from, I believe), and will require the v2 API, but users with no configuration will get v1 PyQt4 for maximum compatibility with legacy apps. It does mean that users of ETS with PyQt must specify QT_API=pyqt, or ETS will be broken in IPython, but all 3 situations should be configurable no matter what installation combination you have.

It does demote the preferable (to us) PySide in the presence of PyQt, but that seems the safer choice at this point.

I think it's fine to ask matplotlib about the qtapi, but the fallback should be on the above pattern, not straight to pyqt4 with the v1 api.

Evan Patterson
Collaborator

My solution was clearly a bit naive (it breaks too much old code), but QT_API should be respected. Otherwise, ETS will be broken, as Min points out.

I think @minrk's proposal is a good compromise.

Eric Firing

This is superseded by PR 560.

Eric Firing efiring closed this
Jean-Louis Durrieu

Hi,

I tried to install the latest version of matplotlib, from github, in order to use pyside instead of pyqt4 (because the latter is slightly too complicated to install for "commoners"). However, it would seem that it still does not work, since by default, my rcParams['backend.qt4'] still is PyQt4... How is rcParams filled in?
I wanted to try on my mac, on which I installed already PyQt4, but renamed it so as to try to only use PySide. Could that explain why python still believes PyQt4 is my backend for Qt4?

edit: sorry, I guess that post should actually appear in the matplotlib github PR board. Anyway, I leave it, the issue seems to be the same for ipython...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 05, 2011
Eric Firing efiring qt_for_kernel: use matplotlib rcParams to decide between PyQt4 and Py…
…Side

This is a companion to a possible change in mpl, adding
rcParams['backend.qt4'], but should work as well with earlier
mpl versions.
(There is still a problem with mpl in the ipython console when
PySide is selected.)
3177632
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 6 additions and 2 deletions. Show diff stats Hide diff stats

  1. +6 2 IPython/external/qt_for_kernel.py
8 IPython/external/qt_for_kernel.py
@@ -6,7 +6,11 @@
6 6 # Older versions of matplotlib do not support PyQt4 v2 APIs or PySide, so we
7 7 # cannot go through the preferred mechanism.
8 8 matplotlib = sys.modules.get('matplotlib')
9   -if matplotlib and matplotlib.__version__ <= '1.0.1':
10   - from PyQt4 import QtCore, QtGui
  9 +if matplotlib:
  10 + mqt = matplotlib.rcParams.get('backend.qt4', 'PyQt4')
  11 + if mqt == 'PyQt4':
  12 + from PyQt4 import QtCore, QtGui
  13 + else:
  14 + from PySide import QtCore, QtGui
11 15 else:
12 16 from IPython.external.qt import QtCore, QtGui

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.