From 270d5ddc31c26b62379e3caa9044dd75ccc71847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Picca=20Fr=C3=A9d=C3=A9ric-Emmanuel?= Date: Sun, 4 Mar 2018 10:20:27 +0100 Subject: New upstream version 0.7.0+dfsg --- silx/gui/qt/_qt.py | 64 ++++++++++++++++++++++++++++++++++++++++++--------- silx/gui/qt/_utils.py | 25 +++++++++++++++++--- 2 files changed, 75 insertions(+), 14 deletions(-) (limited to 'silx/gui/qt') diff --git a/silx/gui/qt/_qt.py b/silx/gui/qt/_qt.py index 0962c21..a54ea67 100644 --- a/silx/gui/qt/_qt.py +++ b/silx/gui/qt/_qt.py @@ -29,18 +29,18 @@ - `PySide `_. 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 `_ 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,7 +64,10 @@ HAS_OPENGL = False """True if Qt provides support for OpenGL (QtOpenGL).""" # First check for an already loaded wrapper -if 'PySide.QtCore' in sys.modules: +if 'PySide2.QtCore' in sys.modules: + BINDING = 'PySide2' + +elif 'PySide.QtCore' in sys.modules: BINDING = 'PySide' elif 'PyQt5.QtCore' in sys.modules: @@ -83,8 +86,13 @@ else: # Then try Qt bindings try: 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 = 'PyQt5' else: @@ -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): diff --git a/silx/gui/qt/_utils.py b/silx/gui/qt/_utils.py index 0aa3ef1..be55465 100644 --- a/silx/gui/qt/_utils.py +++ b/silx/gui/qt/_utils.py @@ -30,15 +30,34 @@ __license__ = "MIT" __date__ = "30/11/2016" import sys -from ._qt import BINDING, QImageReader +from . import _qt as qt def supportedImageFormats(): """Return a set of string of file format extensions supported by the Qt runtime.""" - if sys.version_info[0] < 3 or BINDING == 'PySide': + if sys.version_info[0] < 3 or qt.BINDING in ('PySide', 'PySide2'): convert = str else: convert = lambda data: str(data, 'ascii') - formats = QImageReader.supportedImageFormats() + formats = qt.QImageReader.supportedImageFormats() return set([convert(data) for data in formats]) + + +__globalThreadPoolInstance = None +"""Store the own silx global thread pool""" + + +def silxGlobalThreadPool(): + """"Manage an own QThreadPool to avoid issue on Qt5 Windows with the + default Qt global thread pool. + + :rtype: qt.QThreadPool + """ + global __globalThreadPoolInstance + if __globalThreadPoolInstance is None: + tp = qt.QThreadPool() + # This pointless command fixes a segfault with PyQt 5.9.1 on Windows + tp.setMaxThreadCount(tp.maxThreadCount()) + __globalThreadPoolInstance = tp + return __globalThreadPoolInstance -- cgit v1.2.3