Skip to content

Commit

Permalink
Set PyQt API version to #2 to avoid a hard crash with Jupyter 4.0
Browse files Browse the repository at this point in the history
Fixes #2608

- We were not supporting API #1 since we moved to demand PyQt 4.6+
(in 2.3.0).
  • Loading branch information
ccordoba12 committed Aug 15, 2015
1 parent ab95ebb commit f5ee456
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 42 deletions.
5 changes: 0 additions & 5 deletions spyderlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ def get_versions(reporev=True):
"""Get version information for components used by Spyder"""
import sys
import platform
# Hack to let IPython set QT_API, in case it's installed
try:
from IPython.external import qt # analysis:ignore
except (ImportError, ValueError):
pass
import spyderlib.qt
import spyderlib.qt.QtCore

Expand Down
24 changes: 13 additions & 11 deletions spyderlib/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,26 @@
API_NAME = {'pyqt': 'PyQt4', 'pyside': 'PySide'}[API]

if API == 'pyqt':
# We do not force QString, QVariant, ... API to #1 or #2 anymore
# as spyderlib is now compatible with both APIs
# import sip
# try:
# sip.setapi('QString', 2)
# sip.setapi('QVariant', 2)
# except AttributeError:
# # PyQt < v4.6: in future version, we should warn the user
# # that PyQt is outdated and won't be supported by Spyder >v2.1
# pass
# Since Spyder 2.3.6 we only support API #2
import sip
try:
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
sip.setapi('QDate', 2)
sip.setapi('QDateTime', 2)
sip.setapi('QTextStream', 2)
sip.setapi('QTime', 2)
sip.setapi('QUrl', 2)
except AttributeError:
pass

try:
from PyQt4.QtCore import PYQT_VERSION_STR as __version__
except ImportError:
# Switching to PySide
API = os.environ['QT_API'] = 'pyside'
API_NAME = 'PySide'
else:
__version_info__ = tuple(__version__.split('.')+['final', 1])
is_old_pyqt = __version__.startswith(('4.4', '4.5', '4.6', '4.7'))
is_pyqt46 = __version__.startswith('4.6')
import sip
Expand Down
36 changes: 10 additions & 26 deletions spyderlib/spyder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@


#==============================================================================
# Test if IPython is installed to eventually switch to PyQt API #2
# Check requirements
#==============================================================================
from spyderlib import requirements
requirements.check_path()
requirements.check_qt()


#==============================================================================
# IPython dependencies
#==============================================================================
from spyderlib.baseconfig import _
from spyderlib.ipythonconfig import IPYTHON_QT_INSTALLED, SUPPORTED_IPYTHON
Expand All @@ -52,30 +60,6 @@
dependencies.add("zmq", _("IPython Console integration"),
required_version='>=2.1.11')

if IPYTHON_QT_INSTALLED:
# Importing IPython will eventually set the QT_API environment variable
import IPython # analysis:ignore
if os.environ.get('QT_API', 'pyqt') == 'pyqt':
# If PyQt is the selected GUI toolkit (at this stage, only the
# bootstrap script has eventually set this option), switch to
# PyQt API #2 by simply importing the IPython qt module
os.environ['QT_API'] = 'pyqt'
try:
from IPython.external import qt #analysis:ignore
except ImportError:
# Avoid raising any error here: the spyderlib.requirements module
# will take care of it, in a user-friendly way (Tkinter message box
# if no GUI toolkit is installed)
pass


#==============================================================================
# Check requirements
#==============================================================================
from spyderlib import requirements
requirements.check_path()
requirements.check_qt()


#==============================================================================
# Windows platforms only: support for hiding the attached console window
Expand Down Expand Up @@ -128,7 +112,7 @@
#==============================================================================
# Create splash screen out of MainWindow to reduce perceived startup time.
#==============================================================================
from spyderlib.baseconfig import _, get_image_path
from spyderlib.baseconfig import get_image_path
SPLASH = QSplashScreen(QPixmap(get_image_path('splash.png'), 'png'))
SPLASH_FONT = SPLASH.font()
SPLASH_FONT.setPixelSize(10)
Expand Down

0 comments on commit f5ee456

Please sign in to comment.