[IPython-dev] Qt api selection re. ipython and matplotlib

Darren Dale dsdale24 at gmail.com
Mon Jul 18 13:26:06 EDT 2011


On Wed, Jul 6, 2011 at 4:23 PM, Eric Firing <efiring at hawaii.edu> wrote:
> On 07/06/2011 05:34 AM, MinRK wrote:
>> I updated my IPython PR with my understanding of the recent discussion.
>>
>> Now, QT_API will be asked *first*, and if QT_API=pyqt, IPython will
>> set the v2 APIs.
>>
>> QT_API=pyqt : use pyqt with v2
>> QT_API=pyside : use pyside
>> QT_API unset : ask matplotlib for pyqt4 or pyside, will not set v2 APIs
>>
>> The default, and most likely case remains PyQt4 without updating sip
>> apis, falling back on PySide.
>
> I have updated my mpl PR in a compatible way; the only difference is
> that I have not included a fall-back to pyside.  Either PyQt4 or PySide
> is specified as an rcParam, and if whatever is specified (either
> explicitly there or via the QT_API env var) is not there, an ImportError
> will result.  Anyone who has only PySide will have to know about it and
> use the rcParam or QT_API to request it.

Unfortunately, I think we may have to reopen this discussion. As the
master branch currently stands, the embedding_in_qt4.py example is
broken when I have the QT_API environment variable defined. The reason
is simple: the example imports from PyQt4 first, which defaults to the
v1 api, then the example imports the qt4 backend, which fails in its
attempt to set the api to v2. One workaround is to perform the mpl qt4
backend import before the PyQt4 imports, but such a requirement could
be disruptive to lots of existing code. A better alternative might be
to wrap the setapi calls in a try/except:

    import sip
    if QT_API == QT_API_PYQTv2:
        try:
            sip.setapi('QString', 2)
            sip.setapi('QVariant', 2)
        except ValueError:
            pass


Darren



More information about the IPython-dev mailing list