Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Rename lists to _lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktBurger committed Apr 8, 2024
1 parent 540ce2f commit f076f25
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
6 changes: 3 additions & 3 deletions pyleco_extras/gui/data_logger/data_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions pyleco_extras/gui/data_logger/data_logger_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions pyleco_extras/gui/data_logger/data_logger_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pyleco_extras/gui/data_logger/data_logger_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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:
Expand Down

0 comments on commit f076f25

Please sign in to comment.