From f076f2560585aab52b7072272289df6db2069ce2 Mon Sep 17 00:00:00 2001 From: Benedikt Burger <67148916+BenediktBurger@users.noreply.github.com> Date: Mon, 8 Apr 2024 10:10:06 +0200 Subject: [PATCH] Rename lists to _lists. --- pyleco_extras/gui/data_logger/data_logger.py | 6 +++--- .../gui/data_logger/data_logger_base.py | 17 +++++++++++------ .../gui/data_logger/data_logger_remote.py | 4 ++-- .../gui/data_logger/data_logger_viewer.py | 8 ++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/pyleco_extras/gui/data_logger/data_logger.py b/pyleco_extras/gui/data_logger/data_logger.py index a00d75f..4e35caa 100644 --- a/pyleco_extras/gui/data_logger/data_logger.py +++ b/pyleco_extras/gui/data_logger/data_logger.py @@ -100,12 +100,12 @@ def setup_timers(self): self.auto_save_timer.start(1000000000) # just a number, will be changed in setSettings @property - def lists(self) -> dict[str, list[Any]]: + def _lists(self) -> dict[str, list[Any]]: # for the plots return self.listener.message_handler.lists - @lists.setter - def lists(self, value) -> None: + @_lists.setter + def _lists(self, value) -> None: pass # don't do anything # Control Application diff --git a/pyleco_extras/gui/data_logger/data_logger_base.py b/pyleco_extras/gui/data_logger/data_logger_base.py index 814ece9..19928f2 100644 --- a/pyleco_extras/gui/data_logger/data_logger_base.py +++ b/pyleco_extras/gui/data_logger/data_logger_base.py @@ -118,18 +118,23 @@ def setup_buttons(self) -> None: def setup_lists(self): self.plots: list[PlotGroupWidget] = [] - self.lists: dict[str, list[Any]] = {} + self._lists: dict[str, list[Any]] = {} self.current_units: dict[str, str] = {} # for the current measurement self._variables: Iterable[str] self._units: dict[str, str] + @property + def lists(self) -> dict[str, list[Any]]: + """Dictionary of data lists, for backward compatibility.""" + return self._lists + def cut_lists(self): """Cut the lists to max length.""" if self.data_length_limit == 0: return # cutting is disabled log.debug(f"Lists cut to length {self.data_length_limit}.") - for key, li in self.lists.items(): - self.lists[key] = li[-self.data_length_limit:] + for key, li in self._lists.items(): + self._lists[key] = li[-self.data_length_limit:] def setup_timers(self) -> None: # Timers @@ -152,7 +157,7 @@ def restore_configuration(self) -> None: """Restore the last configuration""" self.set_configuration(self.read_configuration()) for variable in self.variables: - self.lists[variable] = [] + self._lists[variable] = [] @pyqtSlot() def closeEvent(self, event) -> None: @@ -600,7 +605,7 @@ def show_data_point(self, datapoint: dict[str, Any]) -> None: def show_list_length(self): try: - length = len(self.lists[list(self.lists.keys())[0]]) + length = len(self._lists[list(self._lists.keys())[0]]) except IndexError: length = 0 else: @@ -612,7 +617,7 @@ def show_list_length(self): def copy_last_data_point(self) -> None: """Copy the last datapoint to the clipboard.""" text_elements = [] - for key, li in self.lists.items(): + for key, li in self._lists.items(): text_elements.append(f"{key}:\t {li[-1]} {self.current_units.get(key, '')}") clipboard = QtWidgets.QApplication.instance().clipboard() # type: ignore clipboard.setText("\n".join(text_elements)) diff --git a/pyleco_extras/gui/data_logger/data_logger_remote.py b/pyleco_extras/gui/data_logger/data_logger_remote.py index 9bac2ab..00dd17e 100644 --- a/pyleco_extras/gui/data_logger/data_logger_remote.py +++ b/pyleco_extras/gui/data_logger/data_logger_remote.py @@ -247,9 +247,9 @@ def _add_datapoint_to_lists(self, datapoint: dict[str, Any]) -> None: if value is None: value = nan try: - self.lists[key].append(value) + self._lists[key].append(value) except KeyError: - self.lists[key] = [value] + self._lists[key] = [value] def _handle_new_data_point(self, datapoint: dict[str, Any], remote_length: int): self._add_datapoint_to_lists(datapoint=datapoint) diff --git a/pyleco_extras/gui/data_logger/data_logger_viewer.py b/pyleco_extras/gui/data_logger/data_logger_viewer.py index 5f9fdb8..d643d43 100644 --- a/pyleco_extras/gui/data_logger/data_logger_viewer.py +++ b/pyleco_extras/gui/data_logger/data_logger_viewer.py @@ -49,7 +49,7 @@ def __init__(self, name: str = "DataLoggerViewer", **kwargs) -> None: # Add dictionaries for internal storage. self.plots = [] - self.lists = {} + self._lists = {} self.units = {} self.last_path = "" # last path used @@ -105,11 +105,11 @@ def start(self): self.last_path = file_name path = Path(file_name) header, data, meta = load_datalogger_file(path) - self.lists = data + self._lists = data self.leHeader.setPlainText(header.rsplit("\n", maxsplit=1)[0]) self.set_configuration(meta.get("configuration", {})) if "time" in data.keys() and "time_h" not in data.keys(): - self.lists["time_h"] = list(np.array(data["time"]) / 3600) + self._lists["time_h"] = list(np.array(data["time"]) / 3600) self.variables = self.variables + ["time_h"] # type: ignore d = self.units d["time_h"] = "h" @@ -120,7 +120,7 @@ def start(self): self.signals.started.emit() # get length of data points: try: - length = len(self.lists[list(self.lists).pop()]) + length = len(self._lists[list(self._lists).pop()]) except IndexError: pass else: