Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gselzer committed Oct 8, 2024
1 parent 3a81d66 commit a97c5f3
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/ndv/viewer/_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,33 +285,34 @@ def set_data(
the initial index will be set to the middle of the data.
"""
# clear current data
self._data_wrapper = None
self._clear_images()
# NB This is particularly important to be done on every set_data call
# because when going from a N+M-dimensional image to an N-dimensional
# image, we need to remove the sliders for dims N+1, N+2, ...
self._dims_sliders.clear()
self._data_info_label.setText("")
if data is None:
self._data_wrapper = None
self._clear_images()
self._dims_sliders.clear()
self._data_info_label.setText("")
return

# store the data
self._data_wrapper: DataWrapper = DataWrapper.create(data)

# set channel axis
self._channel_axis = self._data_wrapper.guess_channel_axis()

# update the dimensions we are visualizing
sizes = dict(self._data_wrapper.sizes().items())

# set channel axis
self._channel_axis = self._data_wrapper.guess_channel_axis()
self._channel_mode_combo.enable_rgba(
self._channel_axis is not None and sizes[self._channel_axis] in [3, 4]
)

visualized_dims = list(sizes)
if self._channel_axis is not None:
visualized_dims.remove(self._channel_axis)
visualized_dims = visualized_dims[-self._ndims :]
self.set_visualized_dims(visualized_dims)

is_rgba = (self._channel_axis is not None) and (
sizes[self._channel_axis] in [3, 4]
)
self._channel_mode_combo.enable_rgba(is_rgba)

# update the range of all the sliders to match the sizes we set above
with signals_blocked(self._dims_sliders):
self._update_slider_ranges()
Expand Down Expand Up @@ -495,6 +496,12 @@ def _update_slider_ranges(self) -> None:
for dim in self._visualized_dims:
self._dims_sliders.set_dimension_visible(dim, False)

if self._channel_axis is not None:
self._dims_sliders.set_dimension_visible(
self._channel_axis,
self._channel_mode not in [ChannelMode.RGBA, ChannelMode.COMPOSITE],
)

def _on_set_range_clicked(self) -> None:
# using method to swallow the parameter passed by _set_range_btn.clicked
self._canvas.set_range()
Expand Down

0 comments on commit a97c5f3

Please sign in to comment.