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

Commit

Permalink
Use text edit for variables
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktBurger committed Jul 4, 2024
1 parent 4db5cdb commit 19db743
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 63 deletions.
109 changes: 61 additions & 48 deletions pyleco_extras/gui/data_logger/data/DataLogger.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>248</width>
<height>321</height>
<height>353</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -49,7 +49,7 @@
<property name="bottomMargin">
<number>3</number>
</property>
<item row="2" column="3">
<item row="2" column="2">
<widget class="QGroupBox" name="gbValue">
<property name="toolTip">
<string>Takes effect at next measurement start.</string>
Expand Down Expand Up @@ -109,51 +109,7 @@
</layout>
</widget>
</item>
<item row="4" column="0" colspan="4">
<widget class="QLineEdit" name="leVariables">
<property name="toolTip">
<string>Variables to save. This line is appended to the header. Use time for the time in seconds today.</string>
</property>
</widget>
</item>
<item row="5" column="2" colspan="2">
<widget class="QLabel" name="lbValues">
<property name="text">
<string>Values</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<widget class="QPlainTextEdit" name="leHeader">
<property name="toolTip">
<string>Header of the save file.</string>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QLineEdit" name="leSavedName">
<property name="toolTip">
<string>Name of the saved file.</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="lbVariables">
<property name="toolTip">
<string>Variable values of the last data point.</string>
</property>
<property name="text">
<string>Variables</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="gbTrigger">
<property name="toolTip">
<string>Takes effect immediately!</string>
Expand Down Expand Up @@ -223,6 +179,64 @@
</layout>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QPlainTextEdit" name="leHeader">
<property name="toolTip">
<string>Header of the save file.</string>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QLineEdit" name="leSavedName">
<property name="toolTip">
<string>Name of the saved file.</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPlainTextEdit" name="teVariables">
<property name="toolTip">
<string>Variables to save. This line is appended to the header. Use time for the time in seconds today. Use leading period to repeat the publisher name.</string>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="teValues">
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down Expand Up @@ -442,7 +456,6 @@
<tabstop>cbValueMean</tabstop>
<tabstop>cbRepeat</tabstop>
<tabstop>leHeader</tabstop>
<tabstop>leVariables</tabstop>
<tabstop>leSavedName</tabstop>
<tabstop>tabWidget</tabstop>
</tabstops>
Expand Down
2 changes: 1 addition & 1 deletion pyleco_extras/gui/data_logger/data_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def save_data(self, meta: Optional[dict] = None, suffix: str = "") -> str:
file_name = self.communicator.ask_handler(
method="save_data",
timeout=30,
header=f"{self.leHeader.toPlainText()}\n{self.leVariables.text()}",
header=f"{self.leHeader.toPlainText()}\n{self.teVariables.toPlainText()}",
meta=meta,
suffix=suffix,
)
Expand Down
26 changes: 16 additions & 10 deletions pyleco_extras/gui/data_logger/data_logger_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ class DataLoggerBase(LECOBaseMainWindowDesigner):
cbValueMean: QtWidgets.QRadioButton
cbRepeat: QtWidgets.QCheckBox
leHeader: QtWidgets.QPlainTextEdit
leVariables: QtWidgets.QLineEdit
lbVariables: QtWidgets.QLabel
lbValues: QtWidgets.QLabel
teVariables: QtWidgets.QPlainTextEdit
teValues: QtWidgets.QPlainTextEdit

tabWidget: QtWidgets.QTabWidget
toolBar: QtWidgets.QToolBar
Expand Down Expand Up @@ -279,16 +278,24 @@ def get_configuration(self) -> dict[str, Any]:
return config

def _read_variables_and_units(self) -> None:
var_text = self.leVariables.text().replace(": ", ":").replace(",", " ")
var_text = self.teVariables.toPlainText().replace(": ", ":").replace(",", " ")
raw_vars = var_text.split()
last_name = ""
variables = []
units = {}
for raw_var in raw_vars:
if ":" in raw_var:
v, u = raw_var.split(":", maxsplit=1)
units[v] = u
else:
v = raw_var
u = None
if len(split := v.rsplit(".", maxsplit=1)) > 1:
if split[0]:
last_name = split[0]
elif last_name:
v = ".".join((last_name, split[1]))
if u is not None:
units[v] = u
variables.append(v)
self._variables = variables
self._units = units
Expand All @@ -298,10 +305,10 @@ def _update_variables_and_units(self) -> None:
vars = []
for var in self._variables:
if unit := self._units.get(var):
vars.append(":".join((var, unit)))
vars.append(": ".join((var, unit)))
else:
vars.append(var)
self.leVariables.setText(", ".join(vars))
self.teVariables.setPlainText(",\n".join(vars))

@property
def variables(self) -> Iterable[str]:
Expand Down Expand Up @@ -443,7 +450,7 @@ def _set_config(
if variables is not None:
self.variables = variables
if variablesText is not None:
self.leVariables.setText(variablesText)
self.teVariables.setPlainText(variablesText)
if units is not None:
self.units = units
if header is not None:
Expand Down Expand Up @@ -617,8 +624,7 @@ def make_data_point(self) -> None:
@pyqtSlot(dict)
def show_data_point(self, datapoint: dict[str, Any]) -> None:
self.show_list_length()
self.lbVariables.setText("\n".join(datapoint.keys()))
self.lbValues.setText(
self.teValues.setPlainText(
"\n".join(
f"{value} {self.current_units.get(variable, '')}"
for variable, value in datapoint.items()
Expand Down
7 changes: 4 additions & 3 deletions pyleco_extras/gui/data_logger/data_logger_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def setup_buttons(self) -> None:
self.cbRepeat.stateChanged.connect(self.toggleRepeat)
# Text
self.leHeader.textChanged.connect(self.set_header)
self.leVariables.textEdited.connect(self.set_variables)
self.teVariables.textChanged.connect(self.set_variables)

def read_configuration(self) -> dict[str, Any]:
try:
Expand Down Expand Up @@ -237,8 +237,9 @@ def set_header(self) -> None:
text = self.leHeader.toPlainText()
self.set_property("header", text)

@pyqtSlot(str)
def set_variables(self, text: str) -> None:
@pyqtSlot()
def set_variables(self) -> None:
text = self.teVariables.toPlainText()
self.set_property("variablesText", text)

"Regular readout"
Expand Down
3 changes: 2 additions & 1 deletion pyleco_extras/gui/data_logger/data_logger_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def setup_buttons(self) -> None:
self.cbValueMean,
self.cbRepeat,
self.leHeader,
self.leVariables,
self.teVariables,
self.teValues,
):
widget.setEnabled(False)
self.actionStart.setToolTip("Load a measurement file.")
Expand Down

0 comments on commit 19db743

Please sign in to comment.