mirror of
https://github.com/nqrduck/nqrduck-measurement.git
synced 2024-11-09 11:50:01 +00:00
Implemented frequency and averages setting.
This commit is contained in:
parent
de4d4fcad6
commit
ada6b7ad4e
4 changed files with 72 additions and 19 deletions
|
@ -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()
|
||||
|
|
|
@ -51,24 +51,24 @@
|
|||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<widget class="QLabel" name="frequencyLabel">
|
||||
<property name="text">
|
||||
<string>Target Frequency</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_2"/>
|
||||
<widget class="QLineEdit" name="averagesEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="averagesLabel">
|
||||
<property name="text">
|
||||
<string>Averages</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
<widget class="QLineEdit" name="frequencyEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
|
|
|
@ -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__()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue