diff options
Diffstat (limited to 'silx/gui/qt/_qt.py')
-rw-r--r-- | silx/gui/qt/_qt.py | 74 |
1 files changed, 58 insertions, 16 deletions
diff --git a/silx/gui/qt/_qt.py b/silx/gui/qt/_qt.py index 67f3e46..a54ea67 100644 --- a/silx/gui/qt/_qt.py +++ b/silx/gui/qt/_qt.py @@ -29,18 +29,18 @@ - `PySide <http://www.pyside.org>`_. If a Qt binding is already loaded, it will use it, otherwise the different -Qt bindings are tried in this order: PyQt4, PySide, PyQt5. +Qt bindings are tried in this order: PySide2, PyQt4, PySide, PyQt5. The name of the loaded Qt binding is stored in the BINDING variable. For an alternative solution providing a structured namespace, see `qtpy <https://pypi.python.org/pypi/QtPy/>`_ which -provides the namespace of PyQt5 over PyQt4 and PySide. +provides the namespace of PyQt5 over PyQt4, PySide and PySide2. """ -__authors__ = ["V.A. Sole - ESRF Data Analysis"] +__authors__ = ["V.A. Sole"] __license__ = "MIT" -__date__ = "17/01/2017" +__date__ = "11/10/2017" import logging @@ -52,10 +52,10 @@ _logger = logging.getLogger(__name__) BINDING = None -"""The name of the Qt binding in use: 'PyQt5', 'PyQt4' or 'PySide'.""" +"""The name of the Qt binding in use: PyQt5, 'PyQt4, PySide2 or PySide.""" QtBinding = None # noqa -"""The Qt binding module in use: PyQt5, PyQt4 or PySide.""" +"""The Qt binding module in use: PyQt5, PyQt4, PySide2 or PySide.""" HAS_SVG = False """True if Qt provides support for Scalable Vector Graphics (QtSVG).""" @@ -64,12 +64,15 @@ HAS_OPENGL = False """True if Qt provides support for OpenGL (QtOpenGL).""" # First check for an already loaded wrapper -if 'PyQt5.QtCore' in sys.modules: - BINDING = 'PyQt5' +if 'PySide2.QtCore' in sys.modules: + BINDING = 'PySide2' elif 'PySide.QtCore' in sys.modules: BINDING = 'PySide' +elif 'PyQt5.QtCore' in sys.modules: + BINDING = 'PyQt5' + elif 'PyQt4.QtCore' in sys.modules: BINDING = 'PyQt4' @@ -78,17 +81,22 @@ else: # Then try Qt bindings import PyQt4 # noqa except ImportError: try: - import PyQt5 # noqa + import PySide # noqa except ImportError: try: - import PySide # noqa + import PyQt5 # noqa except ImportError: - raise ImportError( - 'No Qt wrapper found. Install PyQt4, PyQt5 or PySide.') + try: + import PySide2 # noqa + except ImportError: + raise ImportError( + 'No Qt wrapper found. Install PyQt4, PyQt5 or PySide2.') + else: + BINDING = 'PySide2' else: - BINDING = 'PySide' + BINDING = 'PyQt5' else: - BINDING = 'PyQt5' + BINDING = 'PySide' else: BINDING = 'PyQt4' @@ -96,7 +104,7 @@ else: # Then try Qt bindings if BINDING == 'PyQt4': _logger.debug('Using PyQt4 bindings') - if sys.version < "3.0.0": + if sys.version_info < (3, ): try: import sip @@ -201,8 +209,42 @@ elif BINDING == 'PyQt5': Slot = pyqtSlot +elif BINDING == 'PySide2': + _logger.debug('Using PySide2 bindings') + _logger.warning( + 'Using PySide2 Qt binding: PySide2 support in silx is experimental!') + + import PySide2 as QtBinding # noqa + + from PySide2.QtCore import * # noqa + from PySide2.QtGui import * # noqa + from PySide2.QtWidgets import * # noqa + from PySide2.QtPrintSupport import * # noqa + + try: + from PySide2.QtOpenGL import * # noqa + except ImportError: + _logger.info("PySide2.QtOpenGL not available") + HAS_OPENGL = False + else: + HAS_OPENGL = True + + try: + from PySide2.QtSvg import * # noqa + except ImportError: + _logger.info("PySide2.QtSvg not available") + HAS_SVG = False + else: + HAS_SVG = True + + # Import loadUi wrapper for PySide2 + # TODO from ._pyside_dynamic import loadUi # noqa + + pyqtSignal = Signal + else: - raise ImportError('No Qt wrapper found. Install PyQt4, PyQt5 or PySide') + raise ImportError('No Qt wrapper found. Install PyQt4, PyQt5, PySide2') + # provide a exception handler but not implement it by default def exceptionHandler(type_, value, trace): |