Skip to content

Commit

Permalink
Nuke Qt4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Oct 13, 2021
1 parent 2f2a25a commit 28b7887
Show file tree
Hide file tree
Showing 30 changed files with 64 additions and 869 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/)
Expand All @@ -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
Expand All @@ -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
Expand Down
72 changes: 1 addition & 71 deletions qtpy/QtCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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')
4 changes: 1 addition & 3 deletions qtpy/QtDesigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
142 changes: 1 addition & 141 deletions qtpy/QtGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@

"""
Provides QtGui classes and functions.
.. warning:: Only PyQt4/PySide QtGui classes compatible with PyQt5.QtGui are
exposed here. Therefore, you need to treat/use this package as if it were
the ``PyQt5.QtGui`` module.
"""
import warnings

from . import PYQT6, PYQT5, PYQT4, PYSIDE, PYSIDE2, PYSIDE6, PythonQtError
from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, PythonQtError


if PYQT6:
Expand All @@ -26,142 +23,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')
6 changes: 1 addition & 5 deletions qtpy/QtHelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@

import warnings

from . import PYQT5, PYQT4, PYSIDE6, PYSIDE2, PYSIDE
from . import PYQT5, PYSIDE6, PYSIDE2

if PYQT5:
from PyQt5.QtHelp import *
elif PYSIDE6:
from PySide6.QtHelp import *
elif PYSIDE2:
from PySide2.QtHelp import *
elif PYQT4:
from PyQt4.QtHelp import *
elif PYSIDE:
from PySide.QtHelp import *
8 changes: 0 additions & 8 deletions qtpy/QtMultimedia.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import warnings

from . import PYQT5
from . import PYQT4
from . import PYSIDE
from . import PYSIDE2
from . import PYSIDE6

Expand All @@ -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
6 changes: 1 addition & 5 deletions qtpy/QtNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')
7 changes: 1 addition & 6 deletions qtpy/QtOpenGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@
"""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 *
elif PYSIDE6:
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
10 changes: 1 addition & 9 deletions qtpy/QtPrintSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')
Loading

0 comments on commit 28b7887

Please sign in to comment.