Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6da1ce6

Browse files
committed
update vendored QtPy
1 parent 4c295c3 commit 6da1ce6

15 files changed

+230
-55
lines changed

winpython/_vendor/qtpy/QtCharts.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
if PYQT5:
1313
try:
1414
from PyQt5.QtChart import *
15-
except ImportError:
16-
raise PythonQtError('The QtChart module was not found. '
17-
'It needs to be installed separately for PyQt5.')
15+
except ImportError as error:
16+
raise PythonQtError(
17+
'The QtChart module was not found. '
18+
'It needs to be installed separately for PyQt5.'
19+
) from error
1820
elif PYQT6:
1921
try:
2022
from PyQt6.QtCharts import *
21-
except ImportError:
22-
raise PythonQtError('The QtCharts module was not found. '
23-
'It needs to be installed separately for PyQt6.')
23+
except ImportError as error:
24+
raise PythonQtError(
25+
'The QtCharts module was not found. '
26+
'It needs to be installed separately for PyQt6.'
27+
) from error
2428
elif PYSIDE6:
2529
from PySide6.QtCharts import *
2630
elif PYSIDE2:

winpython/_vendor/qtpy/QtCore.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,34 @@
88
"""
99
Provides QtCore classes and functions.
1010
"""
11-
1211
from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, PythonQtError
1312

13+
1414
if PYQT6:
15+
from PyQt6 import QtCore
1516
from PyQt6.QtCore import *
1617
from PyQt6.QtCore import pyqtSignal as Signal
18+
from PyQt6.QtCore import pyqtBoundSignal as SignalInstance
19+
from PyQt6.QtCore import pyqtSlot as Slot
20+
from PyQt6.QtCore import pyqtProperty as Property
1721
from PyQt6.QtCore import QT_VERSION_STR as __version__
1822

23+
# For issue #153
24+
from PyQt6.QtCore import QDateTime
25+
QDateTime.toPython = QDateTime.toPyDateTime
26+
27+
# Map missing methods
1928
QCoreApplication.exec_ = QCoreApplication.exec
2029
QEventLoop.exec_ = QEventLoop.exec
2130
QThread.exec_ = QThread.exec
2231

32+
# Those are imported from `import *`
33+
del pyqtSignal, pyqtBoundSignal, pyqtSlot, pyqtProperty, QT_VERSION_STR
34+
35+
# Allow unscoped access for enums inside the QtCore module
36+
from .enums_compat import promote_enums
37+
promote_enums(QtCore)
38+
del QtCore
2339
elif PYQT5:
2440
from PyQt5.QtCore import *
2541
from PyQt5.QtCore import pyqtSignal as Signal
@@ -36,21 +52,27 @@
3652
del pyqtSignal, pyqtBoundSignal, pyqtSlot, pyqtProperty, QT_VERSION_STR
3753

3854
elif PYSIDE6:
39-
from PySide6.QtCore import *
40-
import PySide6.QtCore
41-
__version__ = PySide6.QtCore.__version__
55+
from PySide6.QtCore import *
56+
import PySide6.QtCore
57+
__version__ = PySide6.QtCore.__version__
58+
59+
# obsolete in qt6
60+
Qt.BackgroundColorRole = Qt.BackgroundRole
61+
Qt.TextColorRole = Qt.ForegroundRole
62+
Qt.MidButton = Qt.MiddleButton
4263

43-
# obsolete in qt6
44-
Qt.BackgroundColorRole = Qt.BackgroundRole
45-
Qt.TextColorRole = Qt.ForegroundRole
46-
Qt.MidButton = Qt.MiddleButton
64+
# Map DeprecationWarning methods
65+
QCoreApplication.exec_ = QCoreApplication.exec
66+
QEventLoop.exec_ = QEventLoop.exec
67+
QThread.exec_ = QThread.exec
68+
QTextStreamManipulator.exec_ = QTextStreamManipulator.exec
4769

