Skip to content

Commit

Permalink
Merge: Set PyQt4 API #2 by default (pull request #90)
Browse files Browse the repository at this point in the history
- API #1 is not allowed anymore
  • Loading branch information
ccordoba12 committed Dec 18, 2014
2 parents 8796773 + 476dbfa commit 35a5308
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 52 deletions.
5 changes: 0 additions & 5 deletions spyderlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,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
except ImportError:
pass
import spyderlib.qt
import spyderlib.qt.QtCore

Expand Down
12 changes: 10 additions & 2 deletions spyderlib/ipythonconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@
"""

from spyderlib.utils import programs
from spyderlib import dependencies
from spyderlib.baseconfig import _

IPYTHON_REQVER = '>=0.13'
ZMQ_REQVER = '>=2.1.11'

dependencies.add("IPython", _("IPython Console integration"),
required_version=IPYTHON_REQVER)
dependencies.add("zmq", _("IPython Console integration"),
required_version=ZMQ_REQVER)

def is_qtconsole_installed():
pyzmq_installed = programs.is_module_installed('zmq')
pyzmq_installed = programs.is_module_installed('zmq', version=ZMQ_REQVER)
if programs.is_module_installed('IPython.qt') and pyzmq_installed:
return True
elif programs.is_module_installed('IPython.frontend.qt') and \
Expand All @@ -21,5 +30,4 @@ def is_qtconsole_installed():
else:
return False

SUPPORTED_IPYTHON = '>=0.13'
IPYTHON_QT_INSTALLED = is_qtconsole_installed()
26 changes: 14 additions & 12 deletions spyderlib/qt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2011 Pierre Raybaut
# Copyright © 2011-2012 Pierre Raybaut
# © 2012-2014 anatoly techtonik
# Licensed under the terms of the MIT License
# (see spyderlib/__init__.py for details)

Expand All @@ -15,24 +16,25 @@
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
# 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+
import sip
try:
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
except AttributeError:
# PyQt < v4.6. The actual check is done by requirements.check_qt()
# call from spyder.py
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
37 changes: 4 additions & 33 deletions spyderlib/spyder.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,6 @@
ORIGINAL_SYS_EXIT = sys.exit


#==============================================================================
# Test if IPython v0.13+ is installed to eventually switch to PyQt API #2
#==============================================================================
from spyderlib.baseconfig import _
from spyderlib.ipythonconfig import IPYTHON_QT_INSTALLED, SUPPORTED_IPYTHON
from spyderlib import dependencies

dependencies.add("IPython", _("IPython Console integration"),
required_version=SUPPORTED_IPYTHON)
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
#==============================================================================
Expand All @@ -76,7 +47,7 @@


#==============================================================================
# Windows platforms only: support for hiding the attached console window
# Windows only: support for hiding console window when started with python.exe
#==============================================================================
set_attached_console_visible = None
is_attached_console_visible = None
Expand Down Expand Up @@ -116,9 +87,7 @@


#==============================================================================
# Initial splash screen to reduce perceived startup time.
# It blends with the one of MainWindow (i.e. self.splash) and it's hidden
# just before that one.
# Splash screen
#==============================================================================
from spyderlib.baseconfig import _, get_image_path
SPLASH_APP = QApplication([''])
Expand All @@ -142,6 +111,8 @@
running_in_mac_app)
from spyderlib.config import CONF, EDIT_EXT, IMPORT_EXT, OPEN_FILES_PORT
from spyderlib.cli_options import get_options
from spyderlib import dependencies
from spyderlib.ipythonconfig import IPYTHON_QT_INSTALLED
from spyderlib.userconfig import NoDefault
from spyderlib.utils import encoding, programs
from spyderlib.utils.iofuncs import load_session, save_session, reset_session
Expand Down

0 comments on commit 35a5308

Please sign in to comment.