From 5d55f3facfa75f44a7490f2de55bb137cff4a029 Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Sat, 26 Jun 2021 07:54:03 +0800 Subject: [PATCH] remove imports subdir --- pyqtgraph/Qt/{imports => }/QtCore/__init__.py | 0 pyqtgraph/Qt/{imports => }/QtGui/__init__.py | 0 .../Qt/{imports => }/QtWidgets/__init__.py | 0 pyqtgraph/Qt/__init__.py | 62 +++++++++++-------- pyqtgraph/Qt/imports/__init__.py | 0 5 files changed, 35 insertions(+), 27 deletions(-) rename pyqtgraph/Qt/{imports => }/QtCore/__init__.py (100%) rename pyqtgraph/Qt/{imports => }/QtGui/__init__.py (100%) rename pyqtgraph/Qt/{imports => }/QtWidgets/__init__.py (100%) delete mode 100644 pyqtgraph/Qt/imports/__init__.py diff --git a/pyqtgraph/Qt/imports/QtCore/__init__.py b/pyqtgraph/Qt/QtCore/__init__.py similarity index 100% rename from pyqtgraph/Qt/imports/QtCore/__init__.py rename to pyqtgraph/Qt/QtCore/__init__.py diff --git a/pyqtgraph/Qt/imports/QtGui/__init__.py b/pyqtgraph/Qt/QtGui/__init__.py similarity index 100% rename from pyqtgraph/Qt/imports/QtGui/__init__.py rename to pyqtgraph/Qt/QtGui/__init__.py diff --git a/pyqtgraph/Qt/imports/QtWidgets/__init__.py b/pyqtgraph/Qt/QtWidgets/__init__.py similarity index 100% rename from pyqtgraph/Qt/imports/QtWidgets/__init__.py rename to pyqtgraph/Qt/QtWidgets/__init__.py diff --git a/pyqtgraph/Qt/__init__.py b/pyqtgraph/Qt/__init__.py index c2b11a90..9c825785 100644 --- a/pyqtgraph/Qt/__init__.py +++ b/pyqtgraph/Qt/__init__.py @@ -130,11 +130,30 @@ def _loadUiType(uiFile): return form_class, base_class +# For historical reasons, pyqtgraph maintains a Qt4-ish interface back when +# there wasn't a QtWidgets module. This _was_ done by monkey-patching all of +# QtWidgets into the QtGui module. This monkey-patching modifies QtGui at a +# global level. +# To avoid this, we now maintain a local "mirror" of QtCore, QtGui and QtWidgets. +# Thus, when monkey-patching happens later on in this file, they will only affect +# the local modules and not the global modules. +def _copy_attrs(src, dst): + for o in dir(src): + if not hasattr(dst, o): + setattr(dst, o, getattr(src, o)) + +from . import QtCore, QtGui, QtWidgets + if QT_LIB == 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, sip, uic - + import PyQt5.QtCore, PyQt5.QtGui, PyQt5.QtWidgets + _copy_attrs(PyQt5.QtCore, QtCore) + _copy_attrs(PyQt5.QtGui, QtGui) + _copy_attrs(PyQt5.QtWidgets, QtWidgets) + + from PyQt5 import sip, uic + try: from PyQt5 import QtSvg except ImportError as err: @@ -147,7 +166,12 @@ if QT_LIB == PYQT5: VERSION_INFO = 'PyQt5 ' + QtCore.PYQT_VERSION_STR + ' Qt ' + QtCore.QT_VERSION_STR elif QT_LIB == PYQT6: - from PyQt6 import QtGui, QtCore, QtWidgets, sip, uic + import PyQt6.QtCore, PyQt6.QtGui, PyQt6.QtWidgets + _copy_attrs(PyQt6.QtCore, QtCore) + _copy_attrs(PyQt6.QtGui, QtGui) + _copy_attrs(PyQt6.QtWidgets, QtWidgets) + + from PyQt6 import sip, uic try: from PyQt6 import QtSvg @@ -165,7 +189,10 @@ elif QT_LIB == PYQT6: VERSION_INFO = 'PyQt6 ' + QtCore.PYQT_VERSION_STR + ' Qt ' + QtCore.QT_VERSION_STR elif QT_LIB == PYSIDE2: - from PySide2 import QtGui, QtCore, QtWidgets + import PySide2.QtCore, PySide2.QtGui, PySide2.QtWidgets + _copy_attrs(PySide2.QtCore, QtCore) + _copy_attrs(PySide2.QtGui, QtGui) + _copy_attrs(PySide2.QtWidgets, QtWidgets) try: from PySide2 import QtSvg @@ -182,7 +209,10 @@ elif QT_LIB == PYSIDE2: VERSION_INFO = 'PySide2 ' + PySide2.__version__ + ' Qt ' + QtCore.__version__ elif QT_LIB == PYSIDE6: - from PySide6 import QtGui, QtCore, QtWidgets + import PySide6.QtCore, PySide6.QtGui, PySide6.QtWidgets + _copy_attrs(PySide6.QtCore, QtCore) + _copy_attrs(PySide6.QtGui, QtGui) + _copy_attrs(PySide6.QtWidgets, QtWidgets) try: from PySide6 import QtSvg @@ -206,28 +236,6 @@ else: raise ValueError("Invalid Qt lib '%s'" % QT_LIB) -# For historical reasons, pyqtgraph maintains a Qt4-ish interface back when -# there wasn't a QtWidgets module. This _was_ done by monkey-patching all of -# QtWidgets into the QtGui module. The next section of code mirrors the -# various symbols from QtCore, QtGui and QtWidgets into the corresponding local -# ones. -# Thus, when monkey-patching happens later on in this file, they will only affect -# the local modules and not the global modules. -def _copy_attrs(dst, src): - for o in dir(src): - if not hasattr(dst, o): - setattr(dst, o, getattr(src, o)) - return dst - -from .imports import QtCore as tmp -QtCore = _copy_attrs(tmp, QtCore) -from .imports import QtGui as tmp -QtGui = _copy_attrs(tmp, QtGui) -from .imports import QtWidgets as tmp -QtWidgets = _copy_attrs(tmp, QtWidgets) -del tmp - - # common to PyQt5, PyQt6, PySide2 and PySide6 if QT_LIB in [PYQT5, PYQT6, PYSIDE2, PYSIDE6]: # We're using Qt5 which has a different structure so we're going to use a shim to diff --git a/pyqtgraph/Qt/imports/__init__.py b/pyqtgraph/Qt/imports/__init__.py deleted file mode 100644 index e69de29b..00000000