Merge branch 'pyqt5' of https://github.com/mfitzp/pyqtgraph into mfitzp-pyqt5
This commit is contained in:
commit
8046f1e4ff
@ -11,25 +11,40 @@ This module exists to smooth out some of the differences between PySide and PyQt
|
|||||||
|
|
||||||
import sys, re
|
import sys, re
|
||||||
|
|
||||||
|
PYSIDE = 0
|
||||||
|
PYQT4 = 1
|
||||||
|
PYQT5 = 2
|
||||||
|
|
||||||
|
USE_QT_PY = None
|
||||||
|
|
||||||
## Automatically determine whether to use PyQt or PySide.
|
## Automatically determine whether to use PyQt or PySide.
|
||||||
## This is done by first checking to see whether one of the libraries
|
## This is done by first checking to see whether one of the libraries
|
||||||
## is already imported. If not, then attempt to import PyQt4, then PySide.
|
## is already imported. If not, then attempt to import PyQt4, then PySide.
|
||||||
if 'PyQt4' in sys.modules:
|
if 'PyQt4' in sys.modules:
|
||||||
USE_PYSIDE = False
|
USE_QT_PY = PYQT4
|
||||||
|
if 'PyQt5' in sys.modules:
|
||||||
|
USE_QT_PY = PYQT5
|
||||||
elif 'PySide' in sys.modules:
|
elif 'PySide' in sys.modules:
|
||||||
USE_PYSIDE = True
|
USE_QT_PY = PYSIDE
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
import PyQt4
|
import PyQt4
|
||||||
USE_PYSIDE = False
|
USE_QT_PY = PYQT4
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
import PySide
|
import PyQt5
|
||||||
USE_PYSIDE = True
|
USE_QT_PY = PYQT5
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise Exception("PyQtGraph requires either PyQt4 or PySide; neither package could be imported.")
|
try:
|
||||||
|
import PySide
|
||||||
|
USE_QT_PY = PYSIDE
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if USE_PYSIDE:
|
if USE_QT_PY == None:
|
||||||
|
raise Exception("PyQtGraph requires one of PyQt4, PyQt5 or PySide; none of these packages could be imported.")
|
||||||
|
|
||||||
|
if USE_QT_PY == PYSIDE:
|
||||||
from PySide import QtGui, QtCore, QtOpenGL, QtSvg
|
from PySide import QtGui, QtCore, QtOpenGL, QtSvg
|
||||||
import PySide
|
import PySide
|
||||||
try:
|
try:
|
||||||
@ -82,8 +97,8 @@ if USE_PYSIDE:
|
|||||||
|
|
||||||
return form_class, base_class
|
return form_class, base_class
|
||||||
|
|
||||||
|
elif USE_QT_PY == PYQT4:
|
||||||
|
|
||||||
else:
|
|
||||||
from PyQt4 import QtGui, QtCore, uic
|
from PyQt4 import QtGui, QtCore, uic
|
||||||
try:
|
try:
|
||||||
from PyQt4 import QtSvg
|
from PyQt4 import QtSvg
|
||||||
@ -103,10 +118,59 @@ else:
|
|||||||
QtCore.Signal = QtCore.pyqtSignal
|
QtCore.Signal = QtCore.pyqtSignal
|
||||||
VERSION_INFO = 'PyQt4 ' + QtCore.PYQT_VERSION_STR + ' Qt ' + QtCore.QT_VERSION_STR
|
VERSION_INFO = 'PyQt4 ' + QtCore.PYQT_VERSION_STR + ' Qt ' + QtCore.QT_VERSION_STR
|
||||||
|
|
||||||
|
elif USE_QT_PY == PYQT5:
|
||||||
|
|
||||||
|
# We're using PyQt5 which has a different structure so we're going to use a shim to
|
||||||
|
# recreate the Qt4 structure for Qt5
|
||||||
|
from PyQt5 import QtGui, QtCore, QtWidgets, Qt, uic
|
||||||
|
try:
|
||||||
|
from PyQt5 import QtSvg
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
from PyQt5 import QtOpenGL
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Re-implement deprecated APIs
|
||||||
|
def scale(self, sx, sy):
|
||||||
|
self.setTransform(QtGui.QTransform.fromScale(sx, sy), True)
|
||||||
|
QtWidgets.QGraphicsItem.scale = scale
|
||||||
|
|
||||||
|
def rotate(self, angle):
|
||||||
|
self.setRotation(self.rotation() + angle)
|
||||||
|
QtWidgets.QGraphicsItem.rotate = rotate
|
||||||
|
|
||||||
|
def translate(self, dx, dy):
|
||||||
|
self.setTransform(QtGui.QTransform.fromTranslate(dx, dy), True)
|
||||||
|
QtWidgets.QGraphicsItem.translate = translate
|
||||||
|
|
||||||
|
def setMargin(self, i):
|
||||||
|
self.setContentsMargins(i, i, i, i)
|
||||||
|
QtWidgets.QGridLayout.setMargin = setMargin
|
||||||
|
|
||||||
|
def setResizeMode(self, mode):
|
||||||
|
self.setSectionResizeMode(mode)
|
||||||
|
QtWidgets.QHeaderView.setResizeMode = setResizeMode
|
||||||
|
|
||||||
|
|
||||||
|
QtGui.QApplication = QtWidgets.QApplication
|
||||||
|
QtGui.QGraphicsScene = QtWidgets.QGraphicsScene
|
||||||
|
QtGui.QGraphicsObject = QtWidgets.QGraphicsObject
|
||||||
|
QtGui.QGraphicsWidget = QtWidgets.QGraphicsWidget
|
||||||
|
|
||||||
|
QtGui.QApplication.setGraphicsSystem = None
|
||||||
|
QtCore.Signal = Qt.pyqtSignal
|
||||||
|
|
||||||
|
# Import all QtWidgets objects into QtGui
|
||||||
|
for o in dir(QtWidgets):
|
||||||
|
if o.startswith('Q'):
|
||||||
|
setattr(QtGui, o, getattr(QtWidgets,o) )
|
||||||
|
|
||||||
## Make sure we have Qt >= 4.7
|
## Make sure we have Qt >= 4.7
|
||||||
versionReq = [4, 7]
|
versionReq = [4, 7]
|
||||||
QtVersion = PySide.QtCore.__version__ if USE_PYSIDE else QtCore.QT_VERSION_STR
|
USE_PYSIDE = USE_QT_PY == PYSIDE # still needed internally elsewhere
|
||||||
|
QtVersion = PySide.QtCore.__version__ if USE_QT_PY == PYSIDE else QtCore.QT_VERSION_STR
|
||||||
m = re.match(r'(\d+)\.(\d+).*', QtVersion)
|
m = re.match(r'(\d+)\.(\d+).*', QtVersion)
|
||||||
if m is not None and list(map(int, m.groups())) < versionReq:
|
if m is not None and list(map(int, m.groups())) < versionReq:
|
||||||
print(list(map(int, m.groups())))
|
print(list(map(int, m.groups())))
|
||||||
|
@ -41,7 +41,8 @@ elif 'darwin' in sys.platform: ## openGL can have a major impact on mac, but als
|
|||||||
useOpenGL = False
|
useOpenGL = False
|
||||||
if QtGui.QApplication.instance() is not None:
|
if QtGui.QApplication.instance() is not None:
|
||||||
print('Warning: QApplication was created before pyqtgraph was imported; there may be problems (to avoid bugs, call QApplication.setGraphicsSystem("raster") before the QApplication is created).')
|
print('Warning: QApplication was created before pyqtgraph was imported; there may be problems (to avoid bugs, call QApplication.setGraphicsSystem("raster") before the QApplication is created).')
|
||||||
QtGui.QApplication.setGraphicsSystem('raster') ## work around a variety of bugs in the native graphics system
|
if QtGui.QApplication.setGraphicsSystem:
|
||||||
|
QtGui.QApplication.setGraphicsSystem('raster') ## work around a variety of bugs in the native graphics system
|
||||||
else:
|
else:
|
||||||
useOpenGL = False ## on windows there's a more even performance / bugginess tradeoff.
|
useOpenGL = False ## on windows there's a more even performance / bugginess tradeoff.
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#
|
#
|
||||||
# WARNING! All changes made in this file will be lost!
|
# WARNING! All changes made in this file will be lost!
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from ...Qt import QtCore, QtGui
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_fromUtf8 = QtCore.QString.fromUtf8
|
_fromUtf8 = QtCore.QString.fromUtf8
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#
|
#
|
||||||
# WARNING! All changes made in this file will be lost!
|
# WARNING! All changes made in this file will be lost!
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from ...Qt import QtCore, QtGui
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_fromUtf8 = QtCore.QString.fromUtf8
|
_fromUtf8 = QtCore.QString.fromUtf8
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#
|
#
|
||||||
# WARNING! All changes made in this file will be lost!
|
# WARNING! All changes made in this file will be lost!
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from ..Qt import QtCore, QtGui
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_fromUtf8 = QtCore.QString.fromUtf8
|
_fromUtf8 = QtCore.QString.fromUtf8
|
||||||
|
Loading…
x
Reference in New Issue
Block a user