From a97c5f34da279d2cfc2f7216dcd95ec2c8b67494 Mon Sep 17 00:00:00 2001 From: Gabriel Selzer Date: Tue, 8 Oct 2024 16:52:51 -0500 Subject: [PATCH] Minor fixes --- src/ndv/viewer/_viewer.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/ndv/viewer/_viewer.py b/src/ndv/viewer/_viewer.py index e9335af4..eb3128c7 100755 --- a/src/ndv/viewer/_viewer.py +++ b/src/ndv/viewer/_viewer.py @@ -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() @@ -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()