Skip to content

Commit

Permalink
do key/value comparisons for dict
Browse files Browse the repository at this point in the history
  • Loading branch information
psobolewskiPhD committed Jul 19, 2023
1 parent a9ca7a7 commit 05122db
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions napari_animation/viewer_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ def apply(self, viewer: napari.viewer.Viewer):
layer_attributes = layer.as_layer_data_tuple()[1]
for attribute_name, value in layer_state.items():
original_value = layer_attributes[attribute_name]
# Only set if value differs to avoid expensive redraws
if not np.array_equal(original_value, value):
# Only setattr if value differs to avoid expensive redraws
# dicts can hold arrays, e.g. `color`, requiring comparisons of key/value pairs
if type(value) is dict:
for key, val in value.items():
if not np.array_equal(val, original_value.get(key)):
setattr(layer, attribute_name, value)
break
elif not np.array_equal(original_value, value):
setattr(layer, attribute_name, value)

def render(
Expand Down

0 comments on commit 05122db

Please sign in to comment.