1
1
import os
2
2
from pathlib import Path
3
- from typing import List , Optional , Tuple
3
+ from typing import Optional
4
4
5
5
import matplotlib
6
6
import matplotlib .style as mplstyle
7
7
import napari
8
- from matplotlib .backends .backend_qtagg import (
9
- FigureCanvas ,
8
+ from matplotlib .backends .backend_qtagg import ( # type: ignore[attr-defined]
9
+ FigureCanvasQTAgg ,
10
10
NavigationToolbar2QT ,
11
11
)
12
12
from matplotlib .figure import Figure
@@ -49,12 +49,10 @@ def __init__(
49
49
50
50
# Sets figure.* style
51
51
with mplstyle .context (self .mpl_style_sheet_path ):
52
- self .canvas = FigureCanvas ()
52
+ self .canvas = FigureCanvasQTAgg () # type: ignore[no-untyped-call]
53
53
54
54
self .canvas .figure .set_layout_engine ("constrained" )
55
- self .toolbar = NapariNavigationToolbar (
56
- self .canvas , parent = self
57
- ) # type: ignore[no-untyped-call]
55
+ self .toolbar = NapariNavigationToolbar (self .canvas , parent = self )
58
56
self ._replace_toolbar_icons ()
59
57
# callback to update when napari theme changed
60
58
# TODO: this isn't working completely (see issue #140)
@@ -97,7 +95,7 @@ def add_single_axes(self) -> None:
97
95
# Sets axes.* style.
98
96
# Does not set any text styling set by axes.* keys
99
97
with mplstyle .context (self .mpl_style_sheet_path ):
100
- self .axes = self .figure .subplots ()
98
+ self .axes = self .figure .add_subplot ()
101
99
102
100
def _on_napari_theme_changed (self ) -> None :
103
101
"""
@@ -184,7 +182,7 @@ class NapariMPLWidget(BaseNapariMPLWidget):
184
182
#: Number of layers taken as input
185
183
n_layers_input = Interval (None , None )
186
184
#: Type of layer taken as input
187
- input_layer_types : Tuple [napari .layers .Layer , ...] = (napari .layers .Layer ,)
185
+ input_layer_types : tuple [napari .layers .Layer , ...] = (napari .layers .Layer ,)
188
186
189
187
def __init__ (
190
188
self ,
@@ -193,7 +191,7 @@ def __init__(
193
191
):
194
192
super ().__init__ (napari_viewer = napari_viewer , parent = parent )
195
193
self ._setup_callbacks ()
196
- self .layers : List [napari .layers .Layer ] = []
194
+ self .layers : list [napari .layers .Layer ] = []
197
195
198
196
helper_text = self .n_layers_input ._helper_text
199
197
if helper_text is not None :
@@ -260,7 +258,7 @@ def _draw(self) -> None:
260
258
isinstance (layer , self .input_layer_types ) for layer in self .layers
261
259
):
262
260
self .draw ()
263
- self .canvas .draw ()
261
+ self .canvas .draw () # type: ignore[no-untyped-call]
264
262
265
263
def clear (self ) -> None :
266
264
"""
@@ -309,8 +307,8 @@ def clear(self) -> None:
309
307
class NapariNavigationToolbar (NavigationToolbar2QT ):
310
308
"""Custom Toolbar style for Napari."""
311
309
312
- def __init__ (self , * args , ** kwargs ): # type: ignore[no-untyped-def]
313
- super ().__init__ (* args , ** kwargs )
310
+ def __init__ (self , * args , ** kwargs ) -> None : # type: ignore[no-untyped-def]
311
+ super ().__init__ (* args , ** kwargs ) # type: ignore[no-untyped-call]
314
312
self .setIconSize (
315
313
from_napari_css_get_size_of (
316
314
"QtViewerPushButton" , fallback = (28 , 28 )
@@ -319,7 +317,7 @@ def __init__(self, *args, **kwargs): # type: ignore[no-untyped-def]
319
317
320
318
def _update_buttons_checked (self ) -> None :
321
319
"""Update toggle tool icons when selected/unselected."""
322
- super ()._update_buttons_checked ()
320
+ super ()._update_buttons_checked () # type: ignore[no-untyped-call]
323
321
icon_dir = self .parentWidget ()._get_path_to_icon ()
324
322
325
323
# changes pan/zoom icons depending on state (checked or not)
0 commit comments