qts

The top level package exposes the basic functionality of the qts library.

qts.__version__: str = 'v0.3'

The qts version string.

Selecting a wrapper

A Qt wrapper must be chosen before leveraging the qts compatibility features. qts is notified of the choice by a call to qts.set_wrapper(). qts.autoset_wrapper() automatically chooses and sets an available wrapper. In any case, qts checks for wrappers that have already been imported. The setting of a wrapper will fail if only unsupported wrappers are already imported. The setting also fails if a supported wrapper other than the one requested is already imported.

qts.set_wrapper(wrapper: qts._core.Wrapper) None[source]

Set the wrapper you want to back the Qt modules accessed through qts.

Raises
qts.autoset_wrapper() None[source]

Automatically choose and set the wrapper used to back the Qt modules accessed through qts. If the environment variable QTS_WRAPPER is set to a name of a supported wrapper then that wrapper will be used. The lookup is case insensitive. If a supported wrapper has already been imported then it will be used.

Raises

qts.InvalidWrapperError – When an unsupported wrapper name is specified in the QTS_WRAPPER environment variable.

Supported wrappers

The objects representing the supported wrappers are directly available. Each is an instance of the qts.Wrapper class. The full list of supported wrappers is available as qts._core.supported_wrappers.

qts._core.pyqt_5_wrapper = Wrapper(family='PyQt', name='PyQt5', major_version=5, module_name='PyQt5')

The PyQt/Qt5 wrapper object.

qts._core.pyqt_6_wrapper = Wrapper(family='PyQt', name='PyQt6', major_version=6, module_name='PyQt6')

The PyQt/Qt6 wrapper object.

qts._core.pyside_5_wrapper = Wrapper(family='PySide', name='PySide2', major_version=5, module_name='PySide2')

The PySide/Qt5 wrapper object.

qts._core.pyside_6_wrapper = Wrapper(family='PySide', name='PySide6', major_version=6, module_name='PySide6')

The PySide/Qt6 wrapper object.

qts._core.supported_wrappers = [Wrapper(family='PySide', name='PySide6', major_version=6, module_name='PySide6'), Wrapper(family='PyQt', name='PyQt6', major_version=6, module_name='PyQt6'), Wrapper(family='PySide', name='PySide2', major_version=5, module_name='PySide2'), Wrapper(family='PyQt', name='PyQt5', major_version=5, module_name='PyQt5')]

A list of all the supported wrapper objects.

class qts.Wrapper(family: str, name: str, major_version: int, module_name: str)[source]

Bases: object

A representation of a specific wrapper that can be used to access a specific version of Qt.

family: str

The wrapper family. "PyQt" or "PySide".

name: str

The name of the specific wrapper, including the version number. Such as "PySide6".

major_version: int

The major version of the wrapped Qt library. Such as 6.

module_name: str

The name used to import the module. Such as "PySide6".

Available wrappers

Not all supported wrappers will be available in every case.

qts.available_wrapper(wrappers: Optional[Iterable[qts._core.Wrapper]] = None) qts._core.Wrapper[source]

Get the available wrapper when there is only one.

Returns

The wrapper object for the single available wrapper.

Raises
qts.available_wrappers(wrappers: Optional[Iterable[qts._core.Wrapper]] = None) Sequence[qts._core.Wrapper][source]

Get a sequence of the wrappers that are available for use. If wrappers is passed, only wrappers that are both available and in the passed iterable will be returned. Availability is checked both by installation metadata and any wrappers that have already been imported.

Returns

The wrappers that are installed and available for use.

qts.an_available_wrapper(wrappers: Optional[Iterable[qts._core.Wrapper]] = None) qts._core.Wrapper[source]

Get an available wrapper when there is one or more available.

Parameters

wrappers – The wrappers to consider. All if not specified.

Returns

The wrapper object for the single available wrapper.

Raises

qts.NoWrapperAvailableError – When no wrappers are available.

qts.wrapper_by_name(name: str) qts._core.Wrapper[source]

Get a wrapper object by its name. The name is checked case insensitively.

Returns

The wrapper that goes by the passed name.

Present configuration

You can directly query the present wrapper object multiple ways. The wrapper object can be retrieved directly through qts.wrapper. In some cases it is more useful to simply check if a specific wrapper is selected. The qts.is_* values are helpful for this. In particular, mypy is able to understand booleans via the command line arguments --always-false and --always-true. The Command line interface can be used to help generate the relevant options to pass to mypy.

qts.wrapper: Optional[qts._core.Wrapper]

The presently active wrapper. None if no wrapper is set.

qts.is_pyqt_5_wrapper: bool = False

True if the PyQt/Qt5 wrapper is active.

qts.is_pyqt_6_wrapper: bool = False

True if the PyQt/Qt6 wrapper is active.

qts.is_pyside_5_wrapper: bool = True

True if the PySide/Qt5 wrapper is active.

qts.is_pyside_6_wrapper: bool = False

True if the PySide/Qt6 wrapper is active.

Exceptions

See Exceptions.