From 3c31e189cdd97489079fce0246bd1c971917d567 Mon Sep 17 00:00:00 2001 From: Jesse Averbukh Date: Tue, 14 Nov 2023 15:29:27 -0500 Subject: [PATCH] Viewer multiselect mixed state working --- .../plugins/plot_options/plot_options.py | 27 ------------------- jdaviz/core/template_mixin.py | 10 +++++++ 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/jdaviz/configs/default/plugins/plot_options/plot_options.py b/jdaviz/configs/default/plugins/plot_options/plot_options.py index 9240dd0394..357d29ee5a 100644 --- a/jdaviz/configs/default/plugins/plot_options/plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/plot_options.py @@ -928,30 +928,3 @@ def _viewer_is_image_viewer(self): return isinstance(self.viewer.selected_obj, (ImvizImageView, CubevizImageView, MosvizImageView, MosvizProfile2DView)) - - @observe('line_color_value', 'image_color_value') - def color_change_event(self, event): - # Do not run when Plot Options is being instantiated - if event['old'] is None: - return - layer_names = [x['label'] for x in self.layer_items] - - if isinstance(self.layer_selected, list): - layers_select = self.layer_selected - else: - layers_select = [self.layer_selected] - for layer_select in layers_select: - self.layer_items[layer_names.index(layer_select)]['color'] = event['new'] - self.send_state('layer_items') - - @observe('layer_selected') - def layer_selected_change_event(self, event): - if event is None or event['old'] is None: - return - print("layer", self.layer_items, self.layer.items) - - @observe('viewer_selected') - def viewer_selected_change_event(self, event): - if event is None or event['old'] is None: - return - print("viewer", self.layer_items, self.layer.items) diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index d035d0227a..d66f6ede88 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -1247,6 +1247,8 @@ def __init__(self, plugin, items, selected, viewer, self.add_observe(viewer, self._on_viewer_changed) self._on_layers_changed() + self.callbacks_list = [] + def _get_viewer(self, viewer): # newer will likely be the viewer name in most cases, but viewer id in the case # of additional viewers in imviz. @@ -1274,6 +1276,14 @@ def _on_viewer_changed(self, msg=None): if new != old: self._clear_cache() self._on_layers_changed() + added_viewers = list(set(new) - set(old)) + removed_viewers = list(set(old) - set(new)) + for old_viewer in removed_viewers: + for layer in self._get_viewer(old_viewer).state.layers: + layer.remove_callback('color', self._on_layers_changed) + for new_viewer in added_viewers: + for layer in self._get_viewer(new_viewer).state.layers: + layer.add_callback('color', self._on_layers_changed) @observe('filters') def _on_layers_changed(self, msg=None):