Skip to content

Commit

Permalink
Return full colormap dict in get_state (#5782)
Browse files Browse the repository at this point in the history
# Description
When working with custom colormaps, reader and writers trying to use
that colormap will fail because the only information returned by
`Layer.get_state` is the colormap name. This works fine with builtin
colormaps, but anything custom will fail due to `[unnamed colormap 0]`
not existing.

By returning the full colormap model (in dict form) we can also account
for this.

Plugin writers and readers using `colormap` will likely break (like our
napari-svg) because they assume it to be a string.

Note that this includes #5805. which is a lot smaller and just a bug
fix.

# References
<!-- What resources, documentation, and guides were used in the creation
of this PR? -->

## Type of change
<!-- Please delete options that are not relevant. -->
- [x] Bug-fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

---------

Co-authored-by: Kyle I S Harrington <kephale@users.noreply.github.com>
  • Loading branch information
brisvag and kephale committed Jul 23, 2023
1 parent e0c0c8e commit 9997588
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion napari/layers/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ def _get_state(self):
{
'rgb': self.rgb,
'multiscale': self.multiscale,
'colormap': self.colormap.name,
'colormap': self.colormap.dict(),
'contrast_limits': self.contrast_limits,
'interpolation2d': self.interpolation2d,
'interpolation3d': self.interpolation3d,
Expand Down
4 changes: 2 additions & 2 deletions napari/layers/points/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,13 +1283,13 @@ def _get_state(self):
if self.data.size
else [self.current_face_color],
'face_color_cycle': self.face_color_cycle,
'face_colormap': self.face_colormap.name,
'face_colormap': self.face_colormap.dict(),
'face_contrast_limits': self.face_contrast_limits,
'edge_color': self.edge_color
if self.data.size
else [self.current_edge_color],
'edge_color_cycle': self.edge_color_cycle,
'edge_colormap': self.edge_colormap.name,
'edge_colormap': self.edge_colormap.dict(),
'edge_contrast_limits': self.edge_contrast_limits,
'properties': self.properties,
'property_choices': self.property_choices,
Expand Down
4 changes: 2 additions & 2 deletions napari/layers/shapes/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,11 +1524,11 @@ def _get_state(self):
'edge_width': self.edge_width,
'face_color': face_color,
'face_color_cycle': self.face_color_cycle,
'face_colormap': self.face_colormap.name,
'face_colormap': self.face_colormap.dict(),
'face_contrast_limits': self.face_contrast_limits,
'edge_color': edge_color,
'edge_color_cycle': self.edge_color_cycle,
'edge_colormap': self.edge_colormap.name,
'edge_colormap': self.edge_colormap.dict(),
'edge_contrast_limits': self.edge_contrast_limits,
'data': self.data,
'features': self.features,
Expand Down
2 changes: 1 addition & 1 deletion napari/layers/surface/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def _get_state(self):
state = self._get_base_state()
state.update(
{
'colormap': self.colormap.name,
'colormap': self.colormap.dict(),
'contrast_limits': self.contrast_limits,
'gamma': self.gamma,
'shading': self.shading,
Expand Down
2 changes: 1 addition & 1 deletion napari/layers/vectors/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def _get_state(self):
if self.data.size
else [self._edge.current_color],
'edge_color_cycle': self.edge_color_cycle,
'edge_colormap': self.edge_colormap.name,
'edge_colormap': self.edge_colormap.dict(),
'edge_contrast_limits': self.edge_contrast_limits,
'data': self.data,
'properties': self.properties,
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ install_requires =
magicgui>=0.3.6
napari-console>=0.0.6
napari-plugin-engine>=0.1.9
napari-svg>=0.1.7
napari-svg>=0.1.8
npe2>=0.5.2
numpy>=1.21,<2
numpydoc>=0.9.2
Expand Down

0 comments on commit 9997588

Please sign in to comment.