Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f73f225

Browse filesBrowse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 533597d commit f73f225
Copy full SHA for f73f225

File tree

2 files changed

+37
-32
lines changed
Filter options

2 files changed

+37
-32
lines changed

‎src/napari_matplotlib/base.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/base.py
+12-7Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import matplotlib
66
import matplotlib.style as mplstyle
77
import napari
8-
from napari.utils.events import Event
9-
from napari.utils.theme import get_theme
108
from matplotlib.backends.backend_qtagg import ( # type: ignore[attr-defined]
119
FigureCanvasQTAgg,
1210
NavigationToolbar2QT,
1311
)
1412
from matplotlib.figure import Figure
13+
from napari.utils.events import Event
14+
from napari.utils.theme import get_theme
1515
from qtpy.QtGui import QIcon
1616
from qtpy.QtWidgets import QLabel, QVBoxLayout, QWidget
1717

@@ -47,8 +47,10 @@ def __init__(
4747
):
4848
super().__init__(parent=parent)
4949
self.viewer = napari_viewer
50-
#self._mpl_style_sheet_path: Optional[Path] = None
51-
self.napari_theme_style_sheet = style_sheet_from_theme(get_theme(napari_viewer.theme, as_dict=False))
50+
# self._mpl_style_sheet_path: Optional[Path] = None
51+
self.napari_theme_style_sheet = style_sheet_from_theme(
52+
get_theme(napari_viewer.theme, as_dict=False)
53+
)
5254

5355
# Sets figure.* style
5456
with mplstyle.context(self.napari_theme_style_sheet):
@@ -88,7 +90,9 @@ def _on_napari_theme_changed(self, event: Event) -> None:
8890
event : napari.utils.events.Event
8991
Event that triggered the callback.
9092
"""
91-
self.napari_theme_style_sheet = style_sheet_from_theme(get_theme(event.value, as_dict=False))
93+
self.napari_theme_style_sheet = style_sheet_from_theme(
94+
get_theme(event.value, as_dict=False)
95+
)
9296
self._replace_toolbar_icons()
9397

9498
def _napari_theme_has_light_bg(self) -> bool:
@@ -208,7 +212,7 @@ def _on_napari_theme_changed(self, event: Event) -> None:
208212
Event that triggered the callback.
209213
"""
210214
super()._on_napari_theme_changed(event)
211-
# use self._draw instead of self.draw to cope with redraw while there are no
215+
# use self._draw instead of self.draw to cope with redraw while there are no
212216
# layers, this makes the self.clear() obsolete
213217
self._draw()
214218

@@ -247,7 +251,8 @@ def _draw(self) -> None:
247251
# everything should be done in the style context
248252
self.clear()
249253
if self.n_selected_layers in self.n_layers_input and all(
250-
isinstance(layer, self.input_layer_types) for layer in self.layers
254+
isinstance(layer, self.input_layer_types)
255+
for layer in self.layers
251256
):
252257
self.draw()
253258
self.canvas.draw() # type: ignore[no-untyped-call]

‎src/napari_matplotlib/util.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/util.py
+25-25Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, Optional, Union
1+
from typing import Optional, Union
22
from warnings import warn
33

44
import napari.qt
@@ -141,47 +141,47 @@ def from_napari_css_get_size_of(
141141
return QSize(*fallback)
142142

143143

144-
def style_sheet_from_theme(theme: Theme) -> Dict[str, str]:
144+
def style_sheet_from_theme(theme: Theme) -> dict[str, str]:
145145
"""Translate napari theme to a matplotlib style dictionary.
146146
147147
Parameters
148148
----------
149149
theme : napari.utils.theme.Theme
150150
Napari theme object representing the theme of the current viewer.
151-
151+
152152
Returns
153153
-------
154154
Dict[str, str]
155155
Matplotlib compatible style dictionary.
156156
"""
157157
return {
158-
'axes.edgecolor':theme.secondary.as_hex(),
159-
#BUG: could be the same as napari canvas, but facecolors do not get
158+
"axes.edgecolor": theme.secondary.as_hex(),
159+
# BUG: could be the same as napari canvas, but facecolors do not get
160160
# updated upon redraw for what ever reason
161161
#'axes.facecolor':theme.canvas.as_hex(),
162-
'axes.facecolor':'none',
163-
'axes.labelcolor':theme.text.as_hex(),
164-
'boxplot.boxprops.color':theme.text.as_hex(),
165-
'boxplot.capprops.color':theme.text.as_hex(),
166-
'boxplot.flierprops.markeredgecolor':theme.text.as_hex(),
167-
'boxplot.whiskerprops.color':theme.text.as_hex(),
168-
'figure.edgecolor':theme.secondary.as_hex(),
169-
#BUG: should be the same as napari background, but facecolors do not get
162+
"axes.facecolor": "none",
163+
"axes.labelcolor": theme.text.as_hex(),
164+
"boxplot.boxprops.color": theme.text.as_hex(),
165+
"boxplot.capprops.color": theme.text.as_hex(),
166+
"boxplot.flierprops.markeredgecolor": theme.text.as_hex(),
167+
"boxplot.whiskerprops.color": theme.text.as_hex(),
168+
"figure.edgecolor": theme.secondary.as_hex(),
169+
# BUG: should be the same as napari background, but facecolors do not get
170170
# updated upon redraw for what ever reason
171171
#'figure.facecolor':theme.background.as_hex(),
172-
'figure.facecolor':'none',
173-
'grid.color':theme.foreground.as_hex(),
174-
#COMMENT: the hard coded colors are to match the previous behaviour
172+
"figure.facecolor": "none",
173+
"grid.color": theme.foreground.as_hex(),
174+
# COMMENT: the hard coded colors are to match the previous behaviour
175175
# alternativly we could use the theme to style the legend as well
176176
#'legend.edgecolor':theme.secondary.as_hex(),
177-
'legend.edgecolor':'black',
177+
"legend.edgecolor": "black",
178178
#'legend.facecolor':theme.background.as_hex(),
179-
'legend.facecolor':'white',
179+
"legend.facecolor": "white",
180180
#'legend.labelcolor':theme.text.as_hex()
181-
'legend.labelcolor':'black',
182-
'text.color':theme.text.as_hex(),
183-
'xtick.color':theme.secondary.as_hex(),
184-
'xtick.labelcolor':theme.text.as_hex(),
185-
'ytick.color':theme.secondary.as_hex(),
186-
'ytick.labelcolor':theme.text.as_hex(),
187-
}
181+
"legend.labelcolor": "black",
182+
"text.color": theme.text.as_hex(),
183+
"xtick.color": theme.secondary.as_hex(),
184+
"xtick.labelcolor": theme.text.as_hex(),
185+
"ytick.color": theme.secondary.as_hex(),
186+
"ytick.labelcolor": theme.text.as_hex(),
187+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.