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

Fixed PyQt5 detection without QT_API env var #2691

Merged
merged 1 commit into from
Sep 14, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions spyderlib/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand All @@ -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')
Expand All @@ -57,6 +54,17 @@
API_NAME += (" (API v%d)" % sip.getapi('QString'))
except AttributeError:
pass
from PyQt4 import uic # analysis:ignore
Copy link
Member

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?

Copy link
Contributor Author

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 now python-qwt). Adding the line from PyQt4 import uic here will simply allow to import the uic module with from spyderlib.qt import uic, that's all. FYI, the uic module is used to run GUI built with the help of QtDesigner (see this example).

* guidata.qt , winpython.qt and qwt.qt are extensive copies of spyderlib.qt.

Copy link
Member

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.


PYQT5 = False
if API == 'pyqt5':
try:
from PyQt5.QtCore import PYQT_VERSION_STR as __version__
from PyQt5 import uic # analysis:ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this import? Do you need it for other things?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:
Expand Down