Commit 8e7b3b4e authored by Valentin Valls's avatar Valentin Valls
Browse files

Allow to reach a live plot by name

parent 7d0daabe
......@@ -524,6 +524,7 @@ class FlintClient:
def get_live_plot(
kind: typing.Optional[str] = None,
name: str = None,
image_detector: typing.Optional[str] = None,
mca_detector: typing.Optional[str] = None,
onedim_detector: typing.Optional[str] = None,
......@@ -540,16 +541,21 @@ class FlintClient:
onedim_detector: Name of the detector displaying one dim data.
if kind is not None:
if kind == "default-curve":
if kind in ("curve", "default-curve"):
plot_class = plots.LiveCurvePlot
plot_type = "curve"
elif kind == "default-scatter":
elif kind in ("scatter", "default-scatter"):
plot_class = plots.LiveScatterPlot
plot_type = "scatter"
raise ValueError(f"Unexpected plot kind '{kind}'.")
plot_id = self.get_default_live_scan_plot(plot_type)
if name is not None:
plot_id = self.get_live_scan_plot_by_name(
plot_name=name, plot_type=plot_type
plot_id = self.get_default_live_scan_plot(plot_type)
if plot_id is None:
raise ValueError(f"No {plot_type} plot available")
......@@ -182,6 +182,31 @@ class FlintApi:
return plot_classes[plot_type]
def get_live_scan_plot_by_name(self, plot_type, plot_name: str):
"""Returns the identifier of the default plot according it's type.
Basically returns the first plot of this kind.
Returns `None` is nothing found
plot_class = self.__get_plot_class_by_kind(plot_type)
workspace = self.__flintModel.workspace()
for iwidget, widget in enumerate(workspace.widgets()):
if not hasattr(widget, "scan") or not hasattr(widget, "plotModel"):
# Skip widgets which does not display scans (like profile)
# FIXME: Use interface to flag classes
plot = widget.plotModel()
if plot is None:
if not isinstance(plot, plot_class):
if != plot_name:
return f"live:{iwidget}"
return None
def get_default_live_scan_plot(self, plot_type):
"""Returns the identifier of the default plot according it's type.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment