blob: 66a35a855fb192c43075a577c9ad5afca7599de9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# FIXME:qt6 (lint)
# pylint: disable=missing-module-docstring
# flake8: noqa
import os
import importlib
_WRAPPERS = [
"PyQt6",
"PyQt5",
# Needs more work
# "PySide6",
]
class Error(Exception):
pass
class Unavailable(Error, ImportError):
"""Raised when a module is unavailable with the given wrapper."""
def __init__(self) -> None:
super().__init__(f"Unavailable with {WRAPPER}")
class UnknownWrapper(Error):
pass
def _autoselect_wrapper():
for wrapper in _WRAPPERS:
try:
importlib.import_module(wrapper)
except ImportError:
# FIXME:qt6 show/log this somewhere?
continue
return wrapper
wrappers = ", ".join(_WRAPPERS)
raise Error(f"No Qt wrapper found, tried {wrappers}")
def _select_wrapper():
env_var = "QUTE_QT_WRAPPER"
env_wrapper = os.environ.get(env_var)
if env_wrapper is None:
return _autoselect_wrapper()
if env_wrapper not in _WRAPPERS:
raise Error(f"Unknown wrapper {env_wrapper} set via {env_var}, "
f"allowed: {', '.join(_WRAPPERS)}")
return env_wrapper
WRAPPER = _select_wrapper()
USE_PYQT5 = WRAPPER == "PyQt5"
USE_PYQT6 = WRAPPER == "PyQt6"
USE_PYSIDE6 = WRAPPER == "PySide6"
assert USE_PYQT5 ^ USE_PYQT6 ^ USE_PYSIDE6
IS_QT5 = USE_PYQT5
IS_QT6 = USE_PYQT6 or USE_PYSIDE6
IS_PYQT = USE_PYQT5 or USE_PYQT6
IS_PYSIDE = USE_PYSIDE6
assert IS_QT5 ^ IS_QT6
assert IS_PYQT ^ IS_PYSIDE
if USE_PYQT5:
PACKAGE = "PyQt5"
elif USE_PYQT6:
PACKAGE = "PyQt6"
elif USE_PYSIDE6:
PACKAGE = "PySide6"
|