summaryrefslogtreecommitdiff
path: root/qutebrowser/utils/qtutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'qutebrowser/utils/qtutils.py')
-rw-r--r--qutebrowser/utils/qtutils.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py
index 0bd9c94e8..699dc86d9 100644
--- a/qutebrowser/utils/qtutils.py
+++ b/qutebrowser/utils/qtutils.py
@@ -36,6 +36,7 @@ import contextlib
from typing import (Any, AnyStr, TYPE_CHECKING, BinaryIO, IO, Iterator,
Optional, Union, Tuple, cast)
+from qutebrowser.qt import machinery, sip
from qutebrowser.qt.core import (qVersion, QEventLoop, QDataStream, QByteArray,
QIODevice, QFileDevice, QSaveFile, QT_VERSION_STR,
PYQT_VERSION_STR, QObject, QUrl, QLibraryInfo)
@@ -455,6 +456,12 @@ class QtValueError(ValueError):
super().__init__(err)
+if machinery.IS_QT6:
+ _ProcessEventFlagType = QEventLoop.ProcessEventsFlag
+else:
+ _ProcessEventFlagType = QEventLoop.ProcessEventsFlags
+
+
class EventLoop(QEventLoop):
"""A thin wrapper around QEventLoop.
@@ -468,8 +475,9 @@ class EventLoop(QEventLoop):
def exec(
self,
- flags: QEventLoop.ProcessEventsFlag =
- QEventLoop.ProcessEventsFlag.AllEvents
+ flags: _ProcessEventFlagType = (
+ QEventLoop.ProcessEventsFlag.AllEvents # type: ignore[assignment]
+ ),
) -> int:
"""Override exec_ to raise an exception when re-running."""
if self._executing:
@@ -581,8 +589,7 @@ class LibraryPath(enum.Enum):
def library_path(which: LibraryPath) -> pathlib.Path:
"""Wrapper around QLibraryInfo.path / .location."""
- if hasattr(QLibraryInfo, "path"):
- # Qt 6
+ if machinery.IS_QT6:
val = getattr(QLibraryInfo.LibraryPath, which.value)
ret = QLibraryInfo.path(val)
else:
@@ -593,7 +600,7 @@ def library_path(which: LibraryPath) -> pathlib.Path:
return pathlib.Path(ret)
-def extract_enum_val(val: Union[int, enum.Enum]) -> int:
+def extract_enum_val(val: Union[sip.simplewrapper, int, enum.Enum]) -> int:
"""Extract an int value from a Qt enum value.
For Qt 5, enum values are basically Python integers.
@@ -602,4 +609,6 @@ def extract_enum_val(val: Union[int, enum.Enum]) -> int:
"""
if isinstance(val, enum.Enum):
return val.value
+ elif isinstance(val, sip.simplewrapper):
+ return int(val) # type: ignore[call-overload]
return int(val)