Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace all hacky traitlet replacements with send_state #2285

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 deletions jdaviz/configs/default/plugins/line_lists/line_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,8 @@ def _list_from_notebook(self, msg):
list_contents[row["listname"]]["lines"].append(temp_dict)
tmp_names_rest.append(row["name_rest"])

self.loaded_lists = []
self.loaded_lists = loaded_lists
self.list_contents = {}
self.list_contents = list_contents
self.send_state('loaded_lists')
self.send_state('list_contents')

self._viewer.plot_spectral_lines(tmp_names_rest)
self.update_line_mark_dict()
Expand Down Expand Up @@ -654,9 +652,9 @@ def vue_show_all_in_list(self, listname):
for line in lc[listname]["lines"]:
line["show"] = True
self._viewer.spectral_lines.loc[line["name_rest"]]["show"] = True
# Trick traitlets into updating
self.list_contents = {}

self.list_contents = lc
self.send_state('list_contents')

self._viewer.plot_spectral_lines()
self.update_line_mark_dict()
Expand All @@ -665,14 +663,12 @@ def vue_hide_all_in_list(self, listname):
"""
Toggle all lines in list to be hidden
"""
lc = self.list_contents
name_rests = []
for line in lc[listname]["lines"]:
for line in self.list_contents[listname]["lines"]:
line["show"] = False
name_rests.append(line["name_rest"])
# Trick traitlets into updating
self.list_contents = {}
self.list_contents = lc

self.send_state('list_contents')

self._viewer.erase_spectral_lines(name_rest=name_rests)
self.update_line_mark_dict()
Expand All @@ -686,14 +682,12 @@ def vue_plot_all_lines(self, event):
sender=self, color="error")
self.hub.broadcast(warn_message)
return
lc = self.list_contents
for listname in lc:
for line in lc[listname]["lines"]:
for listname in self.list_contents:
for line in self.list_contents[listname]["lines"]:
line["show"] = True
self._viewer.spectral_lines["show"] = True
# Trick traitlets into updating
self.list_contents = {}
self.list_contents = lc

self.send_state('list_contents')

self._viewer.plot_spectral_lines()
self.update_line_mark_dict()
Expand All @@ -707,13 +701,11 @@ def vue_erase_all_lines(self, event):
sender=self, color="error")
self.hub.broadcast(warn_message)
return
lc = self.list_contents
for listname in lc:
for line in lc[listname]["lines"]:
for listname in self.list_contents:
for line in self.list_contents[listname]["lines"]:
line["show"] = False
# Trick traitlets into updating
self.list_contents = {}
self.list_contents = lc

self.send_state('list_contents')

self._viewer.erase_spectral_lines()
self.update_line_mark_dict()
Expand Down Expand Up @@ -798,11 +790,10 @@ def vue_set_color(self, data):
color = data['color']
if "listname" in data:
listname = data["listname"]
# force a copy so that the change is picked up by traitlets
lc = self.list_contents[listname].copy()
lc["color"] = color

for line in lc["lines"]:
self.list_contents[listname]["color"] = color

for line in self.list_contents[listname]["lines"]:
line["colors"] = color
# Update the astropy table entry
name_rest = line["name_rest"]
Expand All @@ -811,7 +802,7 @@ def vue_set_color(self, data):
if name_rest in self.line_mark_dict:
self.line_mark_dict[name_rest].colors = [color]

self.list_contents = {**self.list_contents, listname: lc}
self.send_state('list_contents')

elif "linename" in data:
pass
Expand Down
10 changes: 2 additions & 8 deletions jdaviz/configs/default/plugins/model_fitting/model_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ def _update_parameters_from_fit(self):

m["parameters"] = temp_params

# Trick traitlets into updating the displayed values
component_models = self.component_models
self.component_models = []
self.component_models = component_models
self.send_state('component_models')

def _update_parameters_from_QM(self):
"""
Expand Down Expand Up @@ -283,10 +280,7 @@ def _update_parameters_from_QM(self):
temp_params += temp_param
m["parameters"] = temp_params

# Trick traitlets into updating the displayed values
component_models = self.component_models
self.component_models = []
self.component_models = component_models
self.send_state('component_models')

def _update_initialized_parameters(self):
# If the user changes a parameter value, we need to change it in the
Expand Down
5 changes: 2 additions & 3 deletions jdaviz/configs/mosviz/plugins/slit_overlay/slit_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ def remove_slit_overlay(self):
# We need to do the following instead of just removing directly on
# the marks otherwise traitlets doesn't register a change in the
# marks.
marks = image_figure.marks.copy()
marks.remove(self._slit_overlay_mark)
image_figure.marks = marks
image_figure.marks.remove(self._slit_overlay_mark)
image_figure.send_state('marks')
self._slit_overlay_mark = None