Commit 80633bad authored by David Gobbi's avatar David Gobbi Committed by Kitware Robot

Merge topic 'pyside2-support'

c1cce50d Add support for PySide2
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !4721
parents 118b08de c1cce50d
...@@ -38,6 +38,9 @@ Changes by Alex Tsui, Apr. 2015 ...@@ -38,6 +38,9 @@ Changes by Alex Tsui, Apr. 2015
Changes by Fabian Wenzel, Jan. 2016 Changes by Fabian Wenzel, Jan. 2016
Support for Python3 Support for Python3
Changes by Tobias Hänel, Sep. 2018
Support for PySide2
""" """
# Check whether a specific PyQt implementation was chosen # Check whether a specific PyQt implementation was chosen
...@@ -65,14 +68,18 @@ if PyQtImpl is None: ...@@ -65,14 +68,18 @@ if PyQtImpl is None:
PyQtImpl = "PyQt5" PyQtImpl = "PyQt5"
except ImportError: except ImportError:
try: try:
import PyQt4 import PySide2
PyQtImpl = "PyQt4" PyQtImpl = "PySide2"
except ImportError: except ImportError:
try: try:
import PySide import PyQt4
PyQtImpl = "PySide" PyQtImpl = "PyQt4"
except ImportError: except ImportError:
raise ImportError("Cannot load either PyQt or PySide") try:
import PySide
PyQtImpl = "PySide"
except ImportError:
raise ImportError("Cannot load either PyQt or PySide")
if PyQtImpl == "PyQt5": if PyQtImpl == "PyQt5":
if QVTKRWIBase == "QGLWidget": if QVTKRWIBase == "QGLWidget":
...@@ -86,6 +93,18 @@ if PyQtImpl == "PyQt5": ...@@ -86,6 +93,18 @@ if PyQtImpl == "PyQt5":
from PyQt5.QtCore import QObject from PyQt5.QtCore import QObject
from PyQt5.QtCore import QSize from PyQt5.QtCore import QSize
from PyQt5.QtCore import QEvent from PyQt5.QtCore import QEvent
elif PyQtImpl == "PySide2":
if QVTKRWIBase == "QGLWidget":
from PySide2.QtOpenGL import QGLWidget
from PySide2.QtWidgets import QWidget
from PySide2.QtWidgets import QSizePolicy
from PySide2.QtWidgets import QApplication
from PySide2.QtGui import QCursor
from PySide2.QtCore import Qt
from PySide2.QtCore import QTimer
from PySide2.QtCore import QObject
from PySide2.QtCore import QSize
from PySide2.QtCore import QEvent
elif PyQtImpl == "PyQt4": elif PyQtImpl == "PyQt4":
if QVTKRWIBase == "QGLWidget": if QVTKRWIBase == "QGLWidget":
from PyQt4.QtOpenGL import QGLWidget from PyQt4.QtOpenGL import QGLWidget
...@@ -382,7 +401,7 @@ class QVTKRenderWindowInteractor(QVTKRWIBaseClass): ...@@ -382,7 +401,7 @@ class QVTKRenderWindowInteractor(QVTKRWIBaseClass):
@staticmethod @staticmethod
def _getPixelRatio(): def _getPixelRatio():
if PyQtImpl == "PyQt5": if PyQtImpl in ["PyQt5", "PySide2"]:
# Source: https://stackoverflow.com/a/40053864/3388962 # Source: https://stackoverflow.com/a/40053864/3388962
pos = QCursor.pos() pos = QCursor.pos()
for screen in QApplication.screens(): for screen in QApplication.screens():
......
...@@ -25,7 +25,7 @@ import sys ...@@ -25,7 +25,7 @@ import sys
PyQtImpl = None PyQtImpl = None
# Has an implementation has been imported yet? # Has an implementation has been imported yet?
for impl in ["PyQt5", "PyQt4", "PySide"]: for impl in ["PyQt5", "PySide2", "PyQt4", "PySide"]:
if impl in sys.modules: if impl in sys.modules:
PyQtImpl = impl PyQtImpl = impl
break break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment