Skip to content

Allow style sheets to be used #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add theme test
  • Loading branch information
dstansby committed Jun 21, 2023
commit 3528dac6b04d3c5942465cd6844f5852c360dede
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/napari_matplotlib/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import numpy as np
import pytest
Expand Down Expand Up @@ -52,3 +53,8 @@ def set_strict_qt():
os.environ[env_var] = old_val
else:
del os.environ[env_var]


@pytest.fixture
def theme_path():
return Path(__file__).parent / "data" / "test_theme.mplstyle"
15 changes: 15 additions & 0 deletions src/napari_matplotlib/tests/data/test_theme.mplstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Dark-theme napari colour scheme for matplotlib plots

#f4b8b2 # light red
#b2e4f4 # light blue
#0aa3fc # dark blue
#008939 # dark green

figure.facecolor : f4b8b2 # light red
axes.facecolor : b2e4f4 # light blue
axes.edgecolor : 0aa3fc # dark blue

xtick.color : 008939 # dark green
xtick.labelcolor : 008939 # dark green
ytick.color : 008939 # dark green
ytick.labelcolor : 008939 # dark green
22 changes: 22 additions & 0 deletions src/napari_matplotlib/tests/test_theme.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from copy import deepcopy

import napari
import numpy as np
import pytest
Expand Down Expand Up @@ -118,3 +120,23 @@ def test_no_theme_side_effects(make_napari_viewer):
unrelated_figure.tight_layout()

return unrelated_figure


@pytest.mark.mpl_image_compare
def test_custom_theme(make_napari_viewer, theme_path, brain_data):
viewer = make_napari_viewer()
viewer.theme = "dark"

widget = ScatterWidget(viewer)
widget.mpl_style_sheet_path = theme_path

viewer.add_image(brain_data[0], **brain_data[1], name="brain")
viewer.add_image(
brain_data[0] * -1, **brain_data[1], name="brain_reversed"
)

viewer.layers.selection.clear()
viewer.layers.selection.add(viewer.layers[0])
viewer.layers.selection.add(viewer.layers[1])

return deepcopy(widget.figure)