From a3b24f92420420c8968ef4793342c3857c826e57 Mon Sep 17 00:00:00 2001 From: wyzula-jan <133381102+wyzula-jan@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:16:23 +0100 Subject: [PATCH] feat: monitor.py error message popup --- bec_widgets/widgets/monitor/monitor.py | 56 ++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/bec_widgets/widgets/monitor/monitor.py b/bec_widgets/widgets/monitor/monitor.py index 8804ba9d..40491f46 100644 --- a/bec_widgets/widgets/monitor/monitor.py +++ b/bec_widgets/widgets/monitor/monitor.py @@ -136,6 +136,35 @@ config_no_entry = { ], } +config_wrong = { + "plot_settings": { + "background_color": "white", + "num_columns": 5, + "colormap": "plasma", + "scan_types": False, + }, + "plot_data": [ + { + "plot_name": "BPM4i plots vs samx", + "x": {"label": "Motor Y", "signals": [{"name": "samx"}]}, + "y": {"label": "bpm4i", "signals": [{"name": "bpm4i"}]}, + }, + { + "plot_name": "Gauss plots vs samx", + "x": {"label": "Motor X", "signals": [{"name": "samx"}]}, + "y": { + "label": "Gauss", + "signals": [ + {"name": "gauss_bpm"}, + {"name": "non_exist1"}, + {"name": "non_exist2"}, + {"name": "gauss_bpm", "entry": "samx"}, + ], + }, + }, + ], +} + test_config = { "plot_settings": { "background_color": "white", @@ -459,9 +488,30 @@ class BECMonitor(pg.GraphicsLayoutWidget): self.config = validated_config.model_dump() self._init_config() except ValidationError as e: - error_message = f"Monitor configuration validation error: {e}" - print(error_message) - # QMessageBox.critical(self, "Configuration Error", error_message) #TODO do better error popups + error_str = str(e) + formatted_error_message = BECMonitor.format_validation_error(error_str) + + # Display the formatted error message in a popup + QMessageBox.critical(self, "Configuration Error", formatted_error_message) + + @staticmethod + def format_validation_error(error_str: str) -> str: + error_lines = error_str.split("\n") + # The first line contains the number of errors. + error_header = f"
{error_lines[0]}
{location}
{message}