Skip to content

Integration with qtpy #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rth opened this issue Sep 15, 2017 · 5 comments
Closed

Integration with qtpy #184

rth opened this issue Sep 15, 2017 · 5 comments

Comments

@rth
Copy link
Contributor

rth commented Sep 15, 2017

The support of multiple PyQt / PySide backends is a recurrent problem for any project working with Qt in Python. In pytest-qt it is solved by providing a compatibility _QtApi interface in qt_compat.py (that is not in the public interface). At the same time there are packages that specialize in providing such a compatibility interface, namely spyder-ide/qtpy and mottosso/Qt.py. For project that use one of those packages (e.g. matplotlib is considering it), and wanting to test it with with pytest-qt it would mean that they would not, technically be testing the project in the same conditions (and it would also mean setting differently named environment variables twice PYTEST_QT_API and QT_API or QT_PREFERRED_BINDING.)

I think the integration could be straightforward: e.g. to integrate with qtpy, the following should almost work,

At the end of pytestqt/qt_compat.py

try:
    if 'QT_API' not in os.environ and 'PYTEST_QT_API' in os.environ:
        os.environ['QT_API'] = os.environ['PYTEST_QT_API']
    import qtpy
    qt_api = qtpy
    qt_api.pytest_qt_api = qtpy.API
except ImportError:
     # fallback to the built-in compatibility layer..
    qt_api = _QtApi()

And maybe one extra environment in TravisCI for testing..

What do you think?

@nicoddemus
Copy link
Member

Hi @rth,

I wouldn't mind ditching the current API layer if qtpy fits the bill, it would mean less code to maintain.

Does qtpy support lazy loading?

My preference would be to completely remove the compatibility API and use qtpy directly, if we can maintain backward compatibility with PYTEST_QT_API configuration and lazy loading.

@rth
Copy link
Contributor Author

rth commented Sep 15, 2017

Does qtpy support lazy loading?

Aww right, that's another challenge. No qtpy doesn't and expect explicit imports e.g. import qtpy.QtCore. Qt.py (!=qtpy the names are just not confusing) seems to import everything by default if I understood correctly. Maybe one could just wrap qtpy in something like this example mottosso/Qt.py#152 (comment) as a way around it?

Though this would add one extra layer of indirection for the wrapper around the wrapper around Qt :/

@The-Compiler
Copy link
Member

There's already some discussion about this at #130 (comment) FWIW.

@machinekoder
Copy link

python_qt_bindings is another wrapper provided by the ROS project: http://wiki.ros.org/python_qt_binding

@nicoddemus
Copy link
Member

Thanks for the pointer @machinekoder.

But as commented in #130 (comment) it is probably not worth to use a wrapper, the qt_compat module provides lazy loading and doesn't really add too much to maintenance because we don't need to import the entire API anyway, just a few symbols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants