diff --git a/qtpy/Qt3DAnimation.py b/qtpy/Qt3DAnimation.py index 9923d2eb..b51acfc6 100644 --- a/qtpy/Qt3DAnimation.py +++ b/qtpy/Qt3DAnimation.py @@ -4,18 +4,45 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides Qt3DAnimation classes and functions.""" -# Local imports -from . import PYQT5, PYSIDE2, PythonQtError, PYSIDE_VERSION +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, +) if PYQT5: - from PyQt5.Qt3DAnimation import * + try: + from PyQt5.Qt3DAnimation import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DAnimation', missing_package='PyQt3D' + ) from error +elif PYQT6: + try: + from PyQt6.Qt3DAnimation import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DAnimation', missing_package='PyQt6-3D' + ) from error elif PYSIDE2: # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 import PySide2.Qt3DAnimation as __temp import inspect + + for __name in inspect.getmembers(__temp.Qt3DAnimation): + globals()[__name[0]] = __name[1] +elif PYSIDE6: + # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 + import PySide6.Qt3DAnimation as __temp + import inspect + for __name in inspect.getmembers(__temp.Qt3DAnimation): globals()[__name[0]] = __name[1] else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/Qt3DCore.py b/qtpy/Qt3DCore.py index 57f1ef1c..e0b3f83f 100644 --- a/qtpy/Qt3DCore.py +++ b/qtpy/Qt3DCore.py @@ -4,22 +4,45 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides Qt3DCore classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, +) if PYQT5: - from PyQt5.Qt3DCore import * + try: + from PyQt5.Qt3DCore import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DCore', missing_package='PyQt3D' + ) from error elif PYQT6: - from PyQt6.Qt3DCore import * -elif PYSIDE6: - from PySide6.Qt3DCore.Qt3DCore import * + try: + from PyQt6.Qt3DCore import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DCore', missing_package='PyQt6-3D' + ) from error elif PYSIDE2: # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 import PySide2.Qt3DCore as __temp import inspect + + for __name in inspect.getmembers(__temp.Qt3DCore): + globals()[__name[0]] = __name[1] +elif PYSIDE6: + # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 + import PySide6.Qt3DCore as __temp + import inspect + for __name in inspect.getmembers(__temp.Qt3DCore): globals()[__name[0]] = __name[1] else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/Qt3DExtras.py b/qtpy/Qt3DExtras.py index 4397caa1..5bf610b2 100644 --- a/qtpy/Qt3DExtras.py +++ b/qtpy/Qt3DExtras.py @@ -4,22 +4,45 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides Qt3DExtras classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, +) if PYQT5: - from PyQt5.Qt3DExtras import * + try: + from PyQt5.Qt3DExtras import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DExtras', missing_package='PyQt3D' + ) from error elif PYQT6: - from PyQt6.Qt3DExtras import * -elif PYSIDE6: - from PySide6.Qt3DExtras.Qt3DExtras import * + try: + from PyQt6.Qt3DExtras import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DExtras', missing_package='PyQt6-3D' + ) from error elif PYSIDE2: # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 import PySide2.Qt3DExtras as __temp import inspect + + for __name in inspect.getmembers(__temp.Qt3DExtras): + globals()[__name[0]] = __name[1] +elif PYSIDE6: + # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 + import PySide6.Qt3DExtras as __temp + import inspect + for __name in inspect.getmembers(__temp.Qt3DExtras): globals()[__name[0]] = __name[1] else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/Qt3DInput.py b/qtpy/Qt3DInput.py index 45ebf2ac..73471ed2 100644 --- a/qtpy/Qt3DInput.py +++ b/qtpy/Qt3DInput.py @@ -4,22 +4,45 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides Qt3DInput classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, +) if PYQT5: - from PyQt5.Qt3DInput import * + try: + from PyQt5.Qt3DInput import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DInput', missing_package='PyQt3D' + ) from error elif PYQT6: - from PyQt6.Qt3DInput import * -elif PYSIDE6: - from PySide6.Qt3DInput.Qt3DInput import * + try: + from PyQt6.Qt3DInput import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DInput', missing_package='PyQt6-3D' + ) from error elif PYSIDE2: # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 import PySide2.Qt3DInput as __temp import inspect + + for __name in inspect.getmembers(__temp.Qt3DInput): + globals()[__name[0]] = __name[1] +elif PYSIDE6: + # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 + import PySide6.Qt3DInput as __temp + import inspect + for __name in inspect.getmembers(__temp.Qt3DInput): globals()[__name[0]] = __name[1] else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/Qt3DLogic.py b/qtpy/Qt3DLogic.py index 2a71d0af..12a8b7c1 100644 --- a/qtpy/Qt3DLogic.py +++ b/qtpy/Qt3DLogic.py @@ -4,22 +4,45 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides Qt3DLogic classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, +) if PYQT5: - from PyQt5.Qt3DLogic import * + try: + from PyQt5.Qt3DLogic import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DLogic', missing_package='PyQt3D' + ) from error elif PYQT6: - from PyQt6.Qt3DLogic import * -elif PYSIDE6: - from PySide6.Qt3DLogic.Qt3DLogic import * + try: + from PyQt6.Qt3DLogic import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DLogic', missing_package='PyQt6-3D' + ) from error elif PYSIDE2: # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 import PySide2.Qt3DLogic as __temp import inspect + + for __name in inspect.getmembers(__temp.Qt3DLogic): + globals()[__name[0]] = __name[1] +elif PYSIDE6: + # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 + import PySide6.Qt3DLogic as __temp + import inspect + for __name in inspect.getmembers(__temp.Qt3DLogic): globals()[__name[0]] = __name[1] else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/Qt3DRender.py b/qtpy/Qt3DRender.py index 4e9ada31..1a783eae 100644 --- a/qtpy/Qt3DRender.py +++ b/qtpy/Qt3DRender.py @@ -4,22 +4,45 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides Qt3DRender classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, +) if PYQT5: - from PyQt5.Qt3DRender import * -elif PYSIDE6: - from PySide6.Qt3DRender.Qt3DRender import * + try: + from PyQt5.Qt3DRender import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DRender', missing_package='PyQt3D' + ) from error elif PYQT6: - from PyQt6.Qt3DRender import * + try: + from PyQt6.Qt3DRender import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='Qt3DRender', missing_package='PyQt6-3D' + ) from error elif PYSIDE2: # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 import PySide2.Qt3DRender as __temp import inspect + + for __name in inspect.getmembers(__temp.Qt3DRender): + globals()[__name[0]] = __name[1] +elif PYSIDE6: + # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 + import PySide6.Qt3DRender as __temp + import inspect + for __name in inspect.getmembers(__temp.Qt3DRender): globals()[__name[0]] = __name[1] else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtAxContainer.py b/qtpy/QtAxContainer.py new file mode 100644 index 00000000..3ad07148 --- /dev/null +++ b/qtpy/QtAxContainer.py @@ -0,0 +1,28 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtAxContainer classes and functions.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: + raise QtBindingMissingModuleError(name='QtAxContainer') +elif PYQT6: + raise QtBindingMissingModuleError(name='QtAxContainer') +elif PYSIDE2: + from PySide2.QtAxContainer import * +elif PYSIDE6: + from PySide6.QtAxContainer import * +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/QtBluetooth.py b/qtpy/QtBluetooth.py new file mode 100644 index 00000000..3bbcc93a --- /dev/null +++ b/qtpy/QtBluetooth.py @@ -0,0 +1,28 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtBluetooth classes and functions.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: + from PyQt5.QtBluetooth import * +elif PYQT6: + from PyQt6.QtBluetooth import * +elif PYSIDE2: + raise QtBindingMissingModuleError(name='QtBluetooth') +elif PYSIDE6: + from PySide6.QtBluetooth import * +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/QtCharts.py b/qtpy/QtCharts.py index 164be471..21f84de9 100644 --- a/qtpy/QtCharts.py +++ b/qtpy/QtCharts.py @@ -4,38 +4,45 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtChart classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, +) if PYQT5: try: from PyQt5.QtChart import * from PyQt5 import QtChart as QtCharts - except ImportError as error: - raise PythonQtError( - 'The QtChart module was not found. ' - 'It needs to be installed separately for PyQt5.' - ) from error + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtCharts', missing_package='PyQtChart' + ) from error elif PYQT6: try: from PyQt6.QtCharts import * from PyQt6 import QtCharts - except ImportError as error: - raise PythonQtError( - 'The QtCharts module was not found. ' - 'It needs to be installed separately for PyQt6.' - ) from error -elif PYSIDE6: - from PySide6.QtCharts import * - from PySide6 import QtCharts + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtCharts', missing_package='PyQt6-Charts' + ) from error elif PYSIDE2: from PySide2.QtCharts import * + # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 import PySide2.QtCharts as __temp import inspect + for __name in inspect.getmembers(__temp.QtCharts): globals()[__name[0]] = __name[1] +elif PYSIDE6: + from PySide6.QtCharts import * + from PySide6 import QtCharts else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtConcurrent.py b/qtpy/QtConcurrent.py new file mode 100644 index 00000000..d849d4c2 --- /dev/null +++ b/qtpy/QtConcurrent.py @@ -0,0 +1,28 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtConcurrent classes and functions.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: + raise QtBindingMissingModuleError(name='QtConcurrent') +elif PYQT6: + raise QtBindingMissingModuleError(name='QtConcurrent') +elif PYSIDE2: + from PySide2.QtConcurrent import * +elif PYSIDE6: + from PySide6.QtConcurrent import * +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/QtCore.py b/qtpy/QtCore.py index 3b36d7a0..3ae098ae 100644 --- a/qtpy/QtCore.py +++ b/qtpy/QtCore.py @@ -1,17 +1,34 @@ -# +# ----------------------------------------------------------------------------- # Copyright © 2014-2015 Colin Duquesnoy # Copyright © 2009- The Spyder Development Team # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtCore classes and functions.""" + +from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, QtBindingsNotFoundError -""" -Provides QtCore classes and functions. -""" -from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, PythonQtError +if PYQT5: + from PyQt5.QtCore import * + from PyQt5.QtCore import pyqtSignal as Signal + from PyQt5.QtCore import pyqtBoundSignal as SignalInstance + from PyQt5.QtCore import pyqtSlot as Slot + from PyQt5.QtCore import pyqtProperty as Property + from PyQt5.QtCore import QT_VERSION_STR as __version__ + # For issue #153 and updated for issue #305 + from PyQt5.QtCore import QDateTime + QDateTime.toPython = lambda self, *args, **kwargs: self.toPyDateTime(*args, **kwargs) + + # Map missing methods on PyQt5 5.12 + QTextStreamManipulator.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + + # Those are imported from `import *` + del pyqtSignal, pyqtBoundSignal, pyqtSlot, pyqtProperty, QT_VERSION_STR -if PYQT6: +elif PYQT6: from PyQt6 import QtCore from PyQt6.QtCore import * from PyQt6.QtCore import pyqtSignal as Signal @@ -55,23 +72,26 @@ # Alias for MiddleButton removed in PyQt6 but available in PyQt5, PySide2 and PySide6 Qt.MidButton = Qt.MiddleButton -elif PYQT5: - from PyQt5.QtCore import * - from PyQt5.QtCore import pyqtSignal as Signal - from PyQt5.QtCore import pyqtBoundSignal as SignalInstance - from PyQt5.QtCore import pyqtSlot as Slot - from PyQt5.QtCore import pyqtProperty as Property - from PyQt5.QtCore import QT_VERSION_STR as __version__ +elif PYSIDE2: + from PySide2.QtCore import * - # For issue #153 and updated for issue #305 - from PyQt5.QtCore import QDateTime - QDateTime.toPython = lambda self, *args, **kwargs: self.toPyDateTime(*args, **kwargs) + try: # may be limited to PySide-5.11a1 only + from PySide2.QtGui import QStringListModel + except Exception: + pass - # Map missing methods on PyQt5 5.12 - QTextStreamManipulator.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) + import PySide2.QtCore + __version__ = PySide2.QtCore.__version__ - # Those are imported from `import *` - del pyqtSignal, pyqtBoundSignal, pyqtSlot, pyqtProperty, QT_VERSION_STR + # Missing QtGui utility functions on Qt + if getattr(Qt, 'mightBeRichText', None) is None: + try: + from PySide2.QtGui import Qt as guiQt + Qt.mightBeRichText = guiQt.mightBeRichText + del guiQt + except ImportError: + # Fails with PySide2 5.12.0 + pass elif PYSIDE6: from PySide6.QtCore import * @@ -95,25 +115,5 @@ QThread.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) QTextStreamManipulator.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) -elif PYSIDE2: - from PySide2.QtCore import * - - try: # may be limited to PySide-5.11a1 only - from PySide2.QtGui import QStringListModel - except Exception: - pass - - import PySide2.QtCore - __version__ = PySide2.QtCore.__version__ - - # Missing QtGui utility functions on Qt - if getattr(Qt, 'mightBeRichText', None) is None: - try: - from PySide2.QtGui import Qt as guiQt - Qt.mightBeRichText = guiQt.mightBeRichText - del guiQt - except ImportError: - # Fails with PySide2 5.12.0 - pass else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtDBus.py b/qtpy/QtDBus.py index 9499a9f7..2f863c3f 100644 --- a/qtpy/QtDBus.py +++ b/qtpy/QtDBus.py @@ -4,16 +4,31 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtDBus classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +import sys + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, + QtModuleNotInOSError, +) if PYQT5: from PyQt5.QtDBus import * elif PYQT6: from PyQt6.QtDBus import * +elif PYSIDE2: + raise QtBindingMissingModuleError(name='QtDBus') elif PYSIDE6: - from PySide6.QtDBus import * + if sys.platform != 'win32': + from PySide6.QtDBus import * + else: + raise QtModuleNotInOSError(name='QtDBus') else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtDataVisualization.py b/qtpy/QtDataVisualization.py index a0e1dfc2..c5885414 100644 --- a/qtpy/QtDataVisualization.py +++ b/qtpy/QtDataVisualization.py @@ -4,22 +4,41 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtDataVisualization classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, +) -if PYQT6: - from PyQt6.QtDataVisualization import * -elif PYQT5: - from PyQt5.QtDataVisualization import * -elif PYSIDE6: - from PySide6.QtDataVisualization import * +if PYQT5: + try: + from PyQt5.QtDataVisualization import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtDataVisualization', missing_package='PyQtDataVisualization' + ) from error +elif PYQT6: + try: + from PyQt6.QtDataVisualization import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtDataVisualization', + missing_package='PyQt6-DataVisualization', + ) from error elif PYSIDE2: # https://bugreports.qt.io/projects/PYSIDE/issues/PYSIDE-1026 import PySide2.QtDataVisualization as __temp import inspect + for __name in inspect.getmembers(__temp.QtDataVisualization): globals()[__name[0]] = __name[1] +elif PYSIDE6: + from PySide6.QtDataVisualization import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtDesigner.py b/qtpy/QtDesigner.py index 2b086bbe..ae2696b2 100644 --- a/qtpy/QtDesigner.py +++ b/qtpy/QtDesigner.py @@ -1,21 +1,28 @@ -# +# ----------------------------------------------------------------------------- # Copyright © 2014-2015 Colin Duquesnoy # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- -""" -Provides QtDesigner classes and functions. -""" - -from . import PYQT5, PYQT6, PYSIDE6, PythonQtError +"""Provides QtDesigner classes and functions.""" +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) if PYQT5: from PyQt5.QtDesigner import * elif PYQT6: from PyQt6.QtDesigner import * +elif PYSIDE2: + raise QtBindingMissingModuleError(name='QtDesigner') elif PYSIDE6: from PySide6.QtDesigner import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 8b470612..7c585b6a 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -1,17 +1,18 @@ -# +# ----------------------------------------------------------------------------- # Copyright © 2014-2015 Colin Duquesnoy # Copyright © 2009- The Spyder Development Team # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- -""" -Provides QtGui classes and functions. -""" -from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, PythonQtError +"""Provides QtGui classes and functions.""" +from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, QtBindingsNotFoundError -if PYQT6: +if PYQT5: + from PyQt5.QtGui import * +elif PYQT6: from PyQt6 import QtGui from PyQt6.QtGui import * from PyQt6.QtOpenGL import * @@ -26,8 +27,6 @@ from .enums_compat import promote_enums promote_enums(QtGui) del QtGui -elif PYQT5: - from PyQt5.QtGui import * elif PYSIDE2: from PySide2.QtGui import * if hasattr(QFontMetrics, 'horizontalAdvance'): @@ -42,7 +41,7 @@ QDrag.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) QGuiApplication.exec_ = QGuiApplication.exec else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() if PYSIDE2 or PYSIDE6: # PySide{2,6} do not accept the `mode` keyword argument in @@ -73,4 +72,3 @@ def movePositionPatched( ) -> bool: return movePosition(self, operation, mode, n) QTextCursor.movePosition = movePositionPatched - diff --git a/qtpy/QtHelp.py b/qtpy/QtHelp.py index 2fcfdcc9..337e6b0f 100644 --- a/qtpy/QtHelp.py +++ b/qtpy/QtHelp.py @@ -1,22 +1,21 @@ -# +# ----------------------------------------------------------------------------- # Copyright © 2009- The Spyder Development Team # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- """QtHelp Wrapper.""" -import warnings - -from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtHelp import * elif PYQT6: from PyQt6.QtHelp import * -elif PYSIDE6: - from PySide6.QtHelp import * elif PYSIDE2: from PySide2.QtHelp import * +elif PYSIDE6: + from PySide6.QtHelp import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtLocation.py b/qtpy/QtLocation.py index 7241158d..72a6ba12 100644 --- a/qtpy/QtLocation.py +++ b/qtpy/QtLocation.py @@ -4,14 +4,25 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtLocation classes and functions.""" -# Local imports -from . import PYQT5, PYSIDE2, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) if PYQT5: from PyQt5.QtLocation import * +elif PYQT6: + raise QtBindingMissingModuleError(name='QtLocation') elif PYSIDE2: from PySide2.QtLocation import * +elif PYSIDE6: + raise QtBindingMissingModuleError(name='QtLocation') else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtMacExtras.py b/qtpy/QtMacExtras.py new file mode 100644 index 00000000..9d391cb6 --- /dev/null +++ b/qtpy/QtMacExtras.py @@ -0,0 +1,34 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides classes and functions specific to macOS and iOS operating systems""" + +import sys + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInQtVersionError, + QtModuleNotInOSError, +) + +if sys.platform == 'darwin': + if PYQT5: + from PyQt5.QtMacExtras import * + elif PYQT6: + raise QtModuleNotInQtVersionError(name='QtMacExtras') + elif PYSIDE2: + from PySide2.QtMacExtras import * + elif PYSIDE6: + raise QtModuleNotInQtVersionError(name='QtMacExtras') + else: + raise QtBindingsNotFoundError() +else: + raise QtModuleNotInOSError(name='QtMacExtras') diff --git a/qtpy/QtMultimedia.py b/qtpy/QtMultimedia.py index 683c3bb1..cf9ecdc6 100644 --- a/qtpy/QtMultimedia.py +++ b/qtpy/QtMultimedia.py @@ -1,16 +1,21 @@ -import warnings +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- -from . import PYQT5, PYQT6 -from . import PYSIDE2 -from . import PYSIDE6 +"""Provides low-level multimedia functionality.""" + +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtMultimedia import * elif PYQT6: from PyQt6.QtMultimedia import * -elif PYSIDE6: - from PySide6.QtMultimedia import * elif PYSIDE2: from PySide2.QtMultimedia import * +elif PYSIDE6: + from PySide6.QtMultimedia import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtMultimediaWidgets.py b/qtpy/QtMultimediaWidgets.py index ee8db677..0e9dee51 100644 --- a/qtpy/QtMultimediaWidgets.py +++ b/qtpy/QtMultimediaWidgets.py @@ -4,10 +4,10 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtMultimediaWidgets classes and functions.""" -# Local imports -from . import PYSIDE2, PYSIDE6, PYQT5, PYQT6, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtMultimediaWidgets import * @@ -18,4 +18,4 @@ elif PYSIDE6: from PySide6.QtMultimediaWidgets import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtNetwork.py b/qtpy/QtNetwork.py index b053fc41..b3cfdd3c 100644 --- a/qtpy/QtNetwork.py +++ b/qtpy/QtNetwork.py @@ -1,24 +1,22 @@ -# +# ----------------------------------------------------------------------------- # Copyright © 2014-2015 Colin Duquesnoy # Copyright © 2009- The Spyder Development Team # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- -""" -Provides QtNetwork classes and functions. -""" - -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +"""Provides QtNetwork classes and functions.""" +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtNetwork import * elif PYQT6: from PyQt6.QtNetwork import * -elif PYSIDE6: - from PySide6.QtNetwork import * elif PYSIDE2: from PySide2.QtNetwork import * +elif PYSIDE6: + from PySide6.QtNetwork import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtNetworkAuth.py b/qtpy/QtNetworkAuth.py index 1a377778..94f8f5bc 100644 --- a/qtpy/QtNetworkAuth.py +++ b/qtpy/QtNetworkAuth.py @@ -4,16 +4,36 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtNetworkAuth classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, + QtBindingMissingModuleError, +) -if PYQT6: - from PyQt6.QtNetworkAuth import * -elif PYQT5: - from PyQt5.QtNetworkAuth import * +if PYQT5: + try: + from PyQt5.QtNetworkAuth import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtNetworkAuth', missing_package='PyQtNetworkAuth' + ) from error +elif PYQT6: + try: + from PyQt6.QtNetworkAuth import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtNetworkAuth', missing_package='PyQt6-NetworkAuth' + ) from error +elif PYSIDE2: + raise QtBindingMissingModuleError(name='QtNetworkAuth') elif PYSIDE6: from PySide6.QtNetworkAuth import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtNfc.py b/qtpy/QtNfc.py new file mode 100644 index 00000000..adf73e25 --- /dev/null +++ b/qtpy/QtNfc.py @@ -0,0 +1,28 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtNfc classes and functions.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: + from PyQt5.QtNfc import * +elif PYQT6: + from PyQt6.QtNfc import * +elif PYSIDE2: + raise QtBindingMissingModuleError(name='QtNfc') +elif PYSIDE6: + from PySide6.QtNfc import * +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/QtOpenGL.py b/qtpy/QtOpenGL.py index b4cb5a93..b1f749dd 100644 --- a/qtpy/QtOpenGL.py +++ b/qtpy/QtOpenGL.py @@ -4,21 +4,31 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtOpenGL classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtOpenGL import * from PyQt5.QtGui import ( - QOpenGLBuffer, QOpenGLFramebufferObject, - QOpenGLFramebufferObjectFormat, QOpenGLShader, QOpenGLShaderProgram, - QOpenGLContext, QOpenGLContextGroup, QOpenGLDebugLogger, - QOpenGLDebugMessage, QOpenGLPixelTransferOptions, QOpenGLTexture, + QOpenGLBuffer, + QOpenGLFramebufferObject, + QOpenGLFramebufferObjectFormat, + QOpenGLShader, + QOpenGLShaderProgram, + QOpenGLContext, + QOpenGLContextGroup, + QOpenGLDebugLogger, + QOpenGLDebugMessage, + QOpenGLPixelTransferOptions, + QOpenGLTexture, QOpenGLTextureBlitter, - QOpenGLVersionProfile, QOpenGLVertexArrayObject, QOpenGLWindow + QOpenGLVersionProfile, + QOpenGLVertexArrayObject, + QOpenGLWindow, ) + # These are not present on some architectures such as armhf try: from PyQt5.QtGui import QOpenGLTimeMonitor, QOpenGLTimerQuery @@ -26,25 +36,34 @@ pass elif PYQT6: from PyQt6.QtOpenGL import * - from PyQt6.QtGui import (QOpenGLContext, QOpenGLContextGroup) + from PyQt6.QtGui import QOpenGLContext, QOpenGLContextGroup elif PYSIDE6: from PySide6.QtOpenGL import * - from PySide6.QtGui import (QOpenGLContext, QOpenGLContextGroup) + from PySide6.QtGui import QOpenGLContext, QOpenGLContextGroup elif PYSIDE2: from PySide2.QtOpenGL import * from PySide2.QtGui import ( - QOpenGLBuffer, QOpenGLFramebufferObject, - QOpenGLFramebufferObjectFormat, QOpenGLShader, QOpenGLShaderProgram, - QOpenGLContext, QOpenGLContextGroup, QOpenGLDebugLogger, - QOpenGLDebugMessage, QOpenGLPixelTransferOptions, QOpenGLTexture, + QOpenGLBuffer, + QOpenGLFramebufferObject, + QOpenGLFramebufferObjectFormat, + QOpenGLShader, + QOpenGLShaderProgram, + QOpenGLContext, + QOpenGLContextGroup, + QOpenGLDebugLogger, + QOpenGLDebugMessage, + QOpenGLPixelTransferOptions, + QOpenGLTexture, QOpenGLTextureBlitter, - QOpenGLVersionProfile, QOpenGLVertexArrayObject, QOpenGLWindow + QOpenGLVersionProfile, + QOpenGLVertexArrayObject, + QOpenGLWindow, ) + # These are not present on some architectures such as armhf try: from PySide2.QtGui import QOpenGLTimeMonitor, QOpenGLTimerQuery except ImportError: pass else: - raise PythonQtError('No Qt bindings could be found') - + raise QtBindingsNotFoundError() diff --git a/qtpy/QtOpenGLWidgets.py b/qtpy/QtOpenGLWidgets.py index 4df07110..cf1a98d0 100644 --- a/qtpy/QtOpenGLWidgets.py +++ b/qtpy/QtOpenGLWidgets.py @@ -4,14 +4,25 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtOpenGLWidgets classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) -if PYQT6: +if PYQT5: + raise QtBindingMissingModuleError(name='QtOpenGLWidgets') +elif PYQT6: from PyQt6.QtOpenGLWidgets import * +elif PYSIDE2: + raise QtBindingMissingModuleError(name='QtOpenGLWidgets') elif PYSIDE6: from PySide6.QtOpenGLWidgets import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtPositioning.py b/qtpy/QtPositioning.py index 5535ef3f..0583d3e6 100644 --- a/qtpy/QtPositioning.py +++ b/qtpy/QtPositioning.py @@ -4,14 +4,18 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtPositioning classes and functions.""" -# Local imports -from . import PYQT5, PYSIDE2, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtPositioning import * +elif PYQT6: + from PyQt6.QtPositioning import * elif PYSIDE2: from PySide2.QtPositioning import * +elif PYSIDE6: + from PySide6.QtPositioning import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtPrintSupport.py b/qtpy/QtPrintSupport.py index 4fcec32b..2fa24a20 100644 --- a/qtpy/QtPrintSupport.py +++ b/qtpy/QtPrintSupport.py @@ -1,15 +1,13 @@ -# +# ----------------------------------------------------------------------------- # Copyright © 2009- The Spyder Development Team # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- -""" -Provides QtPrintSupport classes and functions. -""" - -from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, PythonQtError +"""Provides QtPrintSupport classes and functions.""" +from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, QtBindingsNotFoundError if PYQT5: from PyQt5.QtPrintSupport import * @@ -26,4 +24,4 @@ elif PYSIDE2: from PySide2.QtPrintSupport import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtPurchasing.py b/qtpy/QtPurchasing.py new file mode 100644 index 00000000..ab0aba57 --- /dev/null +++ b/qtpy/QtPurchasing.py @@ -0,0 +1,34 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtPurchasing classes and functions.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, + QtModuleNotInstalledError, +) + +if PYQT5: + try: + from PyQt5.QtPurchasing import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtPurchasing', missing_package='PyQtPurchasing' + ) from error +elif PYQT6: + raise QtBindingMissingModuleError(name='QtPurchasing') +elif PYSIDE2: + raise QtBindingMissingModuleError(name='QtPurchasing') +elif PYSIDE6: + raise QtBindingMissingModuleError(name='QtPurchasing') +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/QtQml.py b/qtpy/QtQml.py index ec6934a7..4bb35a2c 100644 --- a/qtpy/QtQml.py +++ b/qtpy/QtQml.py @@ -4,10 +4,10 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtQml classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtQml import * @@ -18,4 +18,4 @@ elif PYSIDE2: from PySide2.QtQml import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtQuick.py b/qtpy/QtQuick.py index 10f6a41c..577fcdb0 100644 --- a/qtpy/QtQuick.py +++ b/qtpy/QtQuick.py @@ -4,10 +4,10 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtQuick classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, PythonQtError +from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, QtBindingsNotFoundError if PYQT5: from PyQt5.QtQuick import * @@ -18,4 +18,4 @@ elif PYSIDE2: from PySide2.QtQuick import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtQuick3D.py b/qtpy/QtQuick3D.py new file mode 100644 index 00000000..ad81c14b --- /dev/null +++ b/qtpy/QtQuick3D.py @@ -0,0 +1,28 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtQuick3D classes and functions.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: + from PyQt5.QtQuick3D import * +elif PYQT6: + from PyQt6.QtQuick3D import * +elif PYSIDE2: + raise QtBindingMissingModuleError(name='QtQuick3D') +elif PYSIDE6: + from PySide6.QtQuick3D import * +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/QtQuickControls2.py b/qtpy/QtQuickControls2.py new file mode 100644 index 00000000..0693857f --- /dev/null +++ b/qtpy/QtQuickControls2.py @@ -0,0 +1,28 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtQuickControls2 classes and functions.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: + raise QtBindingMissingModuleError(name='QtQuickControls2') +elif PYQT6: + raise QtBindingMissingModuleError(name='QtQuickControls2') +elif PYSIDE2: + from PySide2.QtQuickControls2 import * +elif PYSIDE6: + from PySide6.QtQuickControls2 import * +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/QtQuickWidgets.py b/qtpy/QtQuickWidgets.py index dfadb2c0..1bc5521a 100644 --- a/qtpy/QtQuickWidgets.py +++ b/qtpy/QtQuickWidgets.py @@ -4,10 +4,10 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtQuickWidgets classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, PythonQtError +from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, QtBindingsNotFoundError if PYQT5: from PyQt5.QtQuickWidgets import * @@ -18,4 +18,4 @@ elif PYSIDE2: from PySide2.QtQuickWidgets import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtRemoteObjects.py b/qtpy/QtRemoteObjects.py index d1515c57..59cce95d 100644 --- a/qtpy/QtRemoteObjects.py +++ b/qtpy/QtRemoteObjects.py @@ -4,10 +4,10 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtRemoteObjects classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtRemoteObjects import * @@ -18,4 +18,4 @@ elif PYSIDE2: from PySide2.QtRemoteObjects import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtScxml.py b/qtpy/QtScxml.py new file mode 100644 index 00000000..cbf2a96b --- /dev/null +++ b/qtpy/QtScxml.py @@ -0,0 +1,28 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtScxml classes and functions.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: + raise QtBindingMissingModuleError(name='QtScxml') +elif PYQT6: + raise QtBindingMissingModuleError(name='QtScxml') +elif PYSIDE2: + from PySide2.QtScxml import * +elif PYSIDE6: + from PySide6.QtScxml import * +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/QtSensors.py b/qtpy/QtSensors.py index 96ac1b12..6e28cc22 100644 --- a/qtpy/QtSensors.py +++ b/qtpy/QtSensors.py @@ -4,10 +4,10 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtSensors classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtSensors import * @@ -18,4 +18,4 @@ elif PYSIDE2: from PySide2.QtSensors import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtSerialPort.py b/qtpy/QtSerialPort.py index 426cb8f5..ed4584a9 100644 --- a/qtpy/QtSerialPort.py +++ b/qtpy/QtSerialPort.py @@ -5,10 +5,10 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtSerialPort classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtSerialPort import * @@ -19,4 +19,4 @@ elif PYSIDE2: from PySide2.QtSerialPort import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtSql.py b/qtpy/QtSql.py index 038c34db..372fe1f9 100644 --- a/qtpy/QtSql.py +++ b/qtpy/QtSql.py @@ -4,10 +4,10 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtSql classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, PythonQtError +from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, QtBindingsNotFoundError if PYQT5: from PyQt5.QtSql import * @@ -25,5 +25,4 @@ elif PYSIDE2: from PySide2.QtSql import * else: - raise PythonQtError('No Qt bindings could be found') - + raise QtBindingsNotFoundError() diff --git a/qtpy/QtStateMachine.py b/qtpy/QtStateMachine.py new file mode 100644 index 00000000..039749a6 --- /dev/null +++ b/qtpy/QtStateMachine.py @@ -0,0 +1,28 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtStateMachine classes and functions.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: + raise QtBindingMissingModuleError(name='QtStateMachine') +elif PYQT6: + raise QtBindingMissingModuleError(name='QtStateMachine') +elif PYSIDE2: + raise QtBindingMissingModuleError(name='QtStateMachine') +elif PYSIDE6: + from PySide6.QtStateMachine import * +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/QtSvg.py b/qtpy/QtSvg.py index 4e7733b9..4d902875 100644 --- a/qtpy/QtSvg.py +++ b/qtpy/QtSvg.py @@ -4,19 +4,18 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtSvg classes and functions.""" -# Local imports -from . import PYSIDE6, PYSIDE2, PYQT5, PYQT6, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError -if PYQT6: - from PyQt6.QtSvg import * -elif PYQT5: +if PYQT5: from PyQt5.QtSvg import * -elif PYSIDE6: - from PySide6.QtSvg import * +elif PYQT6: + from PyQt6.QtSvg import * elif PYSIDE2: from PySide2.QtSvg import * +elif PYSIDE6: + from PySide6.QtSvg import * else: - raise PythonQtError('No Qt bindings could be found') - + raise QtBindingsNotFoundError() diff --git a/qtpy/QtSvgWidgets.py b/qtpy/QtSvgWidgets.py new file mode 100644 index 00000000..571ca18c --- /dev/null +++ b/qtpy/QtSvgWidgets.py @@ -0,0 +1,28 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtSvgWidgets classes and functions.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: + raise QtBindingMissingModuleError(name='QtSvgWidgets') +elif PYQT6: + from PyQt6.QtSvgWidgets import * +elif PYSIDE2: + raise QtBindingMissingModuleError(name='QtSvgWidgets') +elif PYSIDE6: + from PySide6.QtSvgWidgets import * +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/QtTest.py b/qtpy/QtTest.py index 557d1c74..53079983 100644 --- a/qtpy/QtTest.py +++ b/qtpy/QtTest.py @@ -1,29 +1,29 @@ -# +# ----------------------------------------------------------------------------- # Copyright © 2014-2015 Colin Duquesnoy # Copyright © 2009- The Spyder Developmet Team # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- -""" -Provides QtTest and functions -""" +"""Provides QtTest and functions""" -from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, PythonQtError +from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, QtBindingsNotFoundError -if PYQT6: +if PYQT5: + from PyQt5.QtTest import * +elif PYQT6: from PyQt6 import QtTest from PyQt6.QtTest import * # Allow unscoped access for enums inside the QtTest module from .enums_compat import promote_enums + promote_enums(QtTest) del QtTest -elif PYQT5: - from PyQt5.QtTest import * -elif PYSIDE6: - from PySide6.QtTest import * elif PYSIDE2: from PySide2.QtTest import * +elif PYSIDE6: + from PySide6.QtTest import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtTextToSpeech.py b/qtpy/QtTextToSpeech.py index e02e037a..81eae9eb 100644 --- a/qtpy/QtTextToSpeech.py +++ b/qtpy/QtTextToSpeech.py @@ -4,13 +4,25 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtTextToSpeech classes and functions.""" -from . import PYQT5, PYSIDE2, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) if PYQT5: from PyQt5.QtTextToSpeech import * +elif PYQT6: + raise QtBindingMissingModuleError(name='QtTextToSpeech') elif PYSIDE2: from PySide2.QtTextToSpeech import * +elif PYSIDE6: + raise QtBindingMissingModuleError(name='QtTextToSpeech') else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtUiTools.py b/qtpy/QtUiTools.py new file mode 100644 index 00000000..1dc9e377 --- /dev/null +++ b/qtpy/QtUiTools.py @@ -0,0 +1,28 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides QtUiTools classes and functions.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: + raise QtBindingMissingModuleError(name='QtUiTools') +elif PYQT6: + raise QtBindingMissingModuleError(name='QtUiTools') +elif PYSIDE2: + from PySide2.QtUiTools import * +elif PYSIDE6: + from PySide6.QtUiTools import * +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/QtWebChannel.py b/qtpy/QtWebChannel.py index efd402c8..6c7ae285 100644 --- a/qtpy/QtWebChannel.py +++ b/qtpy/QtWebChannel.py @@ -4,18 +4,18 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtWebChannel classes and functions.""" -# Local imports -from . import PYSIDE2, PYSIDE6, PYQT5, PYQT6, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtWebChannel import * elif PYQT6: from PyQt6.QtWebChannel import * -elif PYSIDE6: - from PySide6.QtWebChannel import * elif PYSIDE2: from PySide2.QtWebChannel import * +elif PYSIDE6: + from PySide6.QtWebChannel import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtWebEngine.py b/qtpy/QtWebEngine.py index 1b913a1a..e592f4d7 100644 --- a/qtpy/QtWebEngine.py +++ b/qtpy/QtWebEngine.py @@ -1,19 +1,35 @@ -# +# ----------------------------------------------------------------------------- # Copyright © 2014-2015 Colin Duquesnoy # Copyright © 2009- The Spyder development Team # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- -""" -Provides QtWebEngine classes and functions. -""" +"""Provides QtWebEngine classes and functions.""" -from . import PYQT5, PYSIDE6 +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInQtVersionError, + QtModuleNotInstalledError, +) if PYQT5: - from PyQt5.QtWebEngine import * + try: + from PyQt5.QtWebEngine import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtWebEngine', missing_package='PyQtWebEngine' + ) from error +elif PYQT6: + raise QtModuleNotInQtVersionError(name='QtWebEngine') +elif PYSIDE2: + from PySide2.QtWebEngine import * elif PYSIDE6: - from PySide6.QtWebEngine import * + raise QtModuleNotInQtVersionError(name='QtWebEngine') else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtWebEngineCore.py b/qtpy/QtWebEngineCore.py index 591b14f2..d8c6ca3a 100644 --- a/qtpy/QtWebEngineCore.py +++ b/qtpy/QtWebEngineCore.py @@ -4,18 +4,35 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtWebEngineCore classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, +) if PYQT5: - from PyQt5.QtWebEngineCore import * + try: + from PyQt5.QtWebEngineCore import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtWebEngineCore', missing_package='PyQtWebEngine' + ) from error elif PYQT6: - from PyQt6.QtWebEngineCore import * + try: + from PyQt6.QtWebEngineCore import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtWebEngineCore', missing_package='PyQt6-WebEngine' + ) from error elif PYSIDE2: from PySide2.QtWebEngineCore import * elif PYSIDE6: from PySide6.QtWebEngineCore import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtWebEngineQuick.py b/qtpy/QtWebEngineQuick.py index e5d9afdc..cd10d1d5 100644 --- a/qtpy/QtWebEngineQuick.py +++ b/qtpy/QtWebEngineQuick.py @@ -4,14 +4,31 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtWebEngineQuick classes and functions.""" -# Local imports -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, + QtBindingMissingModuleError, +) -if PYQT6: - from PyQt6.QtWebEngineQuick import * +if PYQT5: + raise QtBindingMissingModuleError(name='QtWebEngineQuick') +elif PYQT6: + try: + from PyQt6.QtWebEngineQuick import * + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtWebEngineQuick', missing_package='PyQt6-WebEngine' + ) from error +elif PYSIDE2: + raise QtBindingMissingModuleError(name='QtWebEngineQuick') elif PYSIDE6: from PySide6.QtWebEngineQuick import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtWebEngineWidgets.py b/qtpy/QtWebEngineWidgets.py index 5bcaebf0..1d0fbda1 100644 --- a/qtpy/QtWebEngineWidgets.py +++ b/qtpy/QtWebEngineWidgets.py @@ -1,20 +1,21 @@ -# +# ----------------------------------------------------------------------------- # Copyright © 2014-2015 Colin Duquesnoy # Copyright © 2009- The Spyder development Team # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- -""" -Provides QtWebEngineWidgets classes and functions. -""" - -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError - - -# To test if we are using WebEngine or WebKit -WEBENGINE = True +"""Provides QtWebEngineWidgets classes and functions.""" +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInstalledError, +) if PYQT5: try: @@ -22,32 +23,37 @@ from PyQt5.QtWebEngineWidgets import QWebEngineView from PyQt5.QtWebEngineWidgets import QWebEngineSettings from PyQt5.QtWebEngineWidgets import QWebEngineScript + # Based on the work at https://github.com/spyder-ide/qtpy/pull/203 from PyQt5.QtWebEngineWidgets import QWebEngineProfile - except ImportError: - from PyQt5.QtWebKitWidgets import QWebPage as QWebEnginePage - from PyQt5.QtWebKitWidgets import QWebView as QWebEngineView - from PyQt5.QtWebKit import QWebSettings as QWebEngineSettings - WEBENGINE = False + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtWebEngineWidgets', missing_package='PyQtWebEngine' + ) from error elif PYQT6: - from PyQt6.QtWebEngineWidgets import * - from PyQt6.QtWebEngineCore import QWebEnginePage - from PyQt6.QtWebEngineCore import QWebEngineSettings - from PyQt6.QtWebEngineCore import QWebEngineProfile - from PyQt6.QtWebEngineCore import QWebEngineScript - -elif PYSIDE6: - from PySide6.QtWebEngineWidgets import * - from PySide6.QtWebEngineCore import QWebEnginePage - from PySide6.QtWebEngineCore import QWebEngineSettings - from PySide6.QtWebEngineCore import QWebEngineProfile - from PySide6.QtWebEngineCore import QWebEngineScript + try: + from PyQt6.QtWebEngineWidgets import * + from PyQt6.QtWebEngineCore import QWebEnginePage + from PyQt6.QtWebEngineCore import QWebEngineSettings + from PyQt6.QtWebEngineCore import QWebEngineProfile + from PyQt6.QtWebEngineCore import QWebEngineScript + except ModuleNotFoundError as error: + raise QtModuleNotInstalledError( + name='QtWebEngineWidgets', missing_package='PyQt6-WebEngine' + ) from error elif PYSIDE2: from PySide2.QtWebEngineWidgets import QWebEnginePage from PySide2.QtWebEngineWidgets import QWebEngineView from PySide2.QtWebEngineWidgets import QWebEngineSettings from PySide2.QtWebEngineWidgets import QWebEngineScript + # Based on the work at https://github.com/spyder-ide/qtpy/pull/203 from PySide2.QtWebEngineWidgets import QWebEngineProfile +elif PYSIDE6: + from PySide6.QtWebEngineWidgets import * + from PySide6.QtWebEngineCore import QWebEnginePage + from PySide6.QtWebEngineCore import QWebEngineSettings + from PySide6.QtWebEngineCore import QWebEngineProfile + from PySide6.QtWebEngineCore import QWebEngineScript else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtWebSockets.py b/qtpy/QtWebSockets.py index 7b2118b8..9a595888 100644 --- a/qtpy/QtWebSockets.py +++ b/qtpy/QtWebSockets.py @@ -4,10 +4,10 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtWebSockets classes and functions.""" -# Local imports -from . import PYSIDE2, PYQT5, PYQT6, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtWebSockets import * @@ -15,5 +15,7 @@ from PyQt6.QtWebSockets import * elif PYSIDE2: from PySide2.QtWebSockets import * +elif PYSIDE6: + from PySide6.QtWebSockets import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtWidgets.py b/qtpy/QtWidgets.py index 70996ae7..25c8f16a 100644 --- a/qtpy/QtWidgets.py +++ b/qtpy/QtWidgets.py @@ -1,17 +1,18 @@ -# +# ----------------------------------------------------------------------------- # Copyright © 2014-2015 Colin Duquesnoy # Copyright © 2009- The Spyder Developmet Team # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- -""" -Provides widget classes and functions. -""" -from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError +"""Provides widget classes and functions.""" +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError -if PYQT6: +if PYQT5: + from PyQt5.QtWidgets import * +elif PYQT6: from PyQt6 import QtWidgets from PyQt6.QtWidgets import * from PyQt6.QtGui import QAction, QActionGroup, QShortcut, QFileSystemModel @@ -32,8 +33,8 @@ from .enums_compat import promote_enums promote_enums(QtWidgets) del QtWidgets -elif PYQT5: - from PyQt5.QtWidgets import * +elif PYSIDE2: + from PySide2.QtWidgets import * elif PYSIDE6: from PySide6.QtWidgets import * from PySide6.QtGui import QAction, QActionGroup, QShortcut @@ -49,7 +50,5 @@ QApplication.exec_ = QApplication.exec QDialog.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) QMenu.exec_ = lambda self, *args, **kwargs: self.exec(*args, **kwargs) -elif PYSIDE2: - from PySide2.QtWidgets import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtWinExtras.py b/qtpy/QtWinExtras.py index 8b870bdf..475ad5e5 100644 --- a/qtpy/QtWinExtras.py +++ b/qtpy/QtWinExtras.py @@ -3,13 +3,32 @@ # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides Windows-specific utilities""" -from . import PYQT5, PYSIDE2, PythonQtError +import sys +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInQtVersionError, + QtModuleNotInOSError, +) -if PYQT5: - from PyQt5.QtWinExtras import * -elif PYSIDE2: - from PySide2.QtWinExtras import * +if sys.platform == 'win32': + if PYQT5: + from PyQt5.QtWinExtras import * + elif PYQT6: + raise QtModuleNotInQtVersionError(name='QtWinExtras') + elif PYSIDE2: + from PySide2.QtWinExtras import * + elif PYSIDE6: + raise QtModuleNotInQtVersionError(name='QtWinExtras') + else: + raise QtBindingsNotFoundError() else: - raise PythonQtError('No Qt bindings could be found') + raise QtModuleNotInOSError(name='QtWinExtras') diff --git a/qtpy/QtX11Extras.py b/qtpy/QtX11Extras.py new file mode 100644 index 00000000..be02348e --- /dev/null +++ b/qtpy/QtX11Extras.py @@ -0,0 +1,34 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides Linux-specific utilities""" + +import sys + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtModuleNotInQtVersionError, + QtModuleNotInOSError, +) + +if sys.platform == 'linux': + if PYQT5: + from PyQt5.QtX11Extras import * + elif PYQT6: + raise QtModuleNotInQtVersionError(name='QtX11Extras') + elif PYSIDE2: + from PySide2.QtX11Extras import * + elif PYSIDE6: + raise QtModuleNotInQtVersionError(name='QtX11Extras') + else: + raise QtBindingsNotFoundError() +else: + raise QtModuleNotInOSError(name='QtX11Extras') diff --git a/qtpy/QtXml.py b/qtpy/QtXml.py index 3c160e60..d2cb1653 100644 --- a/qtpy/QtXml.py +++ b/qtpy/QtXml.py @@ -4,18 +4,18 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtXml classes and functions.""" -# Local imports -from . import PYSIDE2, PYSIDE6, PYQT5, PYQT6, PythonQtError +from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, QtBindingsNotFoundError if PYQT5: from PyQt5.QtXml import * elif PYQT6: from PyQt6.QtXml import * -elif PYSIDE6: - from PySide6.QtXml import * elif PYSIDE2: from PySide2.QtXml import * +elif PYSIDE6: + from PySide6.QtXml import * else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/QtXmlPatterns.py b/qtpy/QtXmlPatterns.py index f6b22a32..71040e0c 100644 --- a/qtpy/QtXmlPatterns.py +++ b/qtpy/QtXmlPatterns.py @@ -4,14 +4,25 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) # ----------------------------------------------------------------------------- + """Provides QtXmlPatterns classes and functions.""" -# Local imports -from . import PYSIDE2, PYQT5, PythonQtError +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) if PYQT5: from PyQt5.QtXmlPatterns import * +elif PYQT6: + raise QtBindingMissingModuleError(name='QtXmlPatterns') elif PYSIDE2: from PySide2.QtXmlPatterns import * +elif PYSIDE6: + raise QtBindingMissingModuleError(name='QtXmlPatterns') else: - raise PythonQtError('No Qt bindings could be found') + raise QtBindingsNotFoundError() diff --git a/qtpy/__init__.py b/qtpy/__init__.py index e9003060..5bb058c2 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -76,6 +76,59 @@ class PythonQtValueError(ValueError): """Error raised if an invalid QT_API is specified.""" +class QtBindingsNotFoundError(PythonQtError): + """Error raised if no bindings could be selected.""" + _msg = 'No Qt bindings could be found' + + def __init__(self): + super().__init__(_msg) + + +class QtModuleNotFoundError(ModuleNotFoundError, PythonQtError): + """Raised when a Python Qt binding submodule is not installed/supported.""" + _msg = 'The {name} module was not found.' + _msg_binding = '{binding}' + _msg_extra = '' + + def __init__(self, *, name, msg=None, **msg_kwargs): + global API_NAME + binding = self._msg_binding.format(binding=API_NAME) + msg = msg or f'{self._msg} {self._msg_extra}'.strip() + msg = msg.format(name=name, binding=binding, **msg_kwargs) + super().__init__(msg, name=name) + + +class QtModuleNotInOSError(QtModuleNotFoundError): + """Raised when a module is not supported on the current operating system.""" + _msg = '{name} does not exist on this operating system.' + + +class QtModuleNotInQtVersionError(QtModuleNotFoundError): + """Raised when a module is not implemented in the current Qt version.""" + _msg = '{name} does not exist in {version}.' + + def __init__(self, *, name, msg=None, **msg_kwargs): + global QT5, QT6 + version = 'Qt5' if QT5 else 'Qt6' + super().__init__(name=name, version=version) + + +class QtBindingMissingModuleError(QtModuleNotFoundError): + """Raised when a module is not supported by a given binding.""" + _msg_extra = 'It is not currently implemented in {binding}.' + + +class QtModuleNotInstalledError(QtModuleNotFoundError): + """Raise when a module is supported by the binding, but not installed.""" + _msg_extra = 'It must be installed separately' + + def __init__(self, *, missing_package=None, **superclass_kwargs): + self.missing_package = missing_package + if missing_package is not None: + self._msg_extra += ' as {missing_package}.' + super().__init__(missing_package=missing_package, **superclass_kwargs) + + # Qt API environment variable name QT_API = 'QT_API' diff --git a/qtpy/shiboken.py b/qtpy/shiboken.py new file mode 100644 index 00000000..4133e85d --- /dev/null +++ b/qtpy/shiboken.py @@ -0,0 +1,30 @@ +# ----------------------------------------------------------------------------- +# Copyright © 2009- The Spyder Development Team +# +# Licensed under the terms of the MIT License +# (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- + +"""Provides access to shiboken.""" + +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: + raise QtBindingMissingModuleError(name='shiboken') +elif PYQT6: + raise QtBindingMissingModuleError(name='shiboken') +elif PYSIDE2: + from shiboken2 import * + import shiboken2 as shiboken +elif PYSIDE6: + from shiboken6 import * + import shiboken6 as shiboken +else: + raise QtBindingsNotFoundError() diff --git a/qtpy/sip.py b/qtpy/sip.py index 64e71e66..736af76f 100644 --- a/qtpy/sip.py +++ b/qtpy/sip.py @@ -1,15 +1,28 @@ -# +# ----------------------------------------------------------------------------- # Copyright © 2009- The Spyder Development Team # # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# ----------------------------------------------------------------------------- -from . import PYQT6, PYQT5, PythonQtError +"""Provides access to sip.""" -if PYQT6: - from PyQt6.sip import * -elif PYQT5: +from . import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + QtBindingsNotFoundError, + QtBindingMissingModuleError, +) + +if PYQT5: from PyQt5.sip import * +elif PYQT6: + from PyQt6.sip import * +elif PYSIDE2: + raise QtBindingMissingModuleError(name='sip') +elif PYSIDE6: + raise QtBindingMissingModuleError(name='sip') else: - raise PythonQtError( - 'Currently selected Qt binding does not support this module') + raise QtBindingsNotFoundError() diff --git a/qtpy/tests/test_main.py b/qtpy/tests/test_main.py index dd57fcca..f6c6efbf 100644 --- a/qtpy/tests/test_main.py +++ b/qtpy/tests/test_main.py @@ -43,10 +43,6 @@ def assert_pyqt5(): assert QtCore.QEvent is PyQt5.QtCore.QEvent assert QtGui.QPainter is PyQt5.QtGui.QPainter assert QtWidgets.QWidget is PyQt5.QtWidgets.QWidget - if QtWebEngineWidgets.WEBENGINE: - assert QtWebEngineWidgets.QWebEnginePage is PyQt5.QtWebEngineWidgets.QWebEnginePage - else: - assert QtWebEngineWidgets.QWebEnginePage is PyQt5.QtWebKitWidgets.QWebPage assert os.environ['QT_API'] == 'pyqt5' def assert_pyqt6(): diff --git a/qtpy/tests/test_qdesktopservice_split.py b/qtpy/tests/test_qdesktopservice_split.py index d412e9c8..27021762 100644 --- a/qtpy/tests/test_qdesktopservice_split.py +++ b/qtpy/tests/test_qdesktopservice_split.py @@ -21,5 +21,3 @@ def test_qdesktopservice(): from qtpy.QtGui import QDesktopServices assert QDesktopServices.setUrlHandler is not None - - diff --git a/qtpy/tests/test_qt3danimation.py b/qtpy/tests/test_qt3danimation.py index 3e355cb8..c546f0c1 100644 --- a/qtpy/tests/test_qt3danimation.py +++ b/qtpy/tests/test_qt3danimation.py @@ -1,6 +1,7 @@ import pytest from qtpy import PYQT5, PYSIDE2 + @pytest.mark.skipif(not (PYQT5 or PYSIDE2), reason="Only available in Qt5 bindings") def test_qt3danimation(): """Test the qtpy.Qt3DAnimation namespace""" diff --git a/qtpy/tests/test_qt3dcore.py b/qtpy/tests/test_qt3dcore.py index b3fdada4..cd17542e 100644 --- a/qtpy/tests/test_qt3dcore.py +++ b/qtpy/tests/test_qt3dcore.py @@ -1,7 +1,9 @@ import pytest -from qtpy import PYQT6 +from qtpy import PYQT6, PYSIDE6 + @pytest.mark.skipif(PYQT6, reason="Not complete in PyQt6") +@pytest.mark.skipif(PYSIDE6, reason="Not complete in PySide6") def test_qt3dcore(): """Test the qtpy.Qt3DCore namespace""" Qt3DCore = pytest.importorskip("qtpy.Qt3DCore") diff --git a/qtpy/tests/test_qt3dextras.py b/qtpy/tests/test_qt3dextras.py index 500ee2a6..ba3f0e14 100644 --- a/qtpy/tests/test_qt3dextras.py +++ b/qtpy/tests/test_qt3dextras.py @@ -1,5 +1,6 @@ import pytest + def test_qt3dextras(): """Test the qtpy.Qt3DExtras namespace""" Qt3DExtras = pytest.importorskip("qtpy.Qt3DExtras") diff --git a/qtpy/tests/test_qt3dinput.py b/qtpy/tests/test_qt3dinput.py index 73ec711a..562055ed 100644 --- a/qtpy/tests/test_qt3dinput.py +++ b/qtpy/tests/test_qt3dinput.py @@ -1,5 +1,6 @@ import pytest + def test_qt3dinput(): """Test the qtpy.Qt3DInput namespace""" Qt3DInput = pytest.importorskip("qtpy.Qt3DInput") @@ -26,4 +27,3 @@ def test_qt3dinput(): assert Qt3DInput.QAction is not None assert Qt3DInput.QAbstractPhysicalDevice is not None assert Qt3DInput.QAxisSetting is not None - diff --git a/qtpy/tests/test_qt3dlogic.py b/qtpy/tests/test_qt3dlogic.py index 4c2df821..c325bf76 100644 --- a/qtpy/tests/test_qt3dlogic.py +++ b/qtpy/tests/test_qt3dlogic.py @@ -1,8 +1,9 @@ import pytest + def test_qt3dlogic(): """Test the qtpy.Qt3DLogic namespace""" Qt3DLogic = pytest.importorskip("qtpy.Qt3DLogic") - + assert Qt3DLogic.QLogicAspect is not None assert Qt3DLogic.QFrameAction is not None diff --git a/qtpy/tests/test_qt3drender.py b/qtpy/tests/test_qt3drender.py index e0c4e99c..c620721b 100644 --- a/qtpy/tests/test_qt3drender.py +++ b/qtpy/tests/test_qt3drender.py @@ -1,7 +1,9 @@ import pytest -from qtpy import PYQT6 +from qtpy import PYQT6, PYSIDE6 + @pytest.mark.skipif(PYQT6, reason="Not complete in PyQt6") +@pytest.mark.skipif(PYSIDE6, reason="Not complete in PySide6") def test_qt3drender(): """Test the qtpy.Qt3DRender namespace""" Qt3DRender = pytest.importorskip("qtpy.Qt3DRender") diff --git a/qtpy/tests/test_qtaxcontainer.py b/qtpy/tests/test_qtaxcontainer.py new file mode 100644 index 00000000..6e31a153 --- /dev/null +++ b/qtpy/tests/test_qtaxcontainer.py @@ -0,0 +1,9 @@ +import pytest + + +def test_qtaxcontainer(): + """Test the qtpy.QtAxContainer namespace""" + QtAxContainer = pytest.importorskip("qtpy.QtAxContainer") + + assert QtAxContainer.QAxSelect is not None + assert QtAxContainer.QAxWidget is not None diff --git a/qtpy/tests/test_qtbluetooth.py b/qtpy/tests/test_qtbluetooth.py new file mode 100644 index 00000000..c1f1e547 --- /dev/null +++ b/qtpy/tests/test_qtbluetooth.py @@ -0,0 +1,15 @@ +import pytest +from qtpy import PYSIDE2 + + +def test_qtbluetooth(): + """Test the qtpy.QtBluetooth namespace""" + QtBluetooth = pytest.importorskip("qtpy.QtBluetooth") + + assert QtBluetooth.QBluetooth is not None + assert QtBluetooth.QBluetoothDeviceInfo is not None + assert QtBluetooth.QBluetoothServer is not None + assert QtBluetooth.QBluetoothSocket is not None + assert QtBluetooth.QBluetoothAddress is not None + assert QtBluetooth.QBluetoothUuid is not None + assert QtBluetooth.QBluetoothServiceDiscoveryAgent is not None diff --git a/qtpy/tests/test_qtcharts.py b/qtpy/tests/test_qtcharts.py index 0531b169..4873e01f 100644 --- a/qtpy/tests/test_qtcharts.py +++ b/qtpy/tests/test_qtcharts.py @@ -3,9 +3,12 @@ from qtpy import PYSIDE2, PYSIDE6 -@pytest.mark.skipif(not (PYSIDE2 or PYSIDE6), reason="Only available by default in PySide") +@pytest.mark.skipif( + not (PYSIDE2 or PYSIDE6), reason="Only available by default in PySide" +) def test_qtcharts(): """Test the qtpy.QtCharts namespace""" - from qtpy import QtCharts + QtCharts = pytest.importorskip("qtpy.QtCharts") + assert QtCharts.QChart is not None assert QtCharts.QtCharts.QChart is not None diff --git a/qtpy/tests/test_qtconcurrent.py b/qtpy/tests/test_qtconcurrent.py new file mode 100644 index 00000000..7bd0c4ca --- /dev/null +++ b/qtpy/tests/test_qtconcurrent.py @@ -0,0 +1,16 @@ +import pytest +from packaging.version import parse +from qtpy import PYSIDE2, PYSIDE_VERSION + + +def test_qtconcurrent(): + """Test the qtpy.QtConcurrent namespace""" + QtConcurrent = pytest.importorskip("qtpy.QtConcurrent") + + assert QtConcurrent.QtConcurrent is not None + + if PYSIDE2 and parse(PYSIDE_VERSION) >= parse("5.15.2"): + assert QtConcurrent.QFutureQString is not None + assert QtConcurrent.QFutureVoid is not None + assert QtConcurrent.QFutureWatcherQString is not None + assert QtConcurrent.QFutureWatcherVoid is not None diff --git a/qtpy/tests/test_qtcore.py b/qtpy/tests/test_qtcore.py index 158d6863..7ff60a01 100644 --- a/qtpy/tests/test_qtcore.py +++ b/qtpy/tests/test_qtcore.py @@ -5,7 +5,15 @@ import pytest -from qtpy import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PYQT_VERSION, PYSIDE_VERSION, QtCore +from qtpy import ( + PYQT5, + PYQT6, + PYSIDE2, + PYSIDE6, + PYQT_VERSION, + PYSIDE_VERSION, + QtCore, +) from qtpy.tests.utils import not_using_conda diff --git a/qtpy/tests/test_qtdbus.py b/qtpy/tests/test_qtdbus.py index 2eaf4f5b..6b9a9ae2 100644 --- a/qtpy/tests/test_qtdbus.py +++ b/qtpy/tests/test_qtdbus.py @@ -1,10 +1,11 @@ import pytest +import sys from qtpy import PYSIDE2, PYSIDE6, PYQT5, PYQT6 -@pytest.mark.skipif(PYSIDE2 or PYSIDE6, reason="Not available in PySide2, not on CI for PySide6") + def test_qtdbus(): """Test the qtpy.QtDBus namespace""" - from qtpy import QtDBus + QtDBus = pytest.importorskip("qtpy.QtDBus") assert QtDBus.QDBusAbstractAdaptor is not None assert QtDBus.QDBusAbstractInterface is not None diff --git a/qtpy/tests/test_qtdesigner.py b/qtpy/tests/test_qtdesigner.py index 04b1374e..be957410 100644 --- a/qtpy/tests/test_qtdesigner.py +++ b/qtpy/tests/test_qtdesigner.py @@ -1,10 +1,12 @@ import pytest from qtpy import PYSIDE2 + @pytest.mark.skipif(PYSIDE2, reason="QtDesigner is not avalaible in PySide2") def test_qtdesigner(): """Test the qtpy.QtDesigner namespace.""" from qtpy import QtDesigner + assert QtDesigner.QAbstractExtensionFactory is not None assert QtDesigner.QAbstractExtensionManager is not None assert QtDesigner.QDesignerActionEditorInterface is not None diff --git a/qtpy/tests/test_qtlocation.py b/qtpy/tests/test_qtlocation.py index 012db7bc..bb599153 100644 --- a/qtpy/tests/test_qtlocation.py +++ b/qtpy/tests/test_qtlocation.py @@ -1,10 +1,15 @@ import pytest from qtpy import PYQT5, PYSIDE2 + @pytest.mark.skipif(not (PYQT5 or PYSIDE2), reason="Only available in Qt5 bindings") def test_qtlocation(): """Test the qtpy.QtLocation namespace""" from qtpy import QtLocation + + if PYSIDE2: + assert QtLocation.QGeoServiceProviderFactory is not None + assert QtLocation.QGeoCodeReply is not None assert QtLocation.QGeoCodingManager is not None assert QtLocation.QGeoCodingManagerEngine is not None @@ -16,7 +21,6 @@ def test_qtlocation(): assert QtLocation.QGeoRoutingManager is not None assert QtLocation.QGeoRoutingManagerEngine is not None assert QtLocation.QGeoServiceProvider is not None - #assert QtLocation.QGeoServiceProviderFactory is not None assert QtLocation.QPlace is not None assert QtLocation.QPlaceAttribute is not None assert QtLocation.QPlaceCategory is not None diff --git a/qtpy/tests/test_qtmacextras.py b/qtpy/tests/test_qtmacextras.py new file mode 100644 index 00000000..3e391d53 --- /dev/null +++ b/qtpy/tests/test_qtmacextras.py @@ -0,0 +1,19 @@ +import pytest +import sys + +from qtpy import PYQT6, PYSIDE2, PYSIDE6 +from qtpy.tests.utils import using_conda + + +@pytest.mark.skipif(PYQT6 or PYSIDE6, reason="Not availible on Qt6-based bindings") +@pytest.mark.skipif( + sys.platform != "darwin" or using_conda(), + reason="Only available in Qt5 bindings > 5.9 with pip on mac in CIs", +) +def test_qtmacextras(): + """Test the qtpy.QtMacExtras namespace""" + QtMacExtras = pytest.importorskip("qtpy.QtMacExtras") + + assert QtMacExtras.QMacPasteboardMime is not None + assert QtMacExtras.QMacToolBar is not None + assert QtMacExtras.QMacToolBarItem is not None diff --git a/qtpy/tests/test_qtmultimedia.py b/qtpy/tests/test_qtmultimedia.py index 6558b2ba..5da7ea4b 100644 --- a/qtpy/tests/test_qtmultimedia.py +++ b/qtpy/tests/test_qtmultimedia.py @@ -4,9 +4,11 @@ from qtpy import PYSIDE6, PYQT6 + @pytest.mark.skipif( - sys.platform.startswith('linux') and (PYSIDE6 or PYQT6), - reason="Needs to setup GStreamer on Linux") + sys.platform.startswith("linux") and (PYSIDE6 or PYQT6), + reason="Needs to setup GStreamer on Linux", +) def test_qtmultimedia(): """Test the qtpy.QtMultimedia namespace""" from qtpy import QtMultimedia diff --git a/qtpy/tests/test_qtmultimediawidgets.py b/qtpy/tests/test_qtmultimediawidgets.py index 4a7fca9a..9d6b099a 100644 --- a/qtpy/tests/test_qtmultimediawidgets.py +++ b/qtpy/tests/test_qtmultimediawidgets.py @@ -3,13 +3,13 @@ import pytest from qtpy import PYQT5, PYSIDE2 -from qtpy.tests.utils import using_conda +from qtpy.tests.utils import using_conda + +@pytest.mark.skipif(not (PYQT5 or PYSIDE2), reason="Only available in Qt5 bindings") @pytest.mark.skipif( - not (PYQT5 or PYSIDE2), reason="Only available in Qt5 bindings") -@pytest.mark.skipif( - using_conda(), - reason="Conda packages don't seem to include QtMultimedia") + using_conda(), reason="Conda packages don't seem to include QtMultimedia" +) def test_qtmultimediawidgets(): """Test the qtpy.QtMultimediaWidgets namespace""" from qtpy import QtMultimediaWidgets diff --git a/qtpy/tests/test_qtnetworkauth.py b/qtpy/tests/test_qtnetworkauth.py index e41a5db1..ba71d0ab 100644 --- a/qtpy/tests/test_qtnetworkauth.py +++ b/qtpy/tests/test_qtnetworkauth.py @@ -2,11 +2,15 @@ from qtpy import PYQT5, PYQT6, PYSIDE2 -@pytest.mark.skipif(PYQT5 or PYQT6 or PYSIDE2, - reason="Not available by default in PyQt. Not available for PySide2") + +@pytest.mark.skipif( + PYQT5 or PYQT6 or PYSIDE2, + reason="Not available by default in PyQt. Not available for PySide2", +) def test_qtnetworkauth(): """Test the qtpy.QtNetworkAuth namespace""" - from qtpy import QtNetworkAuth + QtNetworkAuth = pytest.importorskip("qtpy.QtNetworkAuth") + assert QtNetworkAuth.QAbstractOAuth is not None assert QtNetworkAuth.QAbstractOAuth2 is not None assert QtNetworkAuth.QAbstractOAuthReplyHandler is not None diff --git a/qtpy/tests/test_qtopengl.py b/qtpy/tests/test_qtopengl.py index b4b25120..567fed3b 100644 --- a/qtpy/tests/test_qtopengl.py +++ b/qtpy/tests/test_qtopengl.py @@ -1,6 +1,7 @@ import pytest from qtpy import PYSIDE2, PYSIDE6, PYQT5, PYQT6 + def test_qtopengl(): """Test the qtpy.QtOpenGL namespace""" from qtpy import QtOpenGL @@ -22,4 +23,3 @@ def test_qtopengl(): assert QtOpenGL.QOpenGLWindow is not None # We do not test for QOpenGLTimeMonitor or QOpenGLTimerQuery as # they are not present on some architectures such as armhf - diff --git a/qtpy/tests/test_qtopenglwidgets.py b/qtpy/tests/test_qtopenglwidgets.py index 3085c078..8cde7296 100644 --- a/qtpy/tests/test_qtopenglwidgets.py +++ b/qtpy/tests/test_qtopenglwidgets.py @@ -1,6 +1,7 @@ import pytest from qtpy import PYSIDE2, PYSIDE6, PYQT5, PYQT6 + @pytest.mark.skipif(PYSIDE2 or PYQT5, reason="Not available in PySide2/PyQt5") def test_qtopenglwidgets(): """Test the qtpy.QtOpenGLWidgets namespace""" diff --git a/qtpy/tests/test_qtpositioning.py b/qtpy/tests/test_qtpositioning.py index 5c691864..bc72f4cc 100644 --- a/qtpy/tests/test_qtpositioning.py +++ b/qtpy/tests/test_qtpositioning.py @@ -1,10 +1,12 @@ import pytest from qtpy import PYQT5, PYSIDE2 + @pytest.mark.skipif(not (PYQT5 or PYSIDE2), reason="Only available in Qt5 bindings") def test_qtpositioning(): """Test the qtpy.QtPositioning namespace""" from qtpy import QtPositioning + assert QtPositioning.QGeoAddress is not None assert QtPositioning.QGeoAreaMonitorInfo is not None assert QtPositioning.QGeoAreaMonitorSource is not None diff --git a/qtpy/tests/test_qtprintsupport.py b/qtpy/tests/test_qtprintsupport.py index 45770042..952909fb 100644 --- a/qtpy/tests/test_qtprintsupport.py +++ b/qtpy/tests/test_qtprintsupport.py @@ -7,6 +7,7 @@ from qtpy import QtPrintSupport from qtpy.tests.utils import not_using_conda + def test_qtprintsupport(): """Test the qtpy.QtPrintSupport namespace""" assert QtPrintSupport.QAbstractPrintDialog is not None @@ -30,8 +31,9 @@ def test_qprintdialog_exec_(): @pytest.mark.skipif( - sys.platform.startswith('linux') and not_using_conda(), - reason="Fatal Python error: Aborted on Linux CI when not using conda") + sys.platform.startswith("linux") and not_using_conda(), + reason="Fatal Python error: Aborted on Linux CI when not using conda", +) def test_qprintpreviewwidget_print_(qtbot): """Test qtpy.QtPrintSupport.QPrintPreviewWidget print_""" assert QtPrintSupport.QPrintPreviewWidget.print_ is not None diff --git a/qtpy/tests/test_qtpurchasing.py b/qtpy/tests/test_qtpurchasing.py new file mode 100644 index 00000000..d4c5173b --- /dev/null +++ b/qtpy/tests/test_qtpurchasing.py @@ -0,0 +1,10 @@ +import pytest + + +def test_qtpurchasing(): + """Test the qtpy.QtPurchasing namespace""" + QtPurchasing = pytest.importorskip("qtpy.QtPurchasing") + + assert QtPurchasing.QInAppProduct is not None + assert QtPurchasing.QInAppStore is not None + assert QtPurchasing.QInAppTransaction is not None diff --git a/qtpy/tests/test_qtqml.py b/qtpy/tests/test_qtqml.py index f2a229b9..8f8fe431 100644 --- a/qtpy/tests/test_qtqml.py +++ b/qtpy/tests/test_qtqml.py @@ -1,10 +1,12 @@ import pytest from qtpy import PYQT5, PYSIDE2 + @pytest.mark.skipif(not (PYQT5 or PYSIDE2), reason="Only available in Qt5 bindings") def test_qtqml(): """Test the qtpy.QtQml namespace""" from qtpy import QtQml + assert QtQml.QJSEngine is not None assert QtQml.QJSValue is not None assert QtQml.QJSValueIterator is not None diff --git a/qtpy/tests/test_qtquick.py b/qtpy/tests/test_qtquick.py index d21e2af8..e1e68f34 100644 --- a/qtpy/tests/test_qtquick.py +++ b/qtpy/tests/test_qtquick.py @@ -1,13 +1,26 @@ import pytest from qtpy import PYQT5, PYSIDE2 + @pytest.mark.skipif(not (PYQT5 or PYSIDE2), reason="Only available in Qt5 bindings") def test_qtquick(): """Test the qtpy.QtQuick namespace""" from qtpy import QtQuick - assert QtQuick.QQuickAsyncImageProvider is not None - if not PYSIDE2: + + if PYQT5: assert QtQuick.QQuickCloseEvent is not None + assert QtQuick.QSGFlatColorMaterial is not None + assert QtQuick.QSGImageNode is not None + assert QtQuick.QSGMaterial is not None + assert QtQuick.QSGMaterialShader is not None + assert QtQuick.QSGOpaqueTextureMaterial is not None + assert QtQuick.QSGRectangleNode is not None + assert QtQuick.QSGRenderNode is not None + assert QtQuick.QSGRendererInterface is not None + assert QtQuick.QSGTextureMaterial is not None + assert QtQuick.QSGVertexColorMaterial is not None + + assert QtQuick.QQuickAsyncImageProvider is not None assert QtQuick.QQuickFramebufferObject is not None assert QtQuick.QQuickImageProvider is not None assert QtQuick.QQuickImageResponse is not None @@ -24,28 +37,13 @@ def test_qtquick(): assert QtQuick.QSGClipNode is not None assert QtQuick.QSGDynamicTexture is not None assert QtQuick.QSGEngine is not None - if not PYSIDE2: - assert QtQuick.QSGFlatColorMaterial is not None assert QtQuick.QSGGeometry is not None assert QtQuick.QSGGeometryNode is not None - #assert QtQuick.QSGImageNode is not None - if not PYSIDE2: - assert QtQuick.QSGMaterial is not None - assert QtQuick.QSGMaterialShader is not None assert QtQuick.QSGMaterialType is not None assert QtQuick.QSGNode is not None assert QtQuick.QSGOpacityNode is not None - if not PYSIDE2: - assert QtQuick.QSGOpaqueTextureMaterial is not None - #assert QtQuick.QSGRectangleNode is not None - #assert QtQuick.QSGRenderNode is not None - #assert QtQuick.QSGRendererInterface is not None assert QtQuick.QSGSimpleRectNode is not None assert QtQuick.QSGSimpleTextureNode is not None assert QtQuick.QSGTexture is not None - if not PYSIDE2: - assert QtQuick.QSGTextureMaterial is not None assert QtQuick.QSGTextureProvider is not None assert QtQuick.QSGTransformNode is not None - if not PYSIDE2: - assert QtQuick.QSGVertexColorMaterial is not None diff --git a/qtpy/tests/test_qtquick3d.py b/qtpy/tests/test_qtquick3d.py new file mode 100644 index 00000000..ca614bd6 --- /dev/null +++ b/qtpy/tests/test_qtquick3d.py @@ -0,0 +1,10 @@ +import pytest + + +def test_qtquick3d(): + """Test the qtpy.QtQuick3D namespace""" + QtQuick3D = pytest.importorskip("qtpy.QtQuick3D") + + assert QtQuick3D.QQuick3D is not None + assert QtQuick3D.QQuick3DGeometry is not None + assert QtQuick3D.QQuick3DObject is not None diff --git a/qtpy/tests/test_qtquickcontrols2.py b/qtpy/tests/test_qtquickcontrols2.py new file mode 100644 index 00000000..a77ef001 --- /dev/null +++ b/qtpy/tests/test_qtquickcontrols2.py @@ -0,0 +1,8 @@ +import pytest + + +def test_qtquickcontrols2(): + """Test the qtpy.QtQuickControls2 namespace""" + QtQuickControls2 = pytest.importorskip("qtpy.QtQuickControls2") + + assert QtQuickControls2.QQuickStyle is not None diff --git a/qtpy/tests/test_qtquickwidgets.py b/qtpy/tests/test_qtquickwidgets.py index f055a308..53c1d208 100644 --- a/qtpy/tests/test_qtquickwidgets.py +++ b/qtpy/tests/test_qtquickwidgets.py @@ -1,8 +1,10 @@ import pytest from qtpy import PYQT5, PYSIDE2 + @pytest.mark.skipif(not (PYQT5 or PYSIDE2), reason="Only available in Qt5 bindings") def test_qtquickwidgets(): """Test the qtpy.QtQuickWidgets namespace""" from qtpy import QtQuickWidgets + assert QtQuickWidgets.QQuickWidget is not None diff --git a/qtpy/tests/test_qtremoteobjects.py b/qtpy/tests/test_qtremoteobjects.py index 88234b9d..4d91fb2f 100644 --- a/qtpy/tests/test_qtremoteobjects.py +++ b/qtpy/tests/test_qtremoteobjects.py @@ -1,6 +1,7 @@ import pytest from qtpy import PYSIDE2, PYSIDE6, PYQT5, PYQT6 + def test_qtremoteobjects(): """Test the qtpy.QtRemoteObjects namespace""" QtRemoteObjects = pytest.importorskip("qtpy.QtRemoteObjects") diff --git a/qtpy/tests/test_qtscxml.py b/qtpy/tests/test_qtscxml.py new file mode 100644 index 00000000..40033799 --- /dev/null +++ b/qtpy/tests/test_qtscxml.py @@ -0,0 +1,10 @@ +import pytest + + +def test_qtscxml(): + """Test the qtpy.QtScxml namespace""" + QtScxml = pytest.importorskip("qtpy.QtScxml") + + assert QtScxml.QScxmlCompiler is not None + assert QtScxml.QScxmlDynamicScxmlServiceFactory is not None + assert QtScxml.QScxmlExecutableContent is not None diff --git a/qtpy/tests/test_qtsensors.py b/qtpy/tests/test_qtsensors.py index b0d1f21f..3bc087bd 100644 --- a/qtpy/tests/test_qtsensors.py +++ b/qtpy/tests/test_qtsensors.py @@ -1,6 +1,7 @@ import pytest from qtpy import PYSIDE6, PYQT6 + def test_qtsensors(): """Test the qtpy.QtSensors namespace""" from qtpy import QtSensors @@ -8,4 +9,3 @@ def test_qtsensors(): assert QtSensors.QAccelerometer is not None assert QtSensors.QAccelerometerFilter is not None assert QtSensors.QAccelerometerReading is not None - diff --git a/qtpy/tests/test_qtserialport.py b/qtpy/tests/test_qtserialport.py index cb913427..a6cf5031 100644 --- a/qtpy/tests/test_qtserialport.py +++ b/qtpy/tests/test_qtserialport.py @@ -1,6 +1,7 @@ import pytest from qtpy import PYSIDE2 + @pytest.mark.skipif(PYSIDE2, reason="Not available in CI") def test_qtserialport(): """Test the qtpy.QtSerialPort namespace""" diff --git a/qtpy/tests/test_qtsql.py b/qtpy/tests/test_qtsql.py index f69e6c55..f9dcf96b 100644 --- a/qtpy/tests/test_qtsql.py +++ b/qtpy/tests/test_qtsql.py @@ -35,9 +35,11 @@ def test_qtsql(): # Following modules are not (yet) part of any wrapper: # QSqlDriverCreator, QSqlDriverPlugin + @pytest.mark.skipif( - sys.platform == 'win32' and PYSIDE2 and PYSIDE_VERSION.startswith('5.13'), - reason="SQLite driver unavailable on PySide 5.13.2 with Windows") + sys.platform == "win32" and PYSIDE2 and PYSIDE_VERSION.startswith("5.13"), + reason="SQLite driver unavailable on PySide 5.13.2 with Windows", +) def test_qtsql_members_aliases(database_connection): """ Test aliased methods over qtpy.QtSql members including: @@ -59,7 +61,7 @@ def test_qtsql_members_aliases(database_connection): id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, name VARCHAR(40) NOT NULL ) - """ + """, ) # Created table 'test' and 'sqlite_sequence' @@ -78,7 +80,8 @@ def test_qtsql_members_aliases(database_connection): select_table_query.prepare( """ SELECT * FROM test - """) + """ + ) select_table_query.exec_() record = select_table_query.record() assert not record.isEmpty() diff --git a/qtpy/tests/test_qtstatemachine.py b/qtpy/tests/test_qtstatemachine.py new file mode 100644 index 00000000..5fa986b0 --- /dev/null +++ b/qtpy/tests/test_qtstatemachine.py @@ -0,0 +1,16 @@ +import pytest + + +def test_qtstatemachine(): + """Test the qtpy.QtStateMachine namespace""" + QtStateMachine = pytest.importorskip("qtpy.QtStateMachine") + + assert QtStateMachine.QAbstractState is not None + assert QtStateMachine.QAbstractTransition is not None + assert QtStateMachine.QEventTransition is not None + assert QtStateMachine.QFinalState is not None + assert QtStateMachine.QHistoryState is not None + assert QtStateMachine.QKeyEventTransition is not None + assert QtStateMachine.QMouseEventTransition is not None + assert QtStateMachine.QSignalTransition is not None + assert QtStateMachine.QState is not None diff --git a/qtpy/tests/test_qtsvg.py b/qtpy/tests/test_qtsvg.py index 4b2a0bb9..298d9a93 100644 --- a/qtpy/tests/test_qtsvg.py +++ b/qtpy/tests/test_qtsvg.py @@ -1,6 +1,7 @@ import pytest from qtpy import PYSIDE6, PYQT6 + def test_qtsvg(): """Test the qtpy.QtSvg namespace""" from qtpy import QtSvg diff --git a/qtpy/tests/test_qtsvgwidgets.py b/qtpy/tests/test_qtsvgwidgets.py new file mode 100644 index 00000000..75339250 --- /dev/null +++ b/qtpy/tests/test_qtsvgwidgets.py @@ -0,0 +1,9 @@ +import pytest + + +def test_qtsvgwidgets(): + """Test the qtpy.QtSvgWidgets namespace""" + QtSvgWidgets = pytest.importorskip("qtpy.QtSvgWidgets") + + assert QtSvgWidgets.QGraphicsSvgItem is not None + assert QtSvgWidgets.QSvgWidget is not None diff --git a/qtpy/tests/test_qttexttospeech.py b/qtpy/tests/test_qttexttospeech.py index 4cc0daa1..f62bc3e0 100644 --- a/qtpy/tests/test_qttexttospeech.py +++ b/qtpy/tests/test_qttexttospeech.py @@ -3,8 +3,10 @@ from qtpy import PYQT5, PYSIDE2, PYQT_VERSION -@pytest.mark.skipif(not ((PYQT5 and version.parse(PYQT_VERSION) >= version.parse('5.15.1')) or PYSIDE2), - reason="Only available in Qt5 bindings (PyQt5 >= 5.15.1 or PySide2)") +@pytest.mark.skipif( + not ((PYQT5 and version.parse(PYQT_VERSION) >= version.parse("5.15.1")) or PYSIDE2), + reason="Only available in Qt5 bindings (PyQt5 >= 5.15.1 or PySide2)", +) def test_qttexttospeech(): """Test the qtpy.QtTextToSpeech namespace.""" from qtpy import QtTextToSpeech diff --git a/qtpy/tests/test_qtuitools.py b/qtpy/tests/test_qtuitools.py new file mode 100644 index 00000000..13ee4026 --- /dev/null +++ b/qtpy/tests/test_qtuitools.py @@ -0,0 +1,8 @@ +import pytest + + +def test_qtuitools(): + """Test the qtpy.QtUiTools namespace""" + QtUiTools = pytest.importorskip("qtpy.QtUiTools") + + assert QtUiTools.QUiLoader is not None diff --git a/qtpy/tests/test_qtwebchannel.py b/qtpy/tests/test_qtwebchannel.py index 4f33a03b..25e991f3 100644 --- a/qtpy/tests/test_qtwebchannel.py +++ b/qtpy/tests/test_qtwebchannel.py @@ -1,6 +1,7 @@ import pytest from qtpy import PYQT5, PYSIDE2 + @pytest.mark.skipif(not (PYQT5 or PYSIDE2), reason="Only available in Qt5 bindings") def test_qtwebchannel(): """Test the qtpy.QtWebChannel namespace""" @@ -8,4 +9,3 @@ def test_qtwebchannel(): assert QtWebChannel.QWebChannel is not None assert QtWebChannel.QWebChannelAbstractTransport is not None - diff --git a/qtpy/tests/test_qtwebenginecore.py b/qtpy/tests/test_qtwebenginecore.py index 591b0763..a00287ee 100644 --- a/qtpy/tests/test_qtwebenginecore.py +++ b/qtpy/tests/test_qtwebenginecore.py @@ -1,9 +1,9 @@ import pytest from qtpy import PYQT5, PYQT6, PYSIDE2, PYSIDE6 + def test_qtwebenginecore(): """Test the qtpy.QtWebEngineCore namespace""" - from qtpy import QtWebEngineCore + QtWebEngineCore = pytest.importorskip("qtpy.QtWebEngineCore") assert QtWebEngineCore.QWebEngineHttpRequest is not None - diff --git a/qtpy/tests/test_qtwebenginequick.py b/qtpy/tests/test_qtwebenginequick.py index 26074760..50b4bc56 100644 --- a/qtpy/tests/test_qtwebenginequick.py +++ b/qtpy/tests/test_qtwebenginequick.py @@ -1,10 +1,12 @@ import pytest from qtpy import PYQT5, PYQT6, PYSIDE2, PYSIDE6 + @pytest.mark.skipif(PYQT5 or PYSIDE2, reason="Only available in Qt6 bindings") def test_qtwebenginequick(): """Test the qtpy.QtWebEngineQuick namespace""" - from qtpy import QtWebEngineQuick + + QtWebEngineQuick = pytest.importorskip("qtpy.QtWebEngineQuick") + assert QtWebEngineQuick.QtWebEngineQuick is not None assert QtWebEngineQuick.QQuickWebEngineProfile is not None - diff --git a/qtpy/tests/test_qtwebenginewidgets.py b/qtpy/tests/test_qtwebenginewidgets.py index f9b3ac48..680de397 100644 --- a/qtpy/tests/test_qtwebenginewidgets.py +++ b/qtpy/tests/test_qtwebenginewidgets.py @@ -1,6 +1,7 @@ import pytest from qtpy import PYSIDE6, PYQT6 + @pytest.mark.skipif(PYSIDE6 or PYQT6, reason="Only available in Qt<6,>=6.2 bindings") def test_qtwebenginewidgets(): """Test the qtpy.QtWebEngineWidget namespace""" diff --git a/qtpy/tests/test_qtwebsockets.py b/qtpy/tests/test_qtwebsockets.py index 420aa866..52de7692 100644 --- a/qtpy/tests/test_qtwebsockets.py +++ b/qtpy/tests/test_qtwebsockets.py @@ -1,6 +1,7 @@ import pytest from qtpy import PYQT5, PYSIDE2 + @pytest.mark.skipif(not (PYQT5 or PYSIDE2), reason="Only available in Qt5 bindings") def test_qtwebsockets(): """Test the qtpy.QtWebSockets namespace""" diff --git a/qtpy/tests/test_qtwinextras.py b/qtpy/tests/test_qtwinextras.py index ec220104..f68a4b4b 100644 --- a/qtpy/tests/test_qtwinextras.py +++ b/qtpy/tests/test_qtwinextras.py @@ -7,14 +7,16 @@ from qtpy import PYQT6, PYSIDE2, PYSIDE6 from qtpy.tests.utils import using_conda -@pytest.mark.skipif( - PYQT6 or PYSIDE6, reason="Not availible on Qt6-based bindings") + +@pytest.mark.skipif(PYQT6 or PYSIDE6, reason="Not availible on Qt6-based bindings") @pytest.mark.skipif( sys.platform != "win32" or using_conda(), - reason="Only available in Qt5 bindings > 5.9 with pip on Windows in CIs") + reason="Only available in Qt5 bindings > 5.9 with pip on Windows in CIs", +) def test_qtwinextras(): """Test the qtpy.QtWinExtras namespace""" from qtpy import QtWinExtras + assert QtWinExtras.QWinJumpList is not None assert QtWinExtras.QWinJumpListCategory is not None assert QtWinExtras.QWinJumpListItem is not None @@ -29,4 +31,3 @@ def test_qtwinextras(): assert QtWinExtras.QWinColorizationChangeEvent is not None assert QtWinExtras.QWinCompositionChangeEvent is not None assert QtWinExtras.QWinEvent is not None - diff --git a/qtpy/tests/test_qtx11extras.py b/qtpy/tests/test_qtx11extras.py new file mode 100644 index 00000000..f1e683dc --- /dev/null +++ b/qtpy/tests/test_qtx11extras.py @@ -0,0 +1,9 @@ +import pytest + + +def test_qtwinextras(): + QtX11Extras = pytest.importorskip("qtpy.QtX11Extras") + + assert QtX11Extras is not None + # This module doesn't seem to contain any classes + # See https://doc.qt.io/qt-5/qtx11extras-module.html diff --git a/qtpy/tests/test_qtxml.py b/qtpy/tests/test_qtxml.py index 27d4f235..432d975b 100644 --- a/qtpy/tests/test_qtxml.py +++ b/qtpy/tests/test_qtxml.py @@ -1,5 +1,6 @@ import pytest + def test_qtxml(): """Test the qtpy.QtXml namespace""" from qtpy import QtXml diff --git a/qtpy/tests/test_qtxmlpatterns.py b/qtpy/tests/test_qtxmlpatterns.py index a2984879..c75d91d2 100644 --- a/qtpy/tests/test_qtxmlpatterns.py +++ b/qtpy/tests/test_qtxmlpatterns.py @@ -1,10 +1,12 @@ import pytest from qtpy import PYSIDE2, PYSIDE6, PYQT6 + @pytest.mark.skipif((PYSIDE6 or PYQT6), reason="not available with qt 6.0") def test_qtxmlpatterns(): """Test the qtpy.QtXmlPatterns namespace""" from qtpy import QtXmlPatterns + assert QtXmlPatterns.QAbstractMessageHandler is not None assert QtXmlPatterns.QAbstractUriResolver is not None assert QtXmlPatterns.QAbstractXmlNodeModel is not None diff --git a/qtpy/tests/test_shiboken.py b/qtpy/tests/test_shiboken.py new file mode 100644 index 00000000..4920fa55 --- /dev/null +++ b/qtpy/tests/test_shiboken.py @@ -0,0 +1,12 @@ +import pytest + + +def test_shiboken(): + """Test the qtpy.shiboken namespace""" + shiboken = pytest.importorskip("qtpy.shiboken") + + assert shiboken.isValid is not None + assert shiboken.wrapInstance is not None + assert shiboken.getCppPointer is not None + assert shiboken.delete is not None + assert shiboken.dump is not None diff --git a/qtpy/tests/test_sip.py b/qtpy/tests/test_sip.py new file mode 100644 index 00000000..620d1fdf --- /dev/null +++ b/qtpy/tests/test_sip.py @@ -0,0 +1,25 @@ +import pytest + + +def test_sip(): + """Test the qtpy.sip namespace""" + sip = pytest.importorskip("qtpy.sip") + + assert sip.assign is not None + assert sip.cast is not None + assert sip.delete is not None + assert sip.dump is not None + assert sip.enableautoconversion is not None + assert sip.isdeleted is not None + assert sip.ispycreated is not None + assert sip.ispyowned is not None + assert sip.setdeleted is not None + assert sip.settracemask is not None + assert sip.simplewrapper is not None + assert sip.transferback is not None + assert sip.transferto is not None + assert sip.unwrapinstance is not None + assert sip.voidptr is not None + assert sip.wrapinstance is not None + assert sip.wrapper is not None + assert sip.wrappertype is not None