From 021edfdead6f09399a0bcc30f48e3884b23e1426 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 12 Oct 2021 17:19:28 +0200 Subject: [PATCH] Nuke Qt4 support Closes #70 --- README.md | 9 +- qtpy/QtCore.py | 72 +----------- qtpy/QtDesigner.py | 4 +- qtpy/QtGui.py | 139 +---------------------- qtpy/QtHelp.py | 6 +- qtpy/QtMultimedia.py | 8 -- qtpy/QtNetwork.py | 6 +- qtpy/QtOpenGL.py | 7 +- qtpy/QtPrintSupport.py | 10 +- qtpy/QtSql.py | 7 +- qtpy/QtSvg.py | 7 +- qtpy/QtTest.py | 11 +- qtpy/QtWebEngineWidgets.py | 12 +- qtpy/QtWidgets.py | 111 +----------------- qtpy/QtXmlPatterns.py | 6 +- qtpy/__init__.py | 67 +---------- qtpy/compat.py | 64 ++--------- qtpy/tests/test_patch_qheaderview.py | 23 +--- qtpy/tests/test_qdesktopservice_split.py | 15 --- qtpy/tests/test_qtdesigner.py | 4 +- qtpy/tests/test_qtnetwork.py | 17 ++- qtpy/tests/test_qtxmlpatterns.py | 4 +- qtpy/tests/test_uic.py | 4 +- qtpy/uic.py | 15 +-- setup.py | 2 +- 25 files changed, 50 insertions(+), 580 deletions(-) diff --git a/README.md b/README.md index 3f6e46b7..59691109 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# QtPy: Abstraction layer for PyQt5/PyQt4/PySide2/PySide +# QtPy: Abstraction layer for PyQt5/PyQt6/PySide2/PySide6 [![license](https://img.shields.io/pypi/l/qtpy.svg)](./LICENSE) [![pypi version](https://img.shields.io/pypi/v/qtpy.svg)](https://pypi.org/project/QtPy/) @@ -18,7 +18,7 @@ **QtPy** is a small abstraction layer that lets you write applications using a single API call to either PyQt or PySide. -It provides support for PyQt5, PyQt4, PySide6, PySide2 and PySide using the Qt5 layout +It provides support for PyQt5, PyQt6, PySide6, PySide2 using the Qt5 layout (where the QtGui module has been split into QtGui and QtWidgets). Basically, you can write your code as if you were using PySide2 @@ -45,17 +45,16 @@ This project is released under the MIT license. ### Requirements -You need PyQt5, PyQt4, PySide2 or PySide installed in your system to make use +You need PyQt5, PyQt6, PySide2 or PySide6 installed in your system to make use of QtPy. If several of these packages are found, PyQt5 is used by default unless you set the `QT_API` environment variable. `QT_API` can take the following values: * `pyqt5` (to use PyQt5). -* `pyqt` or `pyqt4` (to use PyQt4). +* `pyqt6` (to use PyQt6). * `pyside6` (to use PySide6) * `pyside2` (to use PySide2) -* `pyside` (to use PySide). ### Installation diff --git a/qtpy/QtCore.py b/qtpy/QtCore.py index b353a0dc..a6142bf9 100644 --- a/qtpy/QtCore.py +++ b/qtpy/QtCore.py @@ -10,7 +10,7 @@ Provides QtCore classes and functions. """ -from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, PYQT4, PYSIDE, PythonQtError +from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, PythonQtError if PYQT6: from PyQt6.QtCore import * @@ -54,75 +54,5 @@ import PySide2.QtCore __version__ = PySide2.QtCore.__version__ -elif PYQT4: - from PyQt4.QtCore import * - # Those are things we inherited from Spyder that fix crazy crashes under - # some specific situations. (See #34) - from PyQt4.QtCore import QCoreApplication - from PyQt4.QtCore import Qt - from PyQt4.QtCore import pyqtSignal as Signal - from PyQt4.QtCore import pyqtBoundSignal as SignalInstance - from PyQt4.QtCore import pyqtSlot as Slot - from PyQt4.QtCore import pyqtProperty as Property - from PyQt4.QtGui import (QItemSelection, QItemSelectionModel, - QItemSelectionRange, QSortFilterProxyModel, - QStringListModel) - from PyQt4.QtCore import QT_VERSION_STR as __version__ - from PyQt4.QtCore import qInstallMsgHandler as qInstallMessageHandler - - # QDesktopServices has has been split into (QDesktopServices and - # QStandardPaths) in Qt5 - # This creates a dummy class that emulates QStandardPaths - from PyQt4.QtGui import QDesktopServices as _QDesktopServices - - class QStandardPaths(): - StandardLocation = _QDesktopServices.StandardLocation - displayName = _QDesktopServices.displayName - DesktopLocation = _QDesktopServices.DesktopLocation - DocumentsLocation = _QDesktopServices.DocumentsLocation - FontsLocation = _QDesktopServices.FontsLocation - ApplicationsLocation = _QDesktopServices.ApplicationsLocation - MusicLocation = _QDesktopServices.MusicLocation - MoviesLocation = _QDesktopServices.MoviesLocation - PicturesLocation = _QDesktopServices.PicturesLocation - TempLocation = _QDesktopServices.TempLocation - HomeLocation = _QDesktopServices.HomeLocation - DataLocation = _QDesktopServices.DataLocation - CacheLocation = _QDesktopServices.CacheLocation - writableLocation = _QDesktopServices.storageLocation - - # Those are imported from `import *` - del pyqtSignal, pyqtBoundSignal, pyqtSlot, pyqtProperty, QT_VERSION_STR, qInstallMsgHandler -elif PYSIDE: - from PySide.QtCore import * - from PySide.QtGui import (QItemSelection, QItemSelectionModel, - QItemSelectionRange, QSortFilterProxyModel, - QStringListModel) - from PySide.QtCore import qInstallMsgHandler as qInstallMessageHandler - del qInstallMsgHandler - - # QDesktopServices has has been split into (QDesktopServices and - # QStandardPaths) in Qt5 - # This creates a dummy class that emulates QStandardPaths - from PySide.QtGui import QDesktopServices as _QDesktopServices - - class QStandardPaths(): - StandardLocation = _QDesktopServices.StandardLocation - displayName = _QDesktopServices.displayName - DesktopLocation = _QDesktopServices.DesktopLocation - DocumentsLocation = _QDesktopServices.DocumentsLocation - FontsLocation = _QDesktopServices.FontsLocation - ApplicationsLocation = _QDesktopServices.ApplicationsLocation - MusicLocation = _QDesktopServices.MusicLocation - MoviesLocation = _QDesktopServices.MoviesLocation - PicturesLocation = _QDesktopServices.PicturesLocation - TempLocation = _QDesktopServices.TempLocation - HomeLocation = _QDesktopServices.HomeLocation - DataLocation = _QDesktopServices.DataLocation - CacheLocation = _QDesktopServices.CacheLocation - writableLocation = _QDesktopServices.storageLocation - - import PySide.QtCore - __version__ = PySide.QtCore.__version__ else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtDesigner.py b/qtpy/QtDesigner.py index 4aaafc81..04576785 100644 --- a/qtpy/QtDesigner.py +++ b/qtpy/QtDesigner.py @@ -9,12 +9,10 @@ Provides QtDesigner classes and functions. """ -from . import PYQT5, PYQT4, PythonQtError +from . import PYQT5, PythonQtError if PYQT5: from PyQt5.QtDesigner import * -elif PYQT4: - from PyQt4.QtDesigner import * else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 90c074a4..e474a564 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -14,7 +14,7 @@ """ import warnings -from . import PYQT6, PYQT5, PYQT4, PYSIDE, PYSIDE2, PYSIDE6, PythonQtError +from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, PythonQtError if PYQT6: @@ -26,142 +26,5 @@ elif PYSIDE6: from PySide6.QtGui import * QFontMetrics.width = QFontMetrics.horizontalAdvance - -elif PYQT4: - try: - # Older versions of PyQt4 do not provide these - from PyQt4.QtGui import (QGlyphRun, QMatrix2x2, QMatrix2x3, - QMatrix2x4, QMatrix3x2, QMatrix3x3, - QMatrix3x4, QMatrix4x2, QMatrix4x3, - QMatrix4x4, QTouchEvent, QQuaternion, - QRadialGradient, QRawFont, QStaticText, - QVector2D, QVector3D, QVector4D, - qFuzzyCompare) - except ImportError: - pass - try: - from PyQt4.Qt import QKeySequence, QTextCursor - except ImportError: - # In PyQt4-sip 4.19.13 QKeySequence and QTextCursor are in PyQt4.QtGui - from PyQt4.QtGui import QKeySequence, QTextCursor - from PyQt4.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap, - QBrush, QClipboard, QCloseEvent, QColor, - QConicalGradient, QContextMenuEvent, QCursor, - QDoubleValidator, QDrag, - QDragEnterEvent, QDragLeaveEvent, QDragMoveEvent, - QDropEvent, QFileOpenEvent, QFocusEvent, QFont, - QFontDatabase, QFontInfo, QFontMetrics, - QFontMetricsF, QGradient, QHelpEvent, - QHideEvent, QHoverEvent, QIcon, QIconDragEvent, - QIconEngine, QImage, QImageIOHandler, QImageReader, - QImageWriter, QInputEvent, QInputMethodEvent, - QKeyEvent, QLinearGradient, - QMouseEvent, QMoveEvent, QMovie, - QPaintDevice, QPaintEngine, QPaintEngineState, - QPaintEvent, QPainter, QPainterPath, - QPainterPathStroker, QPalette, QPen, QPicture, - QPictureIO, QPixmap, QPixmapCache, QPolygon, - QPolygonF, QRegExpValidator, QRegion, QResizeEvent, - QSessionManager, QShortcutEvent, QShowEvent, - QStandardItem, QStandardItemModel, - QStatusTipEvent, QSyntaxHighlighter, QTabletEvent, - QTextBlock, QTextBlockFormat, QTextBlockGroup, - QTextBlockUserData, QTextCharFormat, - QTextDocument, QTextDocumentFragment, - QTextDocumentWriter, QTextFormat, QTextFragment, - QTextFrame, QTextFrameFormat, QTextImageFormat, - QTextInlineObject, QTextItem, QTextLayout, - QTextLength, QTextLine, QTextList, QTextListFormat, - QTextObject, QTextObjectInterface, QTextOption, - QTextTable, QTextTableCell, QTextTableCellFormat, - QTextTableFormat, QTransform, - QValidator, QWhatsThisClickedEvent, QWheelEvent, - QWindowStateChangeEvent, qAlpha, qBlue, - qGray, qGreen, qIsGray, qRed, qRgb, - qRgba, QIntValidator) - - # QDesktopServices has has been split into (QDesktopServices and - # QStandardPaths) in Qt5 - # It only exposes QDesktopServices that are still in pyqt5 - from PyQt4.QtGui import QDesktopServices as _QDesktopServices - - class QDesktopServices(): - openUrl = _QDesktopServices.openUrl - setUrlHandler = _QDesktopServices.setUrlHandler - unsetUrlHandler = _QDesktopServices.unsetUrlHandler - - def __getattr__(self, name): - attr = getattr(_QDesktopServices, name) - - new_name = name - if name == 'storageLocation': - new_name = 'writableLocation' - warnings.warn(("Warning QDesktopServices.{} is deprecated in Qt5" - "we recommend you use QDesktopServices.{} instead").format(name, new_name), - DeprecationWarning) - return attr - QDesktopServices = QDesktopServices() - -elif PYSIDE: - from PySide.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap, - QBrush, QClipboard, QCloseEvent, QColor, - QConicalGradient, QContextMenuEvent, QCursor, - QDoubleValidator, QDrag, - QDragEnterEvent, QDragLeaveEvent, QDragMoveEvent, - QDropEvent, QFileOpenEvent, QFocusEvent, QFont, - QFontDatabase, QFontInfo, QFontMetrics, - QFontMetricsF, QGradient, QHelpEvent, - QHideEvent, QHoverEvent, QIcon, QIconDragEvent, - QIconEngine, QImage, QImageIOHandler, QImageReader, - QImageWriter, QInputEvent, QInputMethodEvent, - QKeyEvent, QKeySequence, QLinearGradient, - QMatrix2x2, QMatrix2x3, QMatrix2x4, QMatrix3x2, - QMatrix3x3, QMatrix3x4, QMatrix4x2, QMatrix4x3, - QMatrix4x4, QMouseEvent, QMoveEvent, QMovie, - QPaintDevice, QPaintEngine, QPaintEngineState, - QPaintEvent, QPainter, QPainterPath, - QPainterPathStroker, QPalette, QPen, QPicture, - QPictureIO, QPixmap, QPixmapCache, QPolygon, - QPolygonF, QQuaternion, QRadialGradient, - QRegExpValidator, QRegion, QResizeEvent, - QSessionManager, QShortcutEvent, QShowEvent, - QStandardItem, QStandardItemModel, - QStatusTipEvent, QSyntaxHighlighter, QTabletEvent, - QTextBlock, QTextBlockFormat, QTextBlockGroup, - QTextBlockUserData, QTextCharFormat, QTextCursor, - QTextDocument, QTextDocumentFragment, - QTextFormat, QTextFragment, - QTextFrame, QTextFrameFormat, QTextImageFormat, - QTextInlineObject, QTextItem, QTextLayout, - QTextLength, QTextLine, QTextList, QTextListFormat, - QTextObject, QTextObjectInterface, QTextOption, - QTextTable, QTextTableCell, QTextTableCellFormat, - QTextTableFormat, QTouchEvent, QTransform, - QValidator, QVector2D, QVector3D, QVector4D, - QWhatsThisClickedEvent, QWheelEvent, - QWindowStateChangeEvent, qAlpha, qBlue, - qGray, qGreen, qIsGray, qRed, qRgb, qRgba, - QIntValidator) - # QDesktopServices has has been split into (QDesktopServices and - # QStandardPaths) in Qt5 - # It only exposes QDesktopServices that are still in pyqt5 - from PySide.QtGui import QDesktopServices as _QDesktopServices - - class QDesktopServices(): - openUrl = _QDesktopServices.openUrl - setUrlHandler = _QDesktopServices.setUrlHandler - unsetUrlHandler = _QDesktopServices.unsetUrlHandler - - def __getattr__(self, name): - attr = getattr(_QDesktopServices, name) - - new_name = name - if name == 'storageLocation': - new_name = 'writableLocation' - warnings.warn(("Warning QDesktopServices.{} is deprecated in Qt5" - "we recommend you use QDesktopServices.{} instead").format(name, new_name), - DeprecationWarning) - return attr - QDesktopServices = QDesktopServices() else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtHelp.py b/qtpy/QtHelp.py index bbd44036..de06baf7 100644 --- a/qtpy/QtHelp.py +++ b/qtpy/QtHelp.py @@ -9,7 +9,7 @@ import warnings -from . import PYQT5, PYQT4, PYSIDE6, PYSIDE2, PYSIDE +from . import PYQT5, PYSIDE6, PYSIDE2 if PYQT5: from PyQt5.QtHelp import * @@ -17,7 +17,3 @@ from PySide6.QtHelp import * elif PYSIDE2: from PySide2.QtHelp import * -elif PYQT4: - from PyQt4.QtHelp import * -elif PYSIDE: - from PySide.QtHelp import * diff --git a/qtpy/QtMultimedia.py b/qtpy/QtMultimedia.py index 96d7e906..88cbdf10 100644 --- a/qtpy/QtMultimedia.py +++ b/qtpy/QtMultimedia.py @@ -1,8 +1,6 @@ import warnings from . import PYQT5 -from . import PYQT4 -from . import PYSIDE from . import PYSIDE2 from . import PYSIDE6 @@ -12,9 +10,3 @@ from PySide6.QtMultimedia import * elif PYSIDE2: from PySide2.QtMultimedia import * -elif PYQT4: - from PyQt4.QtMultimedia import * - from PyQt4.QtGui import QSound -elif PYSIDE: - from PySide.QtMultimedia import * - from PySide.QtGui import QSound diff --git a/qtpy/QtNetwork.py b/qtpy/QtNetwork.py index d8b6aa87..c1fcd588 100644 --- a/qtpy/QtNetwork.py +++ b/qtpy/QtNetwork.py @@ -10,7 +10,7 @@ Provides QtNetwork classes and functions. """ -from . import PYQT5, PYSIDE2, PYSIDE6, PYQT4, PYSIDE, PythonQtError +from . import PYQT5, PYSIDE2, PYSIDE6, PythonQtError if PYQT5: @@ -19,9 +19,5 @@ from PySide6.QtNetwork import * elif PYSIDE2: from PySide2.QtNetwork import * -elif PYQT4: - from PyQt4.QtNetwork import * -elif PYSIDE: - from PySide.QtNetwork import * else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtOpenGL.py b/qtpy/QtOpenGL.py index 5b3a80d7..aaa8cd2b 100644 --- a/qtpy/QtOpenGL.py +++ b/qtpy/QtOpenGL.py @@ -8,7 +8,7 @@ """Provides QtOpenGL classes and functions.""" # Local imports -from . import PYQT4, PYQT5, PYSIDE, PYSIDE2, PythonQtError +from . import PYQT5, PYSIDE2, PythonQtError if PYQT5: from PyQt5.QtOpenGL import * @@ -16,11 +16,6 @@ from PySide6.QtOpenGL import * elif PYSIDE2: from PySide2.QtOpenGL import * -elif PYQT4: - from PyQt4.QtOpenGL import * -elif PYSIDE: - from PySide.QtOpenGL import * else: raise PythonQtError('No Qt bindings could be found') -del PYQT4, PYQT5, PYSIDE, PYSIDE2 diff --git a/qtpy/QtPrintSupport.py b/qtpy/QtPrintSupport.py index d7f4ff10..872d8179 100644 --- a/qtpy/QtPrintSupport.py +++ b/qtpy/QtPrintSupport.py @@ -9,7 +9,7 @@ Provides QtPrintSupport classes and functions. """ -from . import PYQT5, PYQT4, PYSIDE6, PYSIDE2, PYSIDE, PythonQtError +from . import PYQT5, PYSIDE6, PYSIDE2, PythonQtError if PYQT5: @@ -18,13 +18,5 @@ from PySide6.QtPrintSupport import * elif PYSIDE2: from PySide2.QtPrintSupport import * -elif PYQT4: - from PyQt4.QtGui import (QAbstractPrintDialog, QPageSetupDialog, - QPrintDialog, QPrintEngine, QPrintPreviewDialog, - QPrintPreviewWidget, QPrinter, QPrinterInfo) -elif PYSIDE: - from PySide.QtGui import (QAbstractPrintDialog, QPageSetupDialog, - QPrintDialog, QPrintEngine, QPrintPreviewDialog, - QPrintPreviewWidget, QPrinter, QPrinterInfo) else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtSql.py b/qtpy/QtSql.py index 583e5cb0..0c8dcb3b 100644 --- a/qtpy/QtSql.py +++ b/qtpy/QtSql.py @@ -8,7 +8,7 @@ """Provides QtSql classes and functions.""" # Local imports -from . import PYQT5, PYSIDE6, PYSIDE2, PYQT4, PYSIDE, PythonQtError +from . import PYQT5, PYSIDE6, PYSIDE2, PythonQtError if PYQT5: from PyQt5.QtSql import * @@ -16,11 +16,6 @@ from PySide6.QtSql import * elif PYSIDE2: from PySide2.QtSql import * -elif PYQT4: - from PyQt4.QtSql import * -elif PYSIDE: - from PySide.QtSql import * else: raise PythonQtError('No Qt bindings could be found') -del PYQT4, PYQT5, PYSIDE, PYSIDE2 diff --git a/qtpy/QtSvg.py b/qtpy/QtSvg.py index ccc3fbd3..cb99e12c 100644 --- a/qtpy/QtSvg.py +++ b/qtpy/QtSvg.py @@ -8,7 +8,7 @@ """Provides QtSvg classes and functions.""" # Local imports -from . import PYQT4, PYSIDE6, PYSIDE2, PYQT5, PYQT6, PYSIDE, PythonQtError +from . import PYSIDE6, PYSIDE2, PYQT5, PYQT6, PythonQtError if PYQT6: from PyQt6.QtSvg import * @@ -18,11 +18,6 @@ from PySide6.QtSvg import * elif PYSIDE2: from PySide2.QtSvg import * -elif PYQT4: - from PyQt4.QtSvg import * -elif PYSIDE: - from PySide.QtSvg import * else: raise PythonQtError('No Qt bindings could be found') -del PYQT4, PYQT5, PYSIDE, PYSIDE2 diff --git a/qtpy/QtTest.py b/qtpy/QtTest.py index b86c174e..83ecb694 100644 --- a/qtpy/QtTest.py +++ b/qtpy/QtTest.py @@ -10,7 +10,7 @@ Provides QtTest and functions """ -from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, PYQT4, PYSIDE, PythonQtError +from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, PythonQtError if PYQT6: from PyQt6.QtTest import QTest @@ -20,14 +20,5 @@ from PySide6.QtTest import QTest elif PYSIDE2: from PySide2.QtTest import QTest -elif PYQT4: - from PyQt4.QtTest import QTest as OldQTest - - class QTest(OldQTest): - @staticmethod - def qWaitForWindowActive(QWidget): - OldQTest.qWaitForWindowShown(QWidget) -elif PYSIDE: - from PySide.QtTest import QTest else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtWebEngineWidgets.py b/qtpy/QtWebEngineWidgets.py index 20de297b..3b41b09a 100644 --- a/qtpy/QtWebEngineWidgets.py +++ b/qtpy/QtWebEngineWidgets.py @@ -10,7 +10,7 @@ Provides QtWebEngineWidgets classes and functions. """ -from . import PYQT5,PYSIDE2, PYSIDE6, PYQT4, PYSIDE, PythonQtError +from . import PYQT5, PYSIDE2, PYSIDE6, PythonQtError # To test if we are using WebEngine or WebKit @@ -40,15 +40,5 @@ from PySide2.QtWebEngineWidgets import QWebEngineSettings # Based on the work at https://github.com/spyder-ide/qtpy/pull/203 from PySide2.QtWebEngineWidgets import QWebEngineProfile -elif PYQT4: - from PyQt4.QtWebKit import QWebPage as QWebEnginePage - from PyQt4.QtWebKit import QWebView as QWebEngineView - from PyQt4.QtWebKit import QWebSettings as QWebEngineSettings - WEBENGINE = False -elif PYSIDE: - from PySide.QtWebKit import QWebPage as QWebEnginePage - from PySide.QtWebKit import QWebView as QWebEngineView - from PySide.QtWebKit import QWebSettings as QWebEngineSettings - WEBENGINE = False else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtWidgets.py b/qtpy/QtWidgets.py index 0dbb4a76..730aee94 100644 --- a/qtpy/QtWidgets.py +++ b/qtpy/QtWidgets.py @@ -13,7 +13,7 @@ were the ``PyQt5.QtWidgets`` module. """ -from . import PYQT5, PYQT6, PYSIDE2, PYQT4, PYSIDE, PYSIDE6, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError from ._patch.qcombobox import patch_qcombobox from ._patch.qheaderview import introduce_renamed_methods_qheaderview @@ -32,114 +32,5 @@ QPlainTextEdit.tabStopWidth = QPlainTextEdit.tabStopDistance elif PYSIDE2: from PySide2.QtWidgets import * -elif PYQT4: - from PyQt4.QtGui import * - QStyleOptionViewItem = QStyleOptionViewItemV4 - del QStyleOptionViewItemV4 - QStyleOptionFrame = QStyleOptionFrameV3 - del QStyleOptionFrameV3 - - # These objects belong to QtGui - try: - # Older versions of PyQt4 do not provide these - del (QGlyphRun, - QMatrix2x2, QMatrix2x3, QMatrix2x4, QMatrix3x2, QMatrix3x3, - QMatrix3x4, QMatrix4x2, QMatrix4x3, QMatrix4x4, - QQuaternion, QRadialGradient, QRawFont, QRegExpValidator, - QStaticText, QTouchEvent, QVector2D, QVector3D, QVector4D, - qFuzzyCompare) - except NameError: - pass - del (QAbstractTextDocumentLayout, QActionEvent, QBitmap, QBrush, QClipboard, - QCloseEvent, QColor, QConicalGradient, QContextMenuEvent, QCursor, - QDesktopServices, QDoubleValidator, QDrag, QDragEnterEvent, - QDragLeaveEvent, QDragMoveEvent, QDropEvent, QFileOpenEvent, - QFocusEvent, QFont, QFontDatabase, QFontInfo, QFontMetrics, - QFontMetricsF, QGradient, QHelpEvent, QHideEvent, - QHoverEvent, QIcon, QIconDragEvent, QIconEngine, QImage, - QImageIOHandler, QImageReader, QImageWriter, QInputEvent, - QInputMethodEvent, QKeyEvent, QKeySequence, QLinearGradient, - QMouseEvent, QMoveEvent, QMovie, QPaintDevice, QPaintEngine, - QPaintEngineState, QPaintEvent, QPainter, QPainterPath, - QPainterPathStroker, QPalette, QPen, QPicture, QPictureIO, QPixmap, - QPixmapCache, QPolygon, QPolygonF, - QRegion, QResizeEvent, QSessionManager, QShortcutEvent, QShowEvent, - QStandardItem, QStandardItemModel, QStatusTipEvent, - QSyntaxHighlighter, QTabletEvent, QTextBlock, QTextBlockFormat, - QTextBlockGroup, QTextBlockUserData, QTextCharFormat, QTextCursor, - QTextDocument, QTextDocumentFragment, QTextDocumentWriter, - QTextFormat, QTextFragment, QTextFrame, QTextFrameFormat, - QTextImageFormat, QTextInlineObject, QTextItem, QTextLayout, - QTextLength, QTextLine, QTextList, QTextListFormat, QTextObject, - QTextObjectInterface, QTextOption, QTextTable, QTextTableCell, - QTextTableCellFormat, QTextTableFormat, QTransform, - QValidator, QWhatsThisClickedEvent, - QWheelEvent, QWindowStateChangeEvent, qAlpha, qBlue, - qGray, qGreen, qIsGray, qRed, qRgb, qRgba, QIntValidator, - QStringListModel) - - # These objects belong to QtPrintSupport - del (QAbstractPrintDialog, QPageSetupDialog, QPrintDialog, QPrintEngine, - QPrintPreviewDialog, QPrintPreviewWidget, QPrinter, QPrinterInfo) - - # These objects belong to QtCore - del (QItemSelection, QItemSelectionModel, QItemSelectionRange, - QSortFilterProxyModel) - - # Patch QComboBox to allow Python objects to be passed to userData - patch_qcombobox(QComboBox) - - # QHeaderView: renamed methods - introduce_renamed_methods_qheaderview(QHeaderView) - -elif PYSIDE: - from PySide.QtGui import * - QStyleOptionViewItem = QStyleOptionViewItemV4 - del QStyleOptionViewItemV4 - - # These objects belong to QtGui - del (QAbstractTextDocumentLayout, QActionEvent, QBitmap, QBrush, QClipboard, - QCloseEvent, QColor, QConicalGradient, QContextMenuEvent, QCursor, - QDesktopServices, QDoubleValidator, QDrag, QDragEnterEvent, - QDragLeaveEvent, QDragMoveEvent, QDropEvent, QFileOpenEvent, - QFocusEvent, QFont, QFontDatabase, QFontInfo, QFontMetrics, - QFontMetricsF, QGradient, QHelpEvent, QHideEvent, - QHoverEvent, QIcon, QIconDragEvent, QIconEngine, QImage, - QImageIOHandler, QImageReader, QImageWriter, QInputEvent, - QInputMethodEvent, QKeyEvent, QKeySequence, QLinearGradient, - QMatrix2x2, QMatrix2x3, QMatrix2x4, QMatrix3x2, QMatrix3x3, - QMatrix3x4, QMatrix4x2, QMatrix4x3, QMatrix4x4, QMouseEvent, - QMoveEvent, QMovie, QPaintDevice, QPaintEngine, QPaintEngineState, - QPaintEvent, QPainter, QPainterPath, QPainterPathStroker, QPalette, - QPen, QPicture, QPictureIO, QPixmap, QPixmapCache, QPolygon, - QPolygonF, QQuaternion, QRadialGradient, QRegExpValidator, - QRegion, QResizeEvent, QSessionManager, QShortcutEvent, QShowEvent, - QStandardItem, QStandardItemModel, QStatusTipEvent, - QSyntaxHighlighter, QTabletEvent, QTextBlock, QTextBlockFormat, - QTextBlockGroup, QTextBlockUserData, QTextCharFormat, QTextCursor, - QTextDocument, QTextDocumentFragment, - QTextFormat, QTextFragment, QTextFrame, QTextFrameFormat, - QTextImageFormat, QTextInlineObject, QTextItem, QTextLayout, - QTextLength, QTextLine, QTextList, QTextListFormat, QTextObject, - QTextObjectInterface, QTextOption, QTextTable, QTextTableCell, - QTextTableCellFormat, QTextTableFormat, QTouchEvent, QTransform, - QValidator, QVector2D, QVector3D, QVector4D, QWhatsThisClickedEvent, - QWheelEvent, QWindowStateChangeEvent, qAlpha, qBlue, qGray, qGreen, - qIsGray, qRed, qRgb, qRgba, QIntValidator, QStringListModel) - - # These objects belong to QtPrintSupport - del (QAbstractPrintDialog, QPageSetupDialog, QPrintDialog, QPrintEngine, - QPrintPreviewDialog, QPrintPreviewWidget, QPrinter, QPrinterInfo) - - # These objects belong to QtCore - del (QItemSelection, QItemSelectionModel, QItemSelectionRange, - QSortFilterProxyModel) - - # Patch QComboBox to allow Python objects to be passed to userData - patch_qcombobox(QComboBox) - - # QHeaderView: renamed methods - introduce_renamed_methods_qheaderview(QHeaderView) - else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtXmlPatterns.py b/qtpy/QtXmlPatterns.py index b41e13df..3ab2661e 100644 --- a/qtpy/QtXmlPatterns.py +++ b/qtpy/QtXmlPatterns.py @@ -8,15 +8,11 @@ """Provides QtXmlPatterns classes and functions.""" # Local imports -from . import PYQT4, PYSIDE2, PYQT5, PYSIDE, PythonQtError +from . import PYSIDE2, PYQT5, PythonQtError if PYQT5: from PyQt5.QtXmlPatterns import * elif PYSIDE2: from PySide2.QtXmlPatterns import * -elif PYQT4: - from PyQt4.QtXmlPatterns import * -elif PYSIDE: - from PySide.QtXmlPatterns import * else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/__init__.py b/qtpy/__init__.py index ab0e9e51..9115b03e 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -106,15 +106,6 @@ class PythonQtWarning(Warning): PYQT6_API = ['pyqt6'] -# Names of the expected PyQt4 api -PYQT4_API = [ - 'pyqt', # name used in IPython.qt - 'pyqt4' # pyqode.qt original name -] - -# Names of the expected PySide api -PYSIDE_API = ['pyside'] - # Names of the expected PySide2 api PYSIDE2_API = ['pyside2'] @@ -129,11 +120,11 @@ class PythonQtWarning(Warning): API = os.environ[QT_API].lower() initial_api = API -assert API in (PYQT5_API + PYQT6_API + PYQT4_API + PYSIDE_API + PYSIDE2_API + PYSIDE6_API) +assert API in (PYQT5_API + PYQT6_API + PYSIDE2_API + PYSIDE6_API) is_old_pyqt = is_pyqt46 = False PYQT5 = True -PYQT4 = PYQT6 = PYSIDE = PYSIDE2 = PYSIDE6 = False +PYQT6 = PYSIDE2 = PYSIDE6 = False # When `FORCE_QT_API` is set, we disregard # any previously imported python bindings. @@ -146,11 +137,6 @@ class PythonQtWarning(Warning): API = initial_api if initial_api in PYSIDE6_API else 'pyside6' elif 'PySide2' in sys.modules: API = initial_api if initial_api in PYSIDE2_API else 'pyside2' - elif 'PyQt4' in sys.modules: - API = initial_api if initial_api in PYQT4_API else 'pyqt4' - elif 'PySide' in sys.modules: - API = initial_api if initial_api in PYSIDE_API else 'pyside' - if API in PYQT5_API: try: @@ -223,46 +209,6 @@ class PythonQtWarning(Warning): API = os.environ['QT_API'] = 'pyqt' -if API in PYQT4_API: - try: - import sip - try: - sip.setapi('QString', 2) - sip.setapi('QVariant', 2) - sip.setapi('QDate', 2) - sip.setapi('QDateTime', 2) - sip.setapi('QTextStream', 2) - sip.setapi('QTime', 2) - sip.setapi('QUrl', 2) - except (AttributeError, ValueError): - # PyQt < v4.6 - pass - try: - from PyQt4.Qt import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore - from PyQt4.Qt import QT_VERSION_STR as QT_VERSION # analysis:ignore - except ImportError: - # In PyQt4-sip 4.19.13 PYQT_VERSION_STR and QT_VERSION_STR are in PyQt4.QtCore - from PyQt4.QtCore import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore - from PyQt4.QtCore import QT_VERSION_STR as QT_VERSION # analysis:ignore - PYSIDE_VERSION = None - PYQT5 = False - PYQT4 = True - except ImportError: - API = os.environ['QT_API'] = 'pyside' - else: - is_old_pyqt = PYQT_VERSION.startswith(('4.4', '4.5', '4.6', '4.7')) - is_pyqt46 = PYQT_VERSION.startswith('4.6') - -if API in PYSIDE_API: - try: - from PySide import __version__ as PYSIDE_VERSION # analysis:ignore - from PySide.QtCore import __version__ as QT_VERSION # analysis:ignore - PYQT_VERSION = None - PYQT5 = PYSIDE2 = PYSIDE6 = False - PYSIDE = True - except ImportError: - raise PythonQtError('No Qt bindings could be found') - # If a correct API name is passed to QT_API and it could not be found, # switches to another and informs through the warning if API != initial_api and binding_specified: @@ -272,16 +218,9 @@ class PythonQtWarning(Warning): API_NAME = {'pyqt6': 'PyQt6', 'pyqt5': 'PyQt5', 'pyqt': 'PyQt4', 'pyqt4': 'PyQt4', 'pyside': 'PySide', 'pyside2':'PySide2', 'pyside6': 'PySide6'}[API] -if PYQT4: - import sip - try: - API_NAME += (" (API v{0})".format(sip.getapi('QString'))) - except AttributeError: - pass - try: # QtDataVisualization backward compatibility (QtDataVisualization vs. QtDatavisualization) # Only available for Qt5 bindings > 5.9 on Windows from . import QtDataVisualization as QtDatavisualization except ImportError: - pass \ No newline at end of file + pass diff --git a/qtpy/compat.py b/qtpy/compat.py index 949d8854..d90ed52b 100644 --- a/qtpy/compat.py +++ b/qtpy/compat.py @@ -10,7 +10,6 @@ from __future__ import print_function import sys -from . import PYQT4 from .QtWidgets import QFileDialog from .py3compat import Callable, is_text_string, to_text_string, TEXT_TYPES @@ -19,58 +18,17 @@ # QVariant conversion utilities # ============================================================================= PYQT_API_1 = False -if PYQT4: - import sip - try: - PYQT_API_1 = sip.getapi('QVariant') == 1 # PyQt API #1 - except AttributeError: - # PyQt