Skip to content
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

Update to use qtpy imports #23

Closed
goanpeca opened this issue Nov 7, 2023 · 1 comment
Closed

Update to use qtpy imports #23

goanpeca opened this issue Nov 7, 2023 · 1 comment

Comments

@goanpeca
Copy link

goanpeca commented Nov 7, 2023

Hello team!

The plugin documentation for napari has a set of best practices for developers, which includes a clause recommending not to depend directly on PyQt5 or PySide2 to allow end-users to choose their bindings freely. More details here.

The files using PyQt5 instead of qtpy are listed here ->

Also I suggest you do not use the * import. That is generally not recommended

Some options might include changing this code

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import *

To

from qtpy.QtCore import Qt
from qtpy.QtWidgets import QWidget   # and explicitely list everything that is needed

Or to

from qtpy import QtCore
from qtpy import QtWidgets

# And then use it like

class OrganoidCounterWidget(QtWidgets.QWidget):

I favor option 1 as it is more explicit in what needs to be imported for a given module.

Is there a reason you need PyQt5 explicitly? Could these imports be updated to use qtpy for the next release?

If you have questions, or need some help, let me know :)

Thanks! 🚀

@christinab12
Copy link
Collaborator

Thanks so much for your tips @goanpeca! #25 includes these changes, I will push a new version now :)

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

2 participants