diff --git a/src/robofish/io/file.py b/src/robofish/io/file.py index 526155bfed08217ead92e86fc55986fff4c79d6c..a2eca16d6aa019dc63651b1a10483337e837f27c 100644 --- a/src/robofish/io/file.py +++ b/src/robofish/io/file.py @@ -902,8 +902,12 @@ class File(h5py.File): points = [grid_points, goal_point, target_line] if options["show_text"]: - label_top_right = ax_text.text(0, 0.95, "", fontsize=10) - label_bottom_right = ax_text.text(0, 0, "", fontsize=10) + label_top_right = ax_text.text( + 0, 0.90, "", fontsize=9, fontfamily="monospace" + ) + label_bottom_right = ax_text.text( + 0, 0.1, "", fontsize=9, fontfamily="monospace" + ) labels = [label_top_right, label_bottom_right] else: labels = [] @@ -935,20 +939,25 @@ class File(h5py.File): def get_attributes_as_text() -> str: attrs = {} + width = 92 for key, val in self.attrs.items(): if key == "experiment_setup": continue attrs[key] = val - separator = "-" * 130 + "\n" + separator = "\u2500" * width + "\n" text = "" text += separator - text += "experiment_setup:\n%s\n" % utils.wrap_newline( - self.attrs["experiment_setup"], 60 + text += "experiment_setup:\n" + text += utils.wrap_newline( + text=self.attrs["experiment_setup"], + width=width, + justify=True, + maxlines=10, ) - text += separator + text += "\n" + separator text += "\n".join( [ - "%s: %s" % (key, utils.wrap_newline(val, 60)) + f"{key}: {utils.wrap_newline(text=val, width=width-len(key)-2, justify=True, maxlines=3)}" for key, val in attrs.items() ] ) diff --git a/src/robofish/io/utils.py b/src/robofish/io/utils.py index 1f704fb8e2319651ee58c36287f08f9d5970b2d6..0144f3953de074520a8d9628c0a0e876140c0d0d 100644 --- a/src/robofish/io/utils.py +++ b/src/robofish/io/utils.py @@ -1,6 +1,6 @@ import robofish.io import numpy as np -from typing import Union, Iterable +from typing import Union, Iterable, Optional from pathlib import Path from tqdm import tqdm import textwrap @@ -123,5 +123,14 @@ def get_all_data_from_paths( return all_data, expected_settings -def wrap_newline(text, width=60): - return "\n".join(textwrap.wrap(str(text), width)) +def wrap_newline( + text: str, width: int = 60, justify: bool = False, maxlines: Optional[int] = None +) -> str: + text = str(text).strip() + if justify: + text = text.replace("\n", " ") + lines = textwrap.wrap(text, width) + if maxlines and len(lines) > maxlines: + lines = lines[:maxlines] + lines[-1] = lines[-1][: width - 3] + "..." + return "\n".join(lines)