diff --git a/waveform_editor/annotations.py b/waveform_editor/annotations.py index ffd49a7a..9eff3e04 100644 --- a/waveform_editor/annotations.py +++ b/waveform_editor/annotations.py @@ -3,6 +3,12 @@ class Annotations(UserList): + def __str__(self): + sorted_annotations = sorted(self, key=lambda ann: ann["row"]) + return "\n".join( + f"Line {a['row'] + 1}: {a['text']}" for a in sorted_annotations + ) + def add_annotations(self, annotations): """Merge another Annotations instance into this instance by appending its annotations. diff --git a/waveform_editor/waveform_editor_gui.py b/waveform_editor/waveform_editor_gui.py index d4fe5bc5..d0d06654 100644 --- a/waveform_editor/waveform_editor_gui.py +++ b/waveform_editor/waveform_editor_gui.py @@ -27,12 +27,12 @@ yaml_parser = YamlParser() yaml_alert = pn.pane.Alert( - "### The YAML did not parse correctly! (see editor)", + "### The YAML did not parse correctly!", alert_type="danger", visible=False, ) error_alert = pn.pane.Alert( - "### There was an error in the YAML configuration (see editor).", + "### There was an error in the YAML configuration.", alert_type="warning", visible=False, ) @@ -41,14 +41,19 @@ def update_plot(value): yaml_alert.visible = error_alert.visible = False yaml_parser.parse_waveforms(value) + annotations = yaml_parser.waveform.annotations - code_editor.annotations = list(yaml_parser.waveform.annotations) + code_editor.annotations = list(annotations) code_editor.param.trigger("annotations") # Show alert when there is a yaml parsing error if yaml_parser.has_yaml_error: + yaml_alert.object = f"### The YAML did not parse correctly\n {annotations}" yaml_alert.visible = True elif code_editor.annotations: + error_alert.object = ( + f"### There was an error in the YAML configuration\n {annotations}" + ) error_alert.visible = True return yaml_parser.plot_tendencies()