Skip to content

Commit

Permalink
spyderlib.qt: Enable PyQt4 API #1 back again, but leave #2 the defaut.
Browse files Browse the repository at this point in the history
Implement fallback logic choosing APIs: PyQt4 #2 -> PyQt4 #1 -> PySide.
Add 'pyqtv1' constant to explicitly select PyQt4 API #1.
  • Loading branch information
techtonik committed Jul 2, 2014
1 parent 7f8be85 commit e57eaf3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
default=False, help="Run Spyder in debug mode")
options, args = parser.parse_args()

assert options.gui in (None, 'pyqt', 'pyside'), \
assert options.gui in (None, 'pyqt', 'pyqtv1', 'pyside'), \
"Invalid GUI toolkit option '%s'" % options.gui

# For testing purposes
Expand Down
30 changes: 21 additions & 9 deletions spyderlib/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,48 @@

import os


def debug(msg):
# lightweight debug function
#print(msg)
pass


os.environ.setdefault('QT_API', 'pyqt')
assert os.environ['QT_API'] in ('pyqt', 'pyside')
assert os.environ['QT_API'] in ('pyqt', 'pyqtv1', 'pyside')

API = os.environ['QT_API']
API_NAME = {'pyqt': 'PyQt4', 'pyside': 'PySide'}[API]
API_NAME = None

if API == 'pyqt':
# Spyder 2.2 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.3+
import sip
try:
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
except ImportError:
debug('qt: PyQt4 is not found. Fallback to PySide API')
API = os.environ['QT_API'] = 'pyside'
except AttributeError:
# PyQt < v4.6. The actual check is done by requirements.check_qt()
# call from spyder.py
pass
# PyQt < 4.6. Fallback to API #1
debug('qt: Fallback to PyQt4 API #1')
API = os.environ['QT_API'] = 'pyqtv1'

if API in ('pyqtv1', 'pyqt'):
try:
from PyQt4.QtCore import PYQT_VERSION_STR as __version__
except ImportError:
# Switching to PySide
# No PyQt4. Fallback to PySide
debug('qt: Fallback to PySide API')
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')
import sip
try:
API_NAME += (" (API v%d)" % sip.getapi('QString'))
API_NAME = ("PyQt4 (API v%d)" % sip.getapi('QString'))
except AttributeError:
pass

Expand All @@ -50,3 +61,4 @@
raise ImportError("Spyder requires PySide or PyQt to be installed")
else:
is_old_pyqt = is_pyqt46 = False
API_NAME = 'PySide'

0 comments on commit e57eaf3

Please sign in to comment.