-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_theme.py
More file actions
72 lines (56 loc) · 2.15 KB
/
test_theme.py
File metadata and controls
72 lines (56 loc) · 2.15 KB
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
# -*- coding: utf-8 -*-
#
# Licensed under the terms of the BSD 3-Clause
# (see guidata/LICENSE for details)
"""
Test dark/light theme switching
"""
from __future__ import annotations
import sys
from typing import Literal
import pytest
from guidata import qthelpers as qth
try:
# guidata > V2.6.2
from guidata.tests.widgets.test_theme import ColorModeWidget as GuidataWidget
except ImportError:
# guidata V2.6.2
from guidata.tests.widgets.test_theme import (
TestWidget as GuidataWidget, # noqa: F401
)
from qtpy import QtWidgets as QW
from plotpy.builder import make
from plotpy.config import update_plotpy_color_mode
from plotpy.plot import PlotOptions, PlotWidget
from plotpy.tests import data as ptd
class ColorModeWidget(GuidataWidget):
"""Testing color mode switching for PlotPy and guidata widgets"""
SIZE = (1400, 600)
def __init__(self, default: Literal["light", "dark", "auto"] = qth.AUTO) -> None:
self.plot_widget: PlotWidget | None = None
super().__init__(default=default)
def setup_widgets(self):
"""Setup widgets"""
super().setup_widgets()
options = PlotOptions(type="image", show_contrast=True)
self.plot_widget = widget = PlotWidget(self, options=options)
plot = self.plot_widget.get_plot()
item = make.image(ptd.gen_image4(300, 200))
plot.add_item(item)
plot.set_active_item(item, select=False)
widget.setSizePolicy(QW.QSizePolicy.Expanding, QW.QSizePolicy.Expanding)
self.grid_layout.addWidget(widget, 1, 2)
def change_color_mode(self, mode: str) -> None:
"""Change color mode"""
super().change_color_mode(mode)
update_plotpy_color_mode()
@pytest.mark.skipif(reason="Not suitable for automated testing")
def test_dark_light_themes(
default: Literal["light", "dark", "auto"] | None = None,
) -> None:
"""Test dark/light theme switching"""
with qth.qt_app_context(exec_loop=True):
widget = ColorModeWidget(default=qth.AUTO if default is None else default)
widget.show()
if __name__ == "__main__":
test_dark_light_themes(None if len(sys.argv) < 2 else sys.argv[1])