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

Skip to content

Commit d561d31

Browse files
authored
Merge pull request #653 from stonebig/master
QtPy vendored fix
2 parents 4beafd0 + d2a47a2 commit d561d31

17 files changed

+228
-136
lines changed

winpython/_vendor/qtpy/QtCore.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
del pyqtSignal, pyqtSlot, pyqtProperty, QT_VERSION_STR
2525
elif PYSIDE2:
2626
from PySide2.QtCore import *
27+
try: # may be limited to PySide-5.11a1 only
28+
from PySide2.QtGui import QStringListModel
29+
except:
30+
pass
2731
elif PYQT4:
2832
from PyQt4.QtCore import *
2933
# Those are things we inherited from Spyder that fix crazy crashes under
@@ -58,6 +62,7 @@ class QStandardPaths():
5862
HomeLocation = _QDesktopServices.HomeLocation
5963
DataLocation = _QDesktopServices.DataLocation
6064
CacheLocation = _QDesktopServices.CacheLocation
65+
writableLocation = _QDesktopServices.storageLocation
6166

6267
# Those are imported from `import *`
6368
del pyqtSignal, pyqtSlot, pyqtProperty, QT_VERSION_STR, qInstallMsgHandler
@@ -88,6 +93,7 @@ class QStandardPaths():
8893
HomeLocation = _QDesktopServices.HomeLocation
8994
DataLocation = _QDesktopServices.DataLocation
9095
CacheLocation = _QDesktopServices.CacheLocation
96+
writableLocation = _QDesktopServices.storageLocation
9197

9298
import PySide.QtCore
9399
__version__ = PySide.QtCore.__version__

winpython/_vendor/qtpy/QtGui.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
exposed here. Therefore, you need to treat/use this package as if it were
1313
the ``PyQt5.QtGui`` module.
1414
"""
15+
import warnings
1516

1617
from . import PYQT5, PYQT4, PYSIDE, PYSIDE2, PythonQtError
1718

@@ -75,10 +76,21 @@
7576
from PyQt4.QtGui import QDesktopServices as _QDesktopServices
7677

7778
class QDesktopServices():
78-
openUrl = _QDesktopServices.openUrl
79-
setUrlHandler = _QDesktopServices.setUrlHandler
80-
unsetUrlHandler = _QDesktopServices.unsetUrlHandler
79+
openUrl = _QDesktopServices.openUrl
80+
setUrlHandler = _QDesktopServices.setUrlHandler
81+
unsetUrlHandler = _QDesktopServices.unsetUrlHandler
8182

83+
def __getattr__(self, name):
84+
attr = getattr(_QDesktopServices, name)
85+
86+
new_name = name
87+
if name == 'storageLocation':
88+
new_name = 'writableLocation'
89+
warnings.warn(("Warning QDesktopServices.{} is deprecated in Qt5"
90+
"we recommend you use QDesktopServices.{} instead").format(name, new_name),
91+
DeprecationWarning)
92+
return attr
93+
QDesktopServices = QDesktopServices()
8294

8395
elif PYSIDE:
8496
from PySide.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap,
@@ -126,8 +138,20 @@ class QDesktopServices():
126138
from PySide.QtGui import QDesktopServices as _QDesktopServices
127139

128140
class QDesktopServices():
129-
openUrl = _QDesktopServices.openUrl
130-
setUrlHandler = _QDesktopServices.setUrlHandler
131-
unsetUrlHandler = _QDesktopServices.unsetUrlHandler
141+
openUrl = _QDesktopServices.openUrl
142+
setUrlHandler = _QDesktopServices.setUrlHandler
143+
unsetUrlHandler = _QDesktopServices.unsetUrlHandler
144+
145+
def __getattr__(self, name):
146+
attr = getattr(_QDesktopServices, name)
147+
148+
new_name = name
149+
if name == 'storageLocation':
150+
new_name = 'writableLocation'
151+
warnings.warn(("Warning QDesktopServices.{} is deprecated in Qt5"
152+
"we recommend you use QDesktopServices.{} instead").format(name, new_name),
153+
DeprecationWarning)
154+
return attr
155+
QDesktopServices = QDesktopServices()
132156
else:
133157
raise PythonQtError('No Qt bindings could be found')

winpython/_vendor/qtpy/QtHelp.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright © 2009- The Spyder Development Team
4+
#
5+
# Licensed under the terms of the MIT License
6+
# (see LICENSE.txt for details)
7+
8+
"""QtHelp Wrapper."""
9+
10+
import warnings
11+
12+
from . import PYQT5
13+
from . import PYQT4
14+
from . import PYSIDE
15+
from . import PYSIDE2
16+
17+
if PYQT5:
18+
from PyQt5.QtHelp import *
19+
elif PYSIDE2:
20+
from PySide2.QtHelp import *
21+
elif PYQT4:
22+
from PyQt4.QtHelp import *
23+
elif PYSIDE:
24+
from PySide.QtHelp import *

winpython/_vendor/qtpy/QtMultimedia.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
import warnings
2+
13
from . import PYQT5
24
from . import PYQT4
35
from . import PYSIDE
46
from . import PYSIDE2
57

6-
78
if PYQT5:
89
from PyQt5.QtMultimedia import *
910
elif PYSIDE2:
10-
# Current wheels don't have this module
11-
# from PySide2.QtMultimedia import *
12-
pass
11+
from PySide2.QtMultimedia import *
1312
elif PYQT4:
1413
from PyQt4.QtMultimedia import *
1514
from PyQt4.QtGui import QSound

winpython/_vendor/qtpy/QtSql.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
# -----------------------------------------------------------------------------
3+
# Copyright © 2009- The Spyder Development Team
4+
#
5+
# Licensed under the terms of the MIT License
6+
# (see LICENSE.txt for details)
7+
# -----------------------------------------------------------------------------
8+
"""Provides QtSql classes and functions."""
9+
10+
# Local imports
11+
from . import PYQT5, PYSIDE2, PYQT4, PYSIDE, PythonQtError
12+
13+
if PYQT5:
14+
from PyQt5.QtSql import *
15+
elif PYSIDE2:
16+
from PySide2.QtSql import *
17+
elif PYQT4:
18+
from PyQt4.QtSql import *
19+
elif PYSIDE:
20+
from PySide.QtSql import *
21+
else:
22+
raise PythonQtError('No Qt bindings could be found')
23+
24+
del PYQT4, PYQT5, PYSIDE, PYSIDE2

winpython/_vendor/qtpy/__init__.py

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
**QtPy** is a shim over the various Python Qt bindings. It is used to write
1111
Qt binding indenpendent libraries or applications.
1212
13-
The shim will automatically select the first available API (PyQt5, PyQt4 and
14-
finally PySide).
13+
If one of the APIs has already been imported, then it will be used.
1514
16-
You can force the use of one specific bindings (e.g. if your application is
17-
using one specific bindings and you need to use library that use QtPy) by
18-
setting up the ``QT_API`` environment variable.
15+
Otherwise, the shim will automatically select the first available API (PyQt5,
16+
PySide2, PyQt4 and finally PySide); in that case, you can force the use of one
17+
specific bindings (e.g. if your application is using one specific bindings and
18+
you need to use library that use QtPy) by setting up the ``QT_API`` environment
19+
variable.
1920
2021
PyQt5
2122
=====
@@ -62,10 +63,23 @@
6263
"""
6364

6465
import os
66+
import sys
67+
import warnings
6568

6669
# Version of QtPy
6770
from ._version import __version__
6871

72+
73+
class PythonQtError(Exception):
74+
"""Error raise if no bindings could be selected"""
75+
pass
76+
77+
78+
class PythonQtWarning(Warning):
79+
"""Warning if some features are not implemented in a binding."""
80+
pass
81+
82+
6983
# Qt API environment variable name
7084
QT_API = 'QT_API'
7185

@@ -86,23 +100,30 @@
86100

87101
# Setting a default value for QT_API
88102
os.environ.setdefault(QT_API, 'pyqt5')
103+
89104
API = os.environ[QT_API].lower()
105+
initial_api = API
90106
assert API in (PYQT5_API + PYQT4_API + PYSIDE_API + PYSIDE2_API)
91107

92108
is_old_pyqt = is_pyqt46 = False
93109
PYQT5 = True
94110
PYQT4 = PYSIDE = PYSIDE2 = False
95111

96112

97-
class PythonQtError(Exception):
98-
"""Error raise if no bindings could be selected"""
99-
pass
113+
if 'PyQt5' in sys.modules:
114+
API = 'pyqt5'
115+
elif 'PySide2' in sys.modules:
116+
API = 'pyside2'
117+
elif 'PyQt4' in sys.modules:
118+
API = 'pyqt4'
119+
elif 'PySide' in sys.modules:
120+
API = 'pyside'
100121

101122

102123
if API in PYQT5_API:
103124
try:
104-
from PyQt5.Qt import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore
105-
from PyQt5.Qt import QT_VERSION_STR as QT_VERSION # analysis:ignore
125+
from PyQt5.QtCore import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore
126+
from PyQt5.QtCore import QT_VERSION_STR as QT_VERSION # analysis:ignore
106127
PYSIDE_VERSION = None
107128
except ImportError:
108129
API = os.environ['QT_API'] = 'pyside2'
@@ -129,7 +150,7 @@ class PythonQtError(Exception):
129150
sip.setapi('QTextStream', 2)
130151
sip.setapi('QTime', 2)
131152
sip.setapi('QUrl', 2)
132-
except AttributeError:
153+
except (AttributeError, ValueError):
133154
# PyQt < v4.6
134155
pass
135156
from PyQt4.Qt import PYQT_VERSION_STR as PYQT_VERSION # analysis:ignore
@@ -153,12 +174,18 @@ class PythonQtError(Exception):
153174
except ImportError:
154175
raise PythonQtError('No Qt bindings could be found')
155176

