diff --git a/src/nqrduck_measurement/controller.py b/src/nqrduck_measurement/controller.py index 83a3b05..0be3b26 100644 --- a/src/nqrduck_measurement/controller.py +++ b/src/nqrduck_measurement/controller.py @@ -1,14 +1,29 @@ import logging -from PyQt6.QtCore import pyqtSlot +from PyQt6.QtCore import pyqtSlot, pyqtSignal +from PyQt6.QtWidgets import QWidget from nqrduck.module.module_controller import ModuleController from nqrduck_spectrometer.measurement import Measurement logger = logging.getLogger(__name__) class MeasurementController(ModuleController): + + set_frequency_failure = pyqtSignal() + set_averages_failure = pyqtSignal() + def __init__(self, module): super().__init__(module) + @pyqtSlot(str) + def set_frequency(self, value): + logger.debug("Setting frequency to: " + value) + self.module.nqrduck_signal.emit("set_frequency", value) + + @pyqtSlot(str) + def set_averages(self, value): + logger.debug("Setting averages to: " + value) + self.module.nqrduck_signal.emit("set_averages", value) + @pyqtSlot() def change_view_mode(self): logger.debug("Changing view mode.") @@ -37,3 +52,11 @@ class MeasurementController(ModuleController): logger.debug("Received measurement error.") self.module.view.measurement_dialog.hide() self.module.nqrduck_signal.emit("notification", ["Error", "Error during measurement."]) + + elif key == "failure" and value[0] == "set_frequency" and self.module.view._ui_form.frequencyEdit.text() == value[1]: + logger.debug("Received set frequency failure.") + self.set_frequency_failure.emit() + + elif key == "failure" and value[0] == "set_averages" and self.module.view._ui_form.averagesEdit.text() == value[1]: + logger.debug("Received set averages failure.") + self.set_averages_failure.emit() diff --git a/src/nqrduck_measurement/resources/measurement_widget.ui b/src/nqrduck_measurement/resources/measurement_widget.ui index ffc2fbb..8e9b101 100644 --- a/src/nqrduck_measurement/resources/measurement_widget.ui +++ b/src/nqrduck_measurement/resources/measurement_widget.ui @@ -51,24 +51,24 @@ - + Target Frequency - + - + Averages - + diff --git a/src/nqrduck_measurement/view.py b/src/nqrduck_measurement/view.py index 9f74cb2..f88ddb1 100644 --- a/src/nqrduck_measurement/view.py +++ b/src/nqrduck_measurement/view.py @@ -52,6 +52,15 @@ class MeasurementView(ModuleView): self._ui_form.buttonStart.clicked.connect(self.on_measurement_start_button_clicked) self._ui_form.fftButton.clicked.connect(self.module.controller.change_view_mode) + self._ui_form.frequencyEdit.editingFinished.connect(lambda: self.on_editing_finished(self._ui_form.frequencyEdit.text())) + self._ui_form.averagesEdit.editingFinished.connect(lambda: self.on_editing_finished(self._ui_form.averagesEdit.text())) + + self.module.controller.set_frequency_failure.connect(self.on_set_frequency_failure) + self.module.controller.set_averages_failure.connect(self.on_set_averages_failure) + + # Call validator for buttonStart + + def init_plotter(self): plotter = self._ui_form.plotter plotter.canvas.ax.clear() @@ -105,6 +114,27 @@ class MeasurementView(ModuleView): logger.debug("Measurement start button clicked.") self.module.controller.start_measurement() + @pyqtSlot(str) + def on_editing_finished(self, value): + logger.debug("Editing finished.") + self.sender().setStyleSheet("") + if self.sender() == self._ui_form.frequencyEdit: + self.module.controller.set_frequency(value) + elif self.sender() == self._ui_form.averagesEdit: + self.module.controller.set_averages(value) + + @pyqtSlot() + def on_set_frequency_failure(self): + """Slot for when the set frequency signal fails.""" + logger.debug("Set frequency failure.") + self._ui_form.frequencyEdit.setStyleSheet("border: 1px solid red;") + + @pyqtSlot() + def on_set_averages_failure(self): + """Slot for when the set averages signal fails.""" + logger.debug("Set averages failure.") + self._ui_form.averagesEdit.setStyleSheet("border: 1px solid red;") + class MeasurementDialog(QDialog): def __init__(self): super().__init__() diff --git a/src/nqrduck_measurement/widget.py b/src/nqrduck_measurement/widget.py index e3ee105..53fb7bc 100644 --- a/src/nqrduck_measurement/widget.py +++ b/src/nqrduck_measurement/widget.py @@ -39,18 +39,18 @@ class Ui_Form(object): self.settingsLayout.addLayout(self.spectrometerLayout) self.gridLayout = QtWidgets.QGridLayout() self.gridLayout.setObjectName("gridLayout") - self.label = QtWidgets.QLabel(parent=Form) - self.label.setObjectName("label") - self.gridLayout.addWidget(self.label, 0, 0, 1, 1) - self.lineEdit_2 = QtWidgets.QLineEdit(parent=Form) - self.lineEdit_2.setObjectName("lineEdit_2") - self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1) - self.label_2 = QtWidgets.QLabel(parent=Form) - self.label_2.setObjectName("label_2") - self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) - self.lineEdit = QtWidgets.QLineEdit(parent=Form) - self.lineEdit.setObjectName("lineEdit") - self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) + self.frequencyLabel = QtWidgets.QLabel(parent=Form) + self.frequencyLabel.setObjectName("frequencyLabel") + self.gridLayout.addWidget(self.frequencyLabel, 0, 0, 1, 1) + self.averagesEdit = QtWidgets.QLineEdit(parent=Form) + self.averagesEdit.setObjectName("averagesEdit") + self.gridLayout.addWidget(self.averagesEdit, 1, 1, 1, 1) + self.averagesLabel = QtWidgets.QLabel(parent=Form) + self.averagesLabel.setObjectName("averagesLabel") + self.gridLayout.addWidget(self.averagesLabel, 1, 0, 1, 1) + self.frequencyEdit = QtWidgets.QLineEdit(parent=Form) + self.frequencyEdit.setObjectName("frequencyEdit") + self.gridLayout.addWidget(self.frequencyEdit, 0, 1, 1, 1) self.settingsLayout.addLayout(self.gridLayout) self.buttonStart = QtWidgets.QPushButton(parent=Form) self.buttonStart.setObjectName("buttonStart") @@ -95,8 +95,8 @@ class Ui_Form(object): Form.setWindowTitle(_translate("Form", "Form")) self.titleLable.setText(_translate("Form", "Single Frequency Measurement: ")) self.spectrometerLabel.setText(_translate("Form", "Spectrometer:")) - self.label.setText(_translate("Form", "Target Frequency")) - self.label_2.setText(_translate("Form", "Averages")) + self.frequencyLabel.setText(_translate("Form", "Target Frequency")) + self.averagesLabel.setText(_translate("Form", "Averages")) self.buttonStart.setText(_translate("Form", "Start Measurement")) self.fftButton.setText(_translate("Form", "FFT")) from nqrduck.contrib.mplwidget import MplWidget