4870
elif PYSIDE2:
4971
from PySide2.QtCore import *
5072

51-
try: # may be limited to PySide-5.11a1 only
73+
try: # may be limited to PySide-5.11a1 only
5274
from PySide2.QtGui import QStringListModel
53-
except:
75+
except Exception:
5476
pass
5577

5678
import PySide2.QtCore

winpython/_vendor/qtpy/QtGui.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,32 @@
88
"""
99
Provides QtGui classes and functions.
1010
"""
11-
import warnings
12-
1311
from . import PYQT6, PYQT5, PYSIDE2, PYSIDE6, PythonQtError
1412

1513

1614
if PYQT6:
15+
from PyQt6 import QtGui
1716
from PyQt6.QtGui import *
17+
18+
# Map missing/renamed methods
1819
QDrag.exec_ = QDrag.exec
1920
QGuiApplication.exec_ = QGuiApplication.exec
2021
QTextDocument.print_ = QTextDocument.print
22+
23+
# Allow unscoped access for enums inside the QtGui module
24+
from .enums_compat import promote_enums
25+
promote_enums(QtGui)
26+
del QtGui
2127
elif PYQT5:
2228
from PyQt5.QtGui import *
2329
elif PYSIDE2:
2430
from PySide2.QtGui import *
2531
elif PYSIDE6:
2632
from PySide6.QtGui import *
2733
QFontMetrics.width = QFontMetrics.horizontalAdvance
34+
35+
# Map DeprecationWarning methods
36+
QDrag.exec_ = QDrag.exec
37+
QGuiApplication.exec_ = QGuiApplication.exec
2838
else:
2939
raise PythonQtError('No Qt bindings could be found')

winpython/_vendor/qtpy/QtPrintSupport.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
QPrintPreviewWidget.print_ = QPrintPreviewWidget.print
2121
elif PYSIDE6:
2222
from PySide6.QtPrintSupport import *
23+
# Map DeprecationWarning methods
24+
QPageSetupDialog.exec_ = QPageSetupDialog.exec
25+
QPrintDialog.exec_ = QPrintDialog.exec
2326
elif PYSIDE2:
2427
from PySide2.QtPrintSupport import *
2528
else:

winpython/_vendor/qtpy/QtSql.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
QSqlResult.exec_ = QSqlResult.exec
1919
elif PYSIDE6:
2020
from PySide6.QtSql import *
21+
# Map DeprecationWarning methods
22+
QSqlDatabase.exec_ = QSqlDatabase.exec
23+
QSqlQuery.exec_ = QSqlQuery.exec
24+
QSqlResult.exec_ = QSqlResult.exec
2125
elif PYSIDE2:
2226
from PySide2.QtSql import *
2327
else:

winpython/_vendor/qtpy/QtTest.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@
1212
from . import PYQT5, PYQT6, PYSIDE6, PYSIDE2, PythonQtError
1313

1414
if PYQT6:
15-
from PyQt6.QtTest import QTest
15+
from PyQt6 import QtTest
16+
from PyQt6.QtTest import *
17+
18+
# Allow unscoped access for enums inside the QtTest module
19+
from .enums_compat import promote_enums
20+
promote_enums(QtTest)
21+
del QtTest
1622
elif PYQT5:
17-
from PyQt5.QtTest import QTest
23+
from PyQt5.QtTest import *
1824
elif PYSIDE6:
19-
from PySide6.QtTest import QTest
25+
from PySide6.QtTest import *
2026
elif PYSIDE2:
21-
from PySide2.QtTest import QTest
27+
from PySide2.QtTest import *
2228
else:
2329
raise PythonQtError('No Qt bindings could be found')
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -----------------------------------------------------------------------------
2+
# Copyright © 2009- The Spyder Development Team
3+
#
4+
# Licensed under the terms of the MIT License
5+
# (see LICENSE.txt for details)
6+
# -----------------------------------------------------------------------------
7+
"""Provides QtTextToSpeech classes and functions."""
8+
9+
from . import PYQT5, PYSIDE2, PythonQtError
10+
11+
if PYQT5:
12+
from PyQt5.QtTextToSpeech import *
13+
elif PYSIDE2:
14+
from PySide2.QtTextToSpeech import *
15+
else:
16+
raise PythonQtError('No Qt bindings could be found')

