-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fixed PyQt5 detection without QT_API env var #2691
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,17 +15,7 @@ | |
API = os.environ['QT_API'] | ||
API_NAME = {'pyqt5': 'PyQt5', 'pyqt': 'PyQt4', 'pyside': 'PySide'}[API] | ||
|
||
PYQT5 = False | ||
|
||
if API == 'pyqt5': | ||
try: | ||
from PyQt5.QtCore import PYQT_VERSION_STR as __version__ | ||
is_old_pyqt = False | ||
is_pyqt46 = False | ||
PYQT5 = True | ||
except ImportError: | ||
pass | ||
elif API == 'pyqt': | ||
if API == 'pyqt': | ||
# Spyder 2.3 is compatible with both #1 and #2 PyQt API, | ||
# but to avoid issues with IPython and other Qt plugins | ||
# we choose to support only API #2 for 2.4+ | ||
|
@@ -46,9 +36,16 @@ | |
|
||
from PyQt4.QtCore import PYQT_VERSION_STR as __version__ # analysis:ignore | ||
except ImportError: | ||
# Switching to PySide | ||
API = os.environ['QT_API'] = 'pyside' | ||
API_NAME = 'PySide' | ||
# Trying PyQt5 before switching to PySide (at this point, PyQt4 may | ||
# not be installed but PyQt5 or Pyside could still be if the QT_API | ||
# environment variable hasn't been set-up) | ||
try: | ||
import PyQt5 # analysis:ignore | ||
API = os.environ['QT_API'] = 'pyqt5' | ||
API_NAME = 'PyQt5' | ||
except ImportError: | ||
API = os.environ['QT_API'] = 'pyside' | ||
API_NAME = 'PySide' | ||
else: | ||
is_old_pyqt = __version__.startswith(('4.4', '4.5', '4.6', '4.7')) | ||
is_pyqt46 = __version__.startswith('4.6') | ||
|
@@ -57,6 +54,17 @@ | |
API_NAME += (" (API v%d)" % sip.getapi('QString')) | ||
except AttributeError: | ||
pass | ||
from PyQt4 import uic # analysis:ignore | ||
|
||
PYQT5 = False | ||
if API == 'pyqt5': | ||
try: | ||
from PyQt5.QtCore import PYQT_VERSION_STR as __version__ | ||
from PyQt5 import uic # analysis:ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same explanation as above. |
||
PYQT5 = True | ||
is_old_pyqt = is_pyqt46 = False | ||
except ImportError: | ||
pass | ||
|
||
if API == 'pyside': | ||
try: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
spyderlib.qt
package was wrote not only for Spyder but also for other libraries* (guidata
,winpython
and nowpython-qwt
). Adding the linefrom PyQt4 import uic
here will simply allow to import theuic
module withfrom spyderlib.qt import uic
, that's all. FYI, theuic
module is used to run GUI built with the help of QtDesigner (see this example).*
guidata.qt
,winpython.qt
andqwt.qt
are extensive copies ofspyderlib.qt
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, no problem. I just wanted to know why you decided to add it given that we don't use QtDesigner in Spyder.
By the way, we're planning to move to use qtpy (one of the Spyder org projects) as our Qt shim.
I think that would help your projects too, to avoid copy/pasting the Spyder shim around, and to have everything consolidated in one place.