6161import warnings
6262
6363# Version of QtPy
64- from . _version import __version__
64+ __version__ = '2.0.0.dev1'
6565
6666
6767class PythonQtError (RuntimeError ):
68- """Error raise if no bindings could be selected."""
69- pass
68+ """Error raised if no bindings could be selected."""
7069
7170
7271class PythonQtWarning (Warning ):
7372 """Warning if some features are not implemented in a binding."""
74- pass
7573
7674
7775# Qt API environment variable name
@@ -88,6 +86,15 @@ class PythonQtWarning(Warning):
8886# Names of the expected PySide6 api
8987PYSIDE6_API = ['pyside6' ]
9088
89+ # Minimum supported versions of Qt and the bindings
90+ QT5_VERSION_MIN = PYQT5_VERSION_MIN = '5.9.0'
91+ PYSIDE2_VERSION_MIN = '5.12.0'
92+ QT6_VERSION_MIN = PYQT6_VERSION_MIN = PYSIDE6_VERSION_MIN = '6.2.0'
93+
94+ QT_VERSION_MIN = QT5_VERSION_MIN
95+ PYQT_VERSION_MIN = PYQT5_VERSION_MIN
96+ PYSIDE_VERISION_MIN = PYSIDE2_VERSION_MIN
97+
9198# Detecting if a binding was specified by the user
9299binding_specified = QT_API in os .environ
93100
@@ -99,26 +106,30 @@ class PythonQtWarning(Warning):
99106assert API in (PYQT5_API + PYQT6_API + PYSIDE2_API + PYSIDE6_API )
100107
101108is_old_pyqt = is_pyqt46 = False
102- PYQT5 = True
103- PYQT6 = PYSIDE2 = PYSIDE6 = False
109+ QT5 = PYQT5 = True
110+ QT4 = QT6 = PYQT4 = PYQT6 = PYSIDE = PYSIDE2 = PYSIDE6 = False
111+
112+ PYQT_VERSION = None
113+ PYSIDE_VERSION = None
114+ QT_VERSION = None
104115
105- # When `FORCE_QT_API` is set, we disregard
106- # any previously imported python bindings.
107- if 'FORCE_QT_API' in os .environ :
116+ # Unless `FORCE_QT_API` is set, use previously imported Qt Python bindings
117+ if not os .environ .get ('FORCE_QT_API' ):
108118 if 'PyQt6' in sys .modules :
109119 API = initial_api if initial_api in PYQT6_API else 'pyqt6'
110120 elif 'PyQt5' in sys .modules :
111121 API = initial_api if initial_api in PYQT5_API else 'pyqt5'
112122 elif 'PySide6' in sys .modules :
113- API = initial_api if initial_api in PYSIDE6_API else 'pyside6'
123+ API = initial_api if initial_api in PYSIDE6_API else 'pyside6'
114124 elif 'PySide2' in sys .modules :
115125 API = initial_api if initial_api in PYSIDE2_API else 'pyside2'
116126
117127if API in PYQT5_API :
118128 try :
119129 from PyQt5 .QtCore import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore
120130 from PyQt5 .QtCore import QT_VERSION_STR as QT_VERSION # analysis:ignore
121- PYSIDE_VERSION = None
131+
132+ QT5 = PYQT5 = True
122133
123134 if sys .platform == 'darwin' :
124135 macos_version = parse (platform .mac_ver ()[0 ])
@@ -143,9 +154,10 @@ class PythonQtWarning(Warning):
143154 try :
144155 from PyQt6 .QtCore import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore
145156 from PyQt6 .QtCore import QT_VERSION_STR as QT_VERSION # analysis:ignore
146- PYSIDE_VERSION = None
147- PYQT5 = False
148- PYQT6 = True
157+
158+ QT5 = PYQT5 = False
159+ QT6 = PYQT6 = True
160+
149161 except ImportError :
150162 API = os .environ ['QT_API' ] = 'pyside2'
151163
@@ -155,9 +167,8 @@ class PythonQtWarning(Warning):
155167 from PySide2 import __version__ as PYSIDE_VERSION # analysis:ignore
156168 from PySide2 .QtCore import __version__ as QT_VERSION # analysis:ignore
157169
158- PYQT_VERSION = None
159170 PYQT5 = False
160- PYSIDE2 = True
171+ QT5 = PYSIDE2 = True
161172
162173 if sys .platform == 'darwin' :
163174 macos_version = parse (platform .mac_ver ()[0 ])
@@ -177,9 +188,8 @@ class PythonQtWarning(Warning):
177188 from PySide6 import __version__ as PYSIDE_VERSION # analysis:ignore
178189 from PySide6 .QtCore import __version__ as QT_VERSION # analysis:ignore
179190
180- PYQT_VERSION = None
181- PYQT5 = False
182- PYSIDE6 = True
191+ QT5 = PYQT5 = False
192+ QT6 = PYSIDE6 = True
183193
184194 except ImportError :
185195 API = os .environ ['QT_API' ] = 'pyqt5'
@@ -197,6 +207,35 @@ class PythonQtWarning(Warning):
197207try :
198208 # QtDataVisualization backward compatibility (QtDataVisualization vs. QtDatavisualization)
199209 # Only available for Qt5 bindings > 5.9 on Windows
200- from . import QtDataVisualization as QtDatavisualization
201- except ImportError :
210+ from . import QtDataVisualization as QtDatavisualization # analysis:ignore
211+ except ( ImportError , PythonQtError ) :
202212 pass
213+
214+
215+ def _warn_old_minor_version (name , old_version , min_version ):
216+ """Warn if using a Qt or binding version no longer supported by QtPy."""
217+ warning_message = (
218+ "{name} version {old_version} is not supported by QtPy. "
219+ "To ensure your application works correctly with QtPy, "
220+ "please upgrade to {name} {min_version} or later." .format (
221+ name = name , old_version = old_version , min_version = min_version ))
222+ warnings .warn (warning_message , PythonQtWarning )
223+
224+
225+ # Warn if using an End of Life or unsupported Qt API/binding minor version
226+ if QT_VERSION :
227+ if QT5 and (parse (QT_VERSION ) < parse (QT5_VERSION_MIN )):
228+ _warn_old_minor_version ('Qt5' , QT_VERSION , QT5_VERSION_MIN )
229+ elif QT6 and (parse (QT_VERSION ) < parse (QT6_VERSION_MIN )):
230+ _warn_old_minor_version ('Qt6' , QT_VERSION , QT6_VERSION_MIN )
231+
232+ if PYQT_VERSION :
233+ if PYQT5 and (parse (PYQT_VERSION ) < parse (PYQT5_VERSION_MIN )):
234+ _warn_old_minor_version ('PyQt5' , PYQT_VERSION , PYQT5_VERSION_MIN )
235+ elif PYQT6 and (parse (PYQT_VERSION ) < parse (PYQT6_VERSION_MIN )):
236+ _warn_old_minor_version ('PyQt6' , PYQT_VERSION , PYQT6_VERSION_MIN )
237+ elif PYSIDE_VERSION :
238+ if PYSIDE2 and (parse (PYSIDE_VERSION ) < parse (PYSIDE2_VERSION_MIN )):
239+ _warn_old_minor_version ('PySide2' , PYSIDE_VERSION , PYSIDE2_VERSION_MIN )
240+ elif PYSIDE6 and (parse (PYSIDE_VERSION ) < parse (PYSIDE6_VERSION_MIN )):
241+ _warn_old_minor_version ('PySide6' , PYSIDE_VERSION , PYSIDE6_VERSION_MIN )
0 commit comments