winpython/_vendor/qtpy/QtWidgets.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,47 @@
88
"""
99
Provides widget classes and functions.
1010
"""
11-
1211
from . import PYQT5, PYQT6, PYSIDE2, PYSIDE6, PythonQtError
13-
from ._patch.qheaderview import introduce_renamed_methods_qheaderview
12+
1413

1514
if PYQT6:
15+
from PyQt6 import QtWidgets
1616
from PyQt6.QtWidgets import *
1717
from PyQt6.QtGui import QAction, QActionGroup, QShortcut
1818
from PyQt6.QtOpenGLWidgets import QOpenGLWidget
19+
20+
# Map missing/renamed methods
1921
QTextEdit.setTabStopWidth = QTextEdit.setTabStopDistance
2022
QTextEdit.tabStopWidth = QTextEdit.tabStopDistance
23+
QTextEdit.print_ = QTextEdit.print
2124
QPlainTextEdit.setTabStopWidth = QPlainTextEdit.setTabStopDistance
2225
QPlainTextEdit.tabStopWidth = QPlainTextEdit.tabStopDistance
26+
QPlainTextEdit.print_ = QPlainTextEdit.print
2327
QApplication.exec_ = QApplication.exec
2428
QDialog.exec_ = QDialog.exec
2529
QMenu.exec_ = QMenu.exec
26-
QTextEdit.print_ = QTextEdit.print
27-
QPlainTextEdit.print_ = QPlainTextEdit.print
30+
31+
# Allow unscoped access for enums inside the QtWidgets module
32+
from .enums_compat import promote_enums
33+
promote_enums(QtWidgets)
34+
del QtWidgets
2835
elif PYQT5:
2936
from PyQt5.QtWidgets import *
3037
elif PYSIDE6:
3138
from PySide6.QtWidgets import *
3239
from PySide6.QtGui import QAction, QActionGroup, QShortcut
3340
from PySide6.QtOpenGLWidgets import QOpenGLWidget
41+
42+
# Map missing/renamed methods
3443
QTextEdit.setTabStopWidth = QTextEdit.setTabStopDistance
3544
QTextEdit.tabStopWidth = QTextEdit.tabStopDistance
3645
QPlainTextEdit.setTabStopWidth = QPlainTextEdit.setTabStopDistance
3746
QPlainTextEdit.tabStopWidth = QPlainTextEdit.tabStopDistance
47+
48+
# Map DeprecationWarning methods
49+
QApplication.exec_ = QApplication.exec
50+
QDialog.exec_ = QDialog.exec
51+
QMenu.exec_ = QMenu.exec
3852
elif PYSIDE2:
3953
from PySide2.QtWidgets import *
4054
else:

winpython/_vendor/qtpy/__init__.py

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,15 @@
6161
import warnings
6262

6363
# Version of QtPy
64-
from ._version import __version__
64+
__version__ = '2.0.0.dev1'
6565

6666

6767
class PythonQtError(RuntimeError):
68-
"""Error raise if no bindings could be selected."""
69-
pass
68+
"""Error raised if no bindings could be selected."""
7069

7170

7271
class 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
8987
PYSIDE6_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
9299
binding_specified = QT_API in os.environ
93100

@@ -99,26 +106,30 @@ class PythonQtWarning(Warning):
99106
assert API in (PYQT5_API + PYQT6_API + PYSIDE2_API + PYSIDE6_API)
100107

101108
is_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

117127
if 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):
197207
try:
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

Comments
 (0)