Commit 8871c678 authored by Wout De Nolf's avatar Wout De Nolf Committed by Valentin Valls
Browse files

[scandisplay] treat SCAN_DISPLAY like SCAN_SAVING

parent ccc691a1
......@@ -151,6 +151,7 @@ from bliss import current_session, is_bliss_shell, global_map
from bliss.config.settings import HashSetting
from bliss.common.protocols import Scannable
from bliss.common.utils import get_matching_names, is_pattern
from bliss.scanning.scan_display import ScanDisplay
from bliss.flint.client import plots as flint_plots
from bliss.flint.client import proxy as flint_proxy
......@@ -258,18 +259,15 @@ plot = default_plot
def plotinit(*counters):
"""
Select counter(s) to use for the next scan display.
Select counter(s) to use for the next scan display. Does not affect the current display.
Args:
counters: String, alias, object identifying an object providing data to
record. It can be a counter name, a counter, an axis, an alias.
"""
# Avoid cyclic import
from bliss.scanning.scan import ScanDisplay
sd = ScanDisplay()
scan_display = ScanDisplay()
channel_names = get_channel_names(*counters)
sd.init_next_scan_meta(channel_names)
scan_display.init_next_scan_meta(channel_names)
def plotselect(*counters):
......@@ -283,9 +281,6 @@ def plotselect(*counters):
counters: String, alias, object identifying an object providing data to
record. It can be a counter name, a counter, an axis, an alias.
"""
# Avoid cyclic import
from bliss.scanning.scan import ScanDisplay
scan_display = ScanDisplay()
channel_names = get_channel_names(*counters)
scan_display.displayed_channels = channel_names
......@@ -322,8 +317,6 @@ def get_plotted_counters():
"""
Returns names of displayed counters.
"""
from bliss.scanning.scan import ScanDisplay
scan_display = ScanDisplay()
return scan_display.displayed_channels
......@@ -331,8 +324,6 @@ def get_plotted_counters():
def display_motor(
axis, scan=None, position=None, marker_id=None, label="", silent=True
):
from bliss.scanning.scan import ScanDisplay
if scan is None:
scan = current_session.scans[-1]
scan_display_params = ScanDisplay()
......
......@@ -47,7 +47,7 @@ from bliss.common.cleanup import cleanup, axis as cleanup_axis
from bliss.common.axis import Axis
from bliss.common.cleanup import error_cleanup
from bliss.scanning.toolbox import DefaultAcquisitionChain
from bliss.scanning.scan import Scan, StepScanDataWatch, ScanDisplay
from bliss.scanning.scan import Scan, StepScanDataWatch
from bliss.scanning.acquisition.motor import VariableStepTriggerMaster
from bliss.scanning.acquisition.motor import MeshStepTriggerMaster
from bliss.controllers.motor import CalcController
......@@ -723,8 +723,6 @@ def anscan(
f"axis:{motor.name}", start=start + d, stop=stop + d, points=npoints
)
_update_with_scan_display_meta(scan_info)
scan_params = dict()
scan_params["start"] = starts_list
scan_params["stop"] = stops_list
......@@ -1291,7 +1289,6 @@ def timescan(
scan_info["title"] = template.format(*args)
scan_info.update({"npoints": npoints, "count_time": count_time})
_update_with_scan_display_meta(scan_info)
_log.info("Doing %s", scan_type)
......@@ -1437,12 +1434,3 @@ def pointscan(
return_scan=return_scan,
scan_info=scan_info,
)
def _update_with_scan_display_meta(scan_info: Dict):
"""Read and remove meta stored in the ScanDisplay and feed the scan_info
with."""
scan_display = ScanDisplay()
info = scan_display.pop_scan_meta()
if info is not None:
scan_info["_display_extra"] = info
......@@ -22,6 +22,7 @@ from bliss.common.proxy import Proxy
from bliss.common.logtools import log_warning
from bliss.common.utils import UserNamespace
from bliss.scanning import scan_saving
from bliss.scanning import scan_display
_SESSION_IMPORTERS = set()
......@@ -363,18 +364,23 @@ class Session:
def env_dict(self):
return self.__env_dict
def _set_scan_saving_class(self, scan_saving_class):
scan_saving.set_scan_saving_class(scan_saving_class)
def _set_scan_saving(self, cls=None):
scan_saving.set_scan_saving_class(cls)
self.scan_saving = scan_saving.ScanSaving(self.name)
if is_bliss_shell():
self.env_dict["SCAN_SAVING"] = self.scan_saving
def _set_scan_display(self):
self.scan_display = scan_display.ScanDisplay(self.name)
if is_bliss_shell():
self.env_dict["SCAN_DISPLAY"] = self.scan_display
def enable_esrf_data_policy(self):
self._set_scan_saving_class(scan_saving.ESRFScanSaving)
self._set_scan_saving(cls=scan_saving.ESRFScanSaving)
def disable_esrf_data_policy(self):
self._set_scan_saving_class(None)
self._set_scan_saving()
def load_script(self, script_module_name, session=None):
"""
......@@ -624,11 +630,13 @@ class Session:
env_dict["user_script_run"] = self.user_script_run
scan_saving_class_name = self.__scan_saving_config.get("class")
if scan_saving_class_name is not None:
try:
scan_saving_class = getattr(scan_saving, scan_saving_class_name)
else:
except (AttributeError, TypeError):
scan_saving_class = None
self._set_scan_saving_class(scan_saving_class)
self._set_scan_saving(cls=scan_saving_class)
self._set_scan_display()
env_dict["ALIASES"] = global_map.aliases
......
......@@ -23,7 +23,7 @@ from bliss.common.axis import Axis
from bliss.common.event import dispatcher
from bliss.common import user_status_info
from bliss.scanning.scan import set_scan_watch_callbacks
from bliss.scanning.scan import ScanDisplay
from bliss.scanning.scan_display import ScanDisplay
from bliss import global_map
from bliss.scanning.chain import ChainPreset, ChainIterationPreset
......
......@@ -24,6 +24,7 @@ from bliss.common import event
from bliss import current_session
from bliss.config.conductor.client import get_default_connection
from bliss.scanning.scan_display import ScanDisplay
from bliss.flint import config
from . import plots
......@@ -135,8 +136,6 @@ class FlintClient:
raise
except subprocess.CalledProcessError as e:
# The process have terminated with an error
from bliss.scanning.scan import ScanDisplay
FLINT_LOGGER.error("Flint has terminated with an error.")
scan_display = ScanDisplay()
if not scan_display.flint_output_enabled:
......@@ -157,8 +156,6 @@ class FlintClient:
raise subprocess.CalledProcessError(e.returncode, e.cmd, out, err)
except Exception:
if hasattr(process, "stdout"):
from bliss.scanning.scan import ScanDisplay
FLINT_LOGGER.error("Flint can't start.")
scan_display = ScanDisplay()
if not scan_display.flint_output_enabled:
......@@ -201,9 +198,6 @@ class FlintClient:
if poll_patch is not None:
poll_patch.set_ld_preload(env)
# Imported here to avoid cyclic dependency
from bliss.scanning.scan import ScanDisplay
scan_display = ScanDisplay()
args = [sys.executable, "-m", "bliss.flint"]
args.extend(scan_display.extra_args)
......
......@@ -14,7 +14,6 @@ import sys
import time
import datetime
import collections
import typing
from functools import wraps
import warnings
......@@ -40,12 +39,10 @@ from bliss.scanning.chain import (
)
from bliss.scanning.writer.null import Writer as NullWriter
from bliss.scanning import scan_math
from bliss.scanning.scan_saving import ScanSaving
from bliss.common.logtools import lprint_disable
from louie import saferef
from bliss.common.plot import get_plot
from bliss import __version__ as publisher_version
from bliss.common import deprecation
# STORE THE CALLBACK FUNCTIONS THAT ARE CALLED DURING A SCAN ON THE EVENTS SCAN_NEW, SCAN_DATA, SCAN_END
......@@ -334,165 +331,6 @@ class _WatchDogTask(gevent.Greenlet):
self.__watchdog_timer = gevent.spawn(loop, self._callback.timeout)
class ScanDisplay(ParametersWardrobe):
SLOTS = []
def __init__(self, session_name=None):
"""
This class represents the display parameters for scans for a session.
"""
if session_name is None:
session_name = current_session.name
super().__init__(
"%s:scan_display_params" % session_name,
default_values={
"auto": False,
"motor_position": True,
"_extra_args": [],
"_next_scan_metadata": None,
"displayed_channels": [],
"scan_display_filter_enabled": True,
},
property_attributes=("session", "extra_args", "flint_output_enabled"),
not_removable=(
"auto",
"motor_position",
"displayed_channels",
"scan_display_filter_enabled",
),
)
self.add("_session_name", session_name)
# Compatibility with deprecated property
# his could be removed for BLISS 1.6
stored = self.to_dict()
if "enable_scan_display_filter" is stored:
try:
value = stored["enable_scan_display_filter"]
self.remove(".enable_scan_display_filter")
except NameError:
self.scan_display_filter_enabled = value
def __dir__(self):
keys = super().__dir__()
return keys
def __repr__(self):
return super().__repr__()
@property
def session(self):
""" This give the name of the current session or default if no current session is defined """
return self._session_name
@property
def extra_args(self):
"""Returns the list of extra arguments which will be provided to flint
at it's next creation"""
return self._extra_args
@extra_args.setter
def extra_args(self, extra_args):
"""Set the list of extra arguments to provide to flint at it's
creation"""
# FIXME: It could warn to restart flint in case it is already loaded
if not isinstance(extra_args, (list, tuple)):
raise TypeError(
"SCAN_DISPLAY.extra_args expects a list or a tuple of strings"
)
# Do not load it while it is not needed
from argparse import ArgumentParser
from bliss.flint import config
# Parse and check flint command line arguments
parser = ArgumentParser(prog="Flint")
config.configure_parser_arguments(parser)
try:
parser.parse_args(extra_args)
except SystemExit:
# Avoid to exit while parsing the arguments
pass
self._extra_args = list(extra_args)
@property
def enable_scan_display_filter(self):
"""Compatibility with deprecated code"""
deprecation.deprecated_warning(
"Property",
"enable_scan_display_filter",
replacement="scan_display_filter_enabled",
since_version="1.5",
skip_backtrace_count=1,
)
return self.scan_display_filter_enabled
@enable_scan_display_filter.setter
def enable_scan_display_filter(self, enabled):
"""Compatibility with deprecated code"""
enabled = bool(enabled)
deprecation.deprecated_warning(
"Property",
"enable_scan_display_filter",
replacement="scan_display_filter_enabled",
since_version="1.5",
skip_backtrace_count=1,
)
self.scan_display_filter_enabled = enabled
@property
def flint_output_enabled(self):
"""
Returns true if the output (strout/stderr) is displayed using the
logging system.
This is an helper to display the `disabled` state of the logger
`flint.output`.
"""
from bliss.common import plot
logger = plot.FLINT_OUTPUT_LOGGER
return not logger.disabled
@flint_output_enabled.setter
def flint_output_enabled(self, enabled):
"""
Enable or disable the display of flint output ((strout/stderr) )
using the logging system.
This is an helper to set the `disabled` state of the logger
`flint.output`.
"""
from bliss.common import plot
enabled = bool(enabled)
logger = plot.FLINT_OUTPUT_LOGGER
logger.disabled = not enabled
def init_next_scan_meta(self, display: typing.List[str] = None):
"""Register extra information for the next scan."""
info = self._next_scan_metadata
if info is None:
info = {}
if display is not None:
info["displayed_channels"] = display
self._next_scan_metadata = info
def get_next_scan_channels(self) -> typing.List[str]:
if self._next_scan_metadata is None:
return []
return self._next_scan_metadata["displayed_channels"]
def pop_scan_meta(self) -> typing.Optional[typing.Dict]:
"""Pop the extra information to feed the scan with."""
info = self._next_scan_metadata
self._next_scan_metadata = None
return info
def _get_channels_dict(acq_object, channels_dict):
scalars = channels_dict.setdefault("scalars", [])
scalars_units = channels_dict.setdefault("scalars_units", {})
......@@ -816,6 +654,8 @@ class Scan:
self.__scan_saving = scan_saving
scan_config = scan_saving.get()
self.__scan_display = current_session.scan_display.clone()
self._scan_info["shadow_scan_number"] = self._shadow_scan_number
self._scan_info["save"] = save
self._scan_info["data_writer"] = scan_saving.writer
......@@ -883,8 +723,7 @@ class Scan:
self._init_scan_info_acquisition_chain()
if is_bliss_shell():
scan_display = ScanDisplay()
if scan_display.auto:
if self.__scan_display.auto:
if self.is_flint_recommended():
get_flint(mandatory=False)
......@@ -1341,6 +1180,9 @@ class Scan:
self._scan_info["filename"] = self.writer.filename
self.user_scan_meta = get_user_scan_meta().copy()
self._update_scan_info_with_user_scan_meta()
display_extra = self.__scan_display.pop_scan_meta()
if display_extra:
self._scan_info["_display_extra"] = display_extra
def disconnect_all(self):
for dev in self._devices:
......
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2015-2019 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import typing
from bliss.common import deprecation
from bliss import current_session
from bliss.config.settings import ParametersWardrobe
class ScanDisplay(ParametersWardrobe):
SLOTS = []
def __init__(self, session_name=None):
"""
This class represents the display parameters for scans for a session.
"""
if session_name is None:
session_name = current_session.name
super().__init__(
"%s:scan_display_params" % session_name,
default_values={
"auto": False,
"motor_position": True,
"_extra_args": [],
"_next_scan_metadata": None,
"displayed_channels": [],
"scan_display_filter_enabled": True,
},
property_attributes=("session", "extra_args", "flint_output_enabled"),
not_removable=(
"auto",
"motor_position",
"displayed_channels",
"scan_display_filter_enabled",
),
)
self.add("_session_name", session_name)
# Compatibility with deprecated property
# his could be removed for BLISS 1.6
stored = self.to_dict()
if "enable_scan_display_filter" is stored:
try:
value = stored["enable_scan_display_filter"]
self.remove(".enable_scan_display_filter")
except NameError:
self.scan_display_filter_enabled = value
def __dir__(self):
keys = super().__dir__()
return keys
def __repr__(self):
return super().__repr__()
def clone(self):
new_scan_display = self.__class__(session_name=self._session_name)
for s in self.SLOTS:
setattr(new_scan_display, s, getattr(self, s))
return new_scan_display
@property
def session(self):
""" This give the name of the current session or default if no current session is defined """
return self._session_name
@property
def extra_args(self):
"""Returns the list of extra arguments which will be provided to flint
at it's next creation"""
return self._extra_args
@extra_args.setter
def extra_args(self, extra_args):
"""Set the list of extra arguments to provide to flint at it's
creation"""
# FIXME: It could warn to restart flint in case it is already loaded
if not isinstance(extra_args, (list, tuple)):
raise TypeError(
"SCAN_DISPLAY.extra_args expects a list or a tuple of strings"
)
# Do not load it while it is not needed
from argparse import ArgumentParser
from bliss.flint import config
# Parse and check flint command line arguments
parser = ArgumentParser(prog="Flint")
config.configure_parser_arguments(parser)
try:
parser.parse_args(extra_args)
except SystemExit:
# Avoid to exit while parsing the arguments
pass
self._extra_args = list(extra_args)
@property
def enable_scan_display_filter(self):
"""Compatibility with deprecated code"""
deprecation.deprecated_warning(
"Property",
"enable_scan_display_filter",
replacement="scan_display_filter_enabled",
since_version="1.5",
skip_backtrace_count=1,
)
return self.scan_display_filter_enabled
@enable_scan_display_filter.setter
def enable_scan_display_filter(self, enabled):
"""Compatibility with deprecated code"""
enabled = bool(enabled)
deprecation.deprecated_warning(
"Property",
"enable_scan_display_filter",
replacement="scan_display_filter_enabled",
since_version="1.5",
skip_backtrace_count=1,
)
self.scan_display_filter_enabled = enabled
@property
def flint_output_enabled(self):
"""
Returns true if the output (strout/stderr) is displayed using the
logging system.
This is an helper to display the `disabled` state of the logger
`flint.output`.
"""
from bliss.common import plot
logger = plot.FLINT_OUTPUT_LOGGER
return not logger.disabled
@flint_output_enabled.setter
def flint_output_enabled(self, enabled):
"""
Enable or disable the display of flint output ((strout/stderr) )
using the logging system.
This is an helper to set the `disabled` state of the logger
`flint.output`.
"""
from bliss.common import plot
enabled = bool(enabled)
logger = plot.FLINT_OUTPUT_LOGGER
logger.disabled = not enabled
def init_next_scan_meta(self, display: typing.List[str] = None):
"""Register extra information for the next scan."""
info = self._next_scan_metadata
if info is None:
info = {}
if display is not None:
info["displayed_channels"] = display
self._next_scan_metadata = info
def get_next_scan_channels(self) -> typing.List[str]:
if self._next_scan_metadata is None:
return []
return self._next_scan_metadata["displayed_channels"]
def pop_scan_meta(self) -> typing.Optional[typing.Dict]:
"""Pop the extra information to feed the scan with."""
info = self._next_scan_metadata
self._next_scan_metadata = None
return info
......@@ -6,7 +6,7 @@ from bliss import current_session, global_map
from bliss.common.types import _countable, _scannable
from bliss.common.plot import display_motor
from bliss.scanning.scan import Scan
from bliss.scanning.scan import ScanDisplay
from bliss.scanning.scan_display import ScanDisplay
from bliss.common.utils import shorten_signature
"""
......
......@@ -121,9 +121,6 @@ def initialize(session_name=None):
env_dict = __main__.__dict__
exec("from bliss.shell.standard import *", env_dict)
from bliss.scanning.scan import ScanDisplay
env_dict["SCAN_DISPLAY"] = ScanDisplay(session.name)
env_dict["history"] = lambda: print("Please press F3-key to view history!")
......
......@@ -87,9 +87,7 @@ from bliss.scanning.scan_tools import (
)
from bliss.common.plot import meshselect # noqa: F401
from bliss.common import plot as plot_module
from bliss.shell.cli import user_dialog, pt_widgets
from bliss.scanning.scan import ScanDisplay
from tabulate import tabulate
......
......@@ -9,7 +9,7 @@
from bliss.common import scans
from bliss.scanning.acquisition.motor import SoftwarePositionTriggerMaster
from bliss.scanning.acquisition.counter import SamplingCounterAcquisitionSlave
from bliss.scanning.scan import Scan