177+
# If a correct API name is passed to QT_API and it could not be found,
178+
# switches to another and informs through the warning
179+
if API != initial_api:
180+
warnings.warn('Selected binding "{}" could not be found, '
181+
'using "{}"'.format(initial_api, API), RuntimeWarning)
182+
156183
API_NAME = {'pyqt5': 'PyQt5', 'pyqt': 'PyQt4', 'pyqt4': 'PyQt4',
157184
'pyside': 'PySide', 'pyside2':'PySide2'}[API]
158185

159186
if PYQT4:
160-
import sip
161-
try:
162-
API_NAME += (" (API v{0})".format(sip.getapi('QString')))
163-
except AttributeError:
164-
pass
187+
import sip
188+
try:
189+
API_NAME += (" (API v{0})".format(sip.getapi('QString')))
190+
except AttributeError:
191+
pass

winpython/_vendor/qtpy/_patch/qheaderview.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# Licensed under the terms of the MIT License
66
# (see LICENSE.txt for details)
7+
import warnings
78

89
def introduce_renamed_methods_qheaderview(QHeaderView):
910

@@ -15,8 +16,9 @@ def sectionsClickable(self):
1516
return _isClickable(self)
1617
QHeaderView.sectionsClickable = sectionsClickable
1718
def isClickable(self):
18-
raise Exception('isClickable is only available in Qt4. Use '
19-
'sectionsClickable instead.')
19+
warnings.warn('isClickable is only available in Qt4. Use '
20+
'sectionsClickable instead.', stacklevel=2)
21+
return _isClickable(self)
2022
QHeaderView.isClickable = isClickable
2123

2224

@@ -28,8 +30,9 @@ def sectionsMovable(self):
2830
return _isMovable(self)
2931
QHeaderView.sectionsMovable = sectionsMovable
3032
def isMovable(self):
31-
raise Exception('isMovable is only available in Qt4. Use '
32-
'sectionsMovable instead.')
33+
warnings.warn('isMovable is only available in Qt4. Use '
34+
'sectionsMovable instead.', stacklevel=2)
35+
return _isMovable(self)
3336
QHeaderView.isMovable = isMovable
3437

3538

@@ -41,8 +44,9 @@ def sectionResizeMode(self, logicalIndex):
4144
return _resizeMode(self, logicalIndex)
4245
QHeaderView.sectionResizeMode = sectionResizeMode
4346
def resizeMode(self, logicalIndex):
44-
raise Exception('resizeMode is only available in Qt4. Use '
45-
'sectionResizeMode instead.')
47+
warnings.warn('resizeMode is only available in Qt4. Use '
48+
'sectionResizeMode instead.', stacklevel=2)
49+
return _resizeMode(self, logicalIndex)
4650
QHeaderView.resizeMode = resizeMode
4751

4852
_setClickable = QHeaderView.setClickable
@@ -53,8 +57,9 @@ def setSectionsClickable(self, clickable):
5357
return _setClickable(self, clickable)
5458
QHeaderView.setSectionsClickable = setSectionsClickable
5559
def setClickable(self, clickable):
56-
raise Exception('setClickable is only available in Qt4. Use '
57-
'setSectionsClickable instead.')
60+
warnings.warn('setClickable is only available in Qt4. Use '
61+
'setSectionsClickable instead.', stacklevel=2)
62+
return _setClickable(self, clickable)
5863
QHeaderView.setClickable = setClickable
5964

6065

@@ -66,8 +71,9 @@ def setSectionsMovable(self, movable):
6671
return _setMovable(self, movable)
6772
QHeaderView.setSectionsMovable = setSectionsMovable
6873
def setMovable(self, movable):
69-
raise Exception('setMovable is only available in Qt4. Use '
70-
'setSectionsMovable instead.')
74+
warnings.warn('setMovable is only available in Qt4. Use '
75+
'setSectionsMovable instead.', stacklevel=2)
76+
return _setMovable(self, movable)
7177
QHeaderView.setMovable = setMovable
7278

7379

@@ -80,8 +86,9 @@ def setSectionResizeMode(self, *args):
8086
_setResizeMode(self, *args)
8187
QHeaderView.setSectionResizeMode = setSectionResizeMode
8288
def setResizeMode(self, *args):
83-
raise Exception('setResizeMode is only available in Qt4. Use '
84-
'setSectionResizeMode instead.')
89+
warnings.warn('setResizeMode is only available in Qt4. Use '
90+
'setSectionResizeMode instead.', stacklevel=2)
91+
_setResizeMode(self, *args)
8592
QHeaderView.setResizeMode = setResizeMode
8693

8794

winpython/_vendor/qtpy/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version_info = (1, 3, 0)
1+
version_info = (1, 4, 2)
22
__version__ = '.'.join(map(str, version_info))

winpython/_vendor/qtpy/tests/test.ui

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)