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

Darren Dale dsdale24 at gmail.com
Mon Jul 18 14:27:31 EDT 2011


On Mon, Jul 18, 2011 at 2:16 PM, MinRK <benjaminrk at gmail.com> wrote:
> On Mon, Jul 18, 2011 at 10:26, Darren Dale <dsdale24 at gmail.com> wrote:
>> 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
>
> QT_API=pyqt *does* imply PyQt4+v2api, since it is an ETS variable, and
> that's how they use it.

I haven't argued otherwise.

> Also note that this variable is only likely
> to be set in cases where users have both PySide and PyQt4, and the
> default is behavior is *not* what the user wants.  That said, a
> warning rather than raising is perhaps preferable, to handle users who
> have ETS applications, for which they use QT_API, but also other Qt
> programs that want to behave differently.

This was my point.



More information about the IPython-dev mailing list