From 437190e28bf20523e0a1a39d7cda4bed1af3f85e Mon Sep 17 00:00:00 2001 From: Sam Cunliffe Date: Thu, 1 Jun 2023 08:38:31 +0100 Subject: [PATCH 1/2] Test the automatic figuring out if a background is light. ... using the pydantic.Color HSL. --- src/napari_matplotlib/tests/test_theme.py | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/napari_matplotlib/tests/test_theme.py b/src/napari_matplotlib/tests/test_theme.py index 207171cf..ae55f1ce 100644 --- a/src/napari_matplotlib/tests/test_theme.py +++ b/src/napari_matplotlib/tests/test_theme.py @@ -1,3 +1,4 @@ +import napari import pytest from napari_matplotlib.base import NapariMPLWidget @@ -18,3 +19,31 @@ def test_theme_mpl_toolbar_icons( assert ( path_to_icons.stem == expected_icons ), "The theme is selecting unexpected icons." + + +def _mock_up_theme() -> None: + """Mock up a new color theme based on dark mode but with a tasteful blue background. + + Based on: + https://napari.org/stable/gallery/new_theme.html + """ + blue_theme = napari.utils.theme.get_theme("dark", False) + blue_theme.name = "blue" + blue_theme.background = "#4169e1" # my favourite shade of blue + napari.utils.theme.register_theme("blue", blue_theme) + + +def test_theme_background_check(make_napari_viewer): + """Check that the hue, saturation, lightness can distinguish dark and light backgrounds.""" + viewer = make_napari_viewer() + widget = NapariMPLWidget(viewer) + + viewer.theme = "dark" + assert widget._theme_has_light_bg() is False + + viewer.theme = "light" + assert widget._theme_has_light_bg() is True + + _mock_up_theme() + viewer.theme = "blue" + assert widget._theme_has_light_bg() is True From 1cb9c2d1712d53d68aeff7d51e7d403fb3504158 Mon Sep 17 00:00:00 2001 From: Sam Cunliffe Date: Thu, 1 Jun 2023 10:41:04 +0100 Subject: [PATCH 2/2] Linting. --- src/napari_matplotlib/tests/test_theme.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/napari_matplotlib/tests/test_theme.py b/src/napari_matplotlib/tests/test_theme.py index ae55f1ce..88b271d6 100644 --- a/src/napari_matplotlib/tests/test_theme.py +++ b/src/napari_matplotlib/tests/test_theme.py @@ -34,7 +34,9 @@ def _mock_up_theme() -> None: def test_theme_background_check(make_napari_viewer): - """Check that the hue, saturation, lightness can distinguish dark and light backgrounds.""" + """ + Check that the hue saturation lightness can distinguish dark and light backgrounds. + """ viewer = make_napari_viewer() widget = NapariMPLWidget(viewer)