1 # -----------------------------------------------------------------------------
2 # Copyright © 2014-2015 Colin Duquesnoy
3 # Copyright © 2009- The Spyder Development Team
5 # Licensed under the terms of the MIT License
6 # (see LICENSE.txt for details)
7 # -----------------------------------------------------------------------------
9 """Provides QtGui classes and functions."""
11 from . import PYQT6
, PYQT5
, PYSIDE2
, PYSIDE6
14 from PyQt5
.QtGui
import *
16 from PyQt6
import QtGui
17 from PyQt6
.QtGui
import *
18 from PyQt6
.QtOpenGL
import *
19 QFontMetrics
.width
= lambda self
, *args
, **kwargs
: self
.horizontalAdvance(*args
, **kwargs
)
20 QFontMetricsF
.width
= lambda self
, *args
, **kwargs
: self
.horizontalAdvance(*args
, **kwargs
)
22 # Map missing/renamed methods
23 QDrag
.exec_
= lambda self
, *args
, **kwargs
: self
.exec(*args
, **kwargs
)
24 QGuiApplication
.exec_
= QGuiApplication
.exec
25 QTextDocument
.print_
= lambda self
, *args
, **kwargs
: self
.print(*args
, **kwargs
)
27 # Allow unscoped access for enums inside the QtGui module
28 from .enums_compat
import promote_enums
32 from PySide2
.QtGui
import *
33 if hasattr(QFontMetrics
, 'horizontalAdvance'):
34 # Needed to prevent raising a DeprecationWarning when using QFontMetrics.width
35 QFontMetrics
.width
= lambda self
, *args
, **kwargs
: self
.horizontalAdvance(*args
, **kwargs
)
37 from PySide6
.QtGui
import *
38 from PySide6
.QtOpenGL
import *
39 QFontMetrics
.width
= lambda self
, *args
, **kwargs
: self
.horizontalAdvance(*args
, **kwargs
)
40 QFontMetricsF
.width
= lambda self
, *args
, **kwargs
: self
.horizontalAdvance(*args
, **kwargs
)
42 # Map DeprecationWarning methods
43 QDrag
.exec_
= lambda self
, *args
, **kwargs
: self
.exec(*args
, **kwargs
)
44 QGuiApplication
.exec_
= QGuiApplication
.exec
46 if PYSIDE2
or PYSIDE6
:
47 # PySide{2,6} do not accept the `mode` keyword argument in
48 # QTextCursor.movePosition() even though it is a valid optional argument
49 # as per C++ API. Fix this by monkeypatching.
53 # * The `mode` argument is called `arg__2` in PySide{2,6} as per
54 # QTextCursor.movePosition.__doc__ and __signature__. Using `arg__2` as
55 # keyword argument works as intended, so does using a positional
56 # argument. Tested with PySide2 5.15.0, 5.15.2.1 and 5.15.3 and PySide6
57 # 6.3.0; older version, down to PySide 1, are probably affected as well [1].
59 # * PySide2 5.15.0 and 5.15.2.1 silently ignore invalid keyword arguments,
60 # i.e. passing the `mode` keyword argument has no effect and doesn’t
61 # raise an exception. Older versions, down to PySide 1, are probably
62 # affected as well [1]. At least PySide2 5.15.3 and PySide6 6.3.0 raise an
63 # exception when `mode` or any other invalid keyword argument is passed.
65 # [1] https://bugreports.qt.io/browse/PYSIDE-185
66 movePosition
= QTextCursor
.movePosition
67 def movePositionPatched(
69 operation
: QTextCursor
.MoveOperation
,
70 mode
: QTextCursor
.MoveMode
= QTextCursor
.MoveAnchor
,
73 return movePosition(self
, operation
, mode
, n
)
74 QTextCursor
.movePosition
= movePositionPatched