From 6e476529a78f7eaa34cee3e543738b44dff57f7f Mon Sep 17 00:00:00 2001 From: Peter Drmota <49479443+pmldrmota@users.noreply.github.com> Date: Tue, 16 Jan 2024 14:32:30 +0000 Subject: [PATCH] plots.model.subscriber: emit source_id_changed and points_rewritten Without this, the applet of a TopLevelRunner with a constant prefix wouldn't update the source_id or the cached data (averaged points) upon resubmitting the same scan. --- ndscan/plots/model/subscriber.py | 23 +++++++++++++++++------ ndscan/plots/xy_1d.py | 1 - 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ndscan/plots/model/subscriber.py b/ndscan/plots/model/subscriber.py index 0bf60afb..92d3e8a7 100644 --- a/ndscan/plots/model/subscriber.py +++ b/ndscan/plots/model/subscriber.py @@ -37,14 +37,14 @@ def d(name): if schema_revision is None: return - if not self._title_set: - fqn = d("fragment_fqn") + fqn = d("fragment_fqn") + if not self._title_set or self._context.get_title() != fqn: if fqn: self._context.set_title(fqn) self._title_set = True - if not self._source_id_set: - source_id = d("source_id") + source_id = d("source_id") + if not self._source_id_set or self._context.get_source_id() != source_id: if source_id: self._context.set_source_id(source_id) self._source_id_set = True @@ -194,10 +194,21 @@ def data_changed(self, values: dict[str, Any], mods: Iterable[dict[str, for name, source in self._analysis_result_sources.items(): source.set(values.get(self._prefix + "analysis_result." + name)) + point_data_changed = False for name in ([f"axis_{i}" for i in range(len(self.axes))] + ["channel_" + c for c in self._channel_schemata.keys()]): - self._point_data[name] = values.get(self._prefix + "points." + name, []) - self.points_appended.emit(self._point_data) + point_values = values.get(self._prefix + "points." + name, []) + if not point_data_changed: + # Check if points were appended or rewritten. + if name in self._point_data: + imax = min(len(point_values), len(self._point_data[name])) + if point_values[:imax] != self._point_data[name][:imax]: + point_data_changed = True + self._point_data[name] = point_values + if point_data_changed: + self.points_rewritten.emit(self._point_data) + else: + self.points_appended.emit(self._point_data) def get_annotations(self) -> list[Annotation]: return self._annotations diff --git a/ndscan/plots/xy_1d.py b/ndscan/plots/xy_1d.py index c762cfad..2b7d4674 100644 --- a/ndscan/plots/xy_1d.py +++ b/ndscan/plots/xy_1d.py @@ -171,7 +171,6 @@ def __init__(self, model: ScanModel, get_alternate_plot_names): self.model.channel_schemata_changed.connect(self._initialise_series) self.model.points_appended.connect(self._update_points) self.model.annotations_changed.connect(self._update_annotations) - # FIXME: Just re-set values instead of throwing away everything. self.model.points_rewritten.connect(self._rewrite) self.selected_point_model = SelectPointFromScanModel(self.model)