Skip to content

Commit

Permalink
Fix inspector issue where color table missing.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeyer committed Oct 16, 2024
1 parent ab27672 commit f94745b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nion/swift/Inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,8 @@ def __init__(self, document_controller: DocumentController.DocumentController, d
self.color_map_items.append(color_map.name)
self._color_map_flags.append(color_map_key)
self._color_map_reverse_map = {p: i for i, p in enumerate(self._color_map_flags)}
self.current_colormap_index = Model.PropertyModel[int](self._color_map_reverse_map[self._display_data_channel.color_map_id])
color_map_index = self._color_map_reverse_map.get(self._display_data_channel.color_map_id, 0)
self.current_colormap_index = Model.PropertyModel[int](color_map_index)

self.brightness_model = DisplayDataChannelPropertyCommandModel(document_controller, display_data_channel, "brightness", title=_("Change Brightness"), command_id="change_brightness")

Expand Down
11 changes: 11 additions & 0 deletions nion/swift/test/Inspector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,17 @@ def test_image_display_inspector_sets_display_limits_when_text_is_changed(self):
inspector_section.image_data_inspector_handler.display_limits_limit_high.editing_finished("")
self.assertEqual(display_data_channel.display_limits, None)

def test_image_data_inspector_handles_missing_color_table(self) -> None:
with TestContext.create_memory_context() as test_context:
document_controller = test_context.create_document_controller()
document_model = document_controller.document_model
data_item = DataItem.DataItem(numpy.zeros((4, 4), numpy.uint32))
document_model.append_data_item(data_item)
display_item = document_model.get_display_item_for_data_item(data_item)
display_data_channel = display_item.display_data_channels[0]
display_data_channel.color_map_id = "__missing__"
Inspector.ImageDataInspectorModel(document_controller, display_data_channel, display_item)

def test_inspector_handles_deleted_data(self):
with TestContext.create_memory_context() as test_context:
document_controller = test_context.create_document_controller()
Expand Down

0 comments on commit f94745b

Please sign in to comment.