diff --git a/src/nqrduck_broadband/controller.py b/src/nqrduck_broadband/controller.py index 6ea0a07..4b88647 100644 --- a/src/nqrduck_broadband/controller.py +++ b/src/nqrduck_broadband/controller.py @@ -11,15 +11,31 @@ class BroadbandController(ModuleController): start_measurement = pyqtSignal() + set_averages_failure = pyqtSignal() + def __init__(self, module): super().__init__(module) + @pyqtSlot(str, object) def process_signals(self, key: str, value: Measurement): if key == "measurement_data": logger.debug("Received single measurement.") self.module.model.single_measurement = value + + elif key == "failure_set_averages" and value == self.module.view._ui_form.averagesEdit.text(): + logger.debug("Received set averages failure.") + self.set_averages_failure.emit() + @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(str) def change_start_frequency(self, value): diff --git a/src/nqrduck_broadband/resources/broadband_widget.ui b/src/nqrduck_broadband/resources/broadband_widget.ui index 84db5a1..28f46b4 100644 --- a/src/nqrduck_broadband/resources/broadband_widget.ui +++ b/src/nqrduck_broadband/resources/broadband_widget.ui @@ -26,7 +26,7 @@ QLayout::SetDefaultConstraint - + @@ -46,15 +46,46 @@ - - - + + + - Start Frequency: + MHz - + + + + Frequency Step: + + + + + + + MHz + + + + + + + Stop Frequency: + + + + + + + 0.1 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + Qt::LeftToRight @@ -67,25 +98,14 @@ - - + + - MHz + Start Frequency: - - - - - - - - Stop Frequency: - - - - + 70.0 @@ -95,67 +115,22 @@ - + MHz - - - - - - - - Frequency Step: - - - - - - - 0.1 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - MHz - - - - - - - - + Averages: - - - - Qt::Horizontal - - - - 32 - 20 - - - - - - + + 1000 @@ -164,19 +139,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -195,7 +157,7 @@ - + @@ -214,19 +176,6 @@ - - - - - 0 - 0 - - - - Load TNMR File - - - @@ -268,8 +217,8 @@ 0 0 - 281 - 673 + 271 + 719 diff --git a/src/nqrduck_broadband/view.py b/src/nqrduck_broadband/view.py index cb03334..aa9055b 100644 --- a/src/nqrduck_broadband/view.py +++ b/src/nqrduck_broadband/view.py @@ -44,6 +44,10 @@ class BroadbandView(ModuleView): self._ui_form.start_measurementButton.clicked.connect(lambda: self._start_measurement_clicked()) self.start_measurement.connect(lambda: self.module._controller.start_measurement()) + self._ui_form.averagesEdit.editingFinished.connect(lambda: self.on_editing_finished(self._ui_form.averagesEdit.text())) + + self.module.controller.set_averages_failure.connect(self.on_set_averages_failure) + def _start_measurement_clicked(self): # Create a QMessageBox object msg_box = QMessageBox() @@ -94,3 +98,15 @@ class BroadbandView(ModuleView): self._ui_form.broadbandPlot.canvas.ax.set_xlim(right=stop_frequency) self._ui_form.broadbandPlot.canvas.draw() self._ui_form.broadbandPlot.canvas.flush_events() + + @pyqtSlot() + def on_editing_finished(self, value): + logger.debug("Averages editing finished.") + self.sender().setStyleSheet("") + if self.sender() == self._ui_form.averagesEdit: + self.module.controller.set_averages(value) + + @pyqtSlot() + def on_set_averages_failure(self): + logger.debug("Set averages failure.") + self._ui_form.averagesEdit.setStyleSheet("border: 1px solid red;") \ No newline at end of file diff --git a/src/nqrduck_broadband/widget.py b/src/nqrduck_broadband/widget.py index 2921af1..7d31969 100644 --- a/src/nqrduck_broadband/widget.py +++ b/src/nqrduck_broadband/widget.py @@ -35,64 +35,47 @@ class Ui_Form(object): self.label_8.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) self.label_8.setObjectName("label_8") self.verticalLayout.addWidget(self.label_8) - self.horizontalLayout = QtWidgets.QHBoxLayout() - self.horizontalLayout.setObjectName("horizontalLayout") - self.label = QtWidgets.QLabel(parent=Form) - self.label.setObjectName("label") - self.horizontalLayout.addWidget(self.label) + self.gridLayout_3 = QtWidgets.QGridLayout() + self.gridLayout_3.setObjectName("gridLayout_3") + self.label_6 = QtWidgets.QLabel(parent=Form) + self.label_6.setObjectName("label_6") + self.gridLayout_3.addWidget(self.label_6, 1, 3, 1, 1) + self.label_5 = QtWidgets.QLabel(parent=Form) + self.label_5.setObjectName("label_5") + self.gridLayout_3.addWidget(self.label_5, 2, 0, 1, 1) + self.label_2 = QtWidgets.QLabel(parent=Form) + self.label_2.setObjectName("label_2") + self.gridLayout_3.addWidget(self.label_2, 0, 3, 1, 1) + self.label_3 = QtWidgets.QLabel(parent=Form) + self.label_3.setObjectName("label_3") + self.gridLayout_3.addWidget(self.label_3, 1, 0, 1, 1) + self.frequency_stepField = QtWidgets.QLineEdit(parent=Form) + self.frequency_stepField.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter) + self.frequency_stepField.setObjectName("frequency_stepField") + self.gridLayout_3.addWidget(self.frequency_stepField, 2, 2, 1, 1) self.start_frequencyField = QtWidgets.QLineEdit(parent=Form) self.start_frequencyField.setLayoutDirection(QtCore.Qt.LayoutDirection.LeftToRight) self.start_frequencyField.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter) self.start_frequencyField.setObjectName("start_frequencyField") - self.horizontalLayout.addWidget(self.start_frequencyField) - self.label_2 = QtWidgets.QLabel(parent=Form) - self.label_2.setObjectName("label_2") - self.horizontalLayout.addWidget(self.label_2) - self.horizontalLayout.setStretch(2, 1) - self.verticalLayout.addLayout(self.horizontalLayout) - self.horizontalLayout_2 = QtWidgets.QHBoxLayout() - self.horizontalLayout_2.setObjectName("horizontalLayout_2") - self.label_3 = QtWidgets.QLabel(parent=Form) - self.label_3.setObjectName("label_3") - self.horizontalLayout_2.addWidget(self.label_3) + self.gridLayout_3.addWidget(self.start_frequencyField, 0, 2, 1, 1) + self.label = QtWidgets.QLabel(parent=Form) + self.label.setObjectName("label") + self.gridLayout_3.addWidget(self.label, 0, 0, 1, 1) self.stop_frequencyField = QtWidgets.QLineEdit(parent=Form) self.stop_frequencyField.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter) self.stop_frequencyField.setObjectName("stop_frequencyField") - self.horizontalLayout_2.addWidget(self.stop_frequencyField) + self.gridLayout_3.addWidget(self.stop_frequencyField, 1, 2, 1, 1) self.label_4 = QtWidgets.QLabel(parent=Form) self.label_4.setObjectName("label_4") - self.horizontalLayout_2.addWidget(self.label_4) - self.horizontalLayout_2.setStretch(2, 1) - self.verticalLayout.addLayout(self.horizontalLayout_2) - self.horizontalLayout_3 = QtWidgets.QHBoxLayout() - self.horizontalLayout_3.setObjectName("horizontalLayout_3") - self.label_5 = QtWidgets.QLabel(parent=Form) - self.label_5.setObjectName("label_5") - self.horizontalLayout_3.addWidget(self.label_5) - self.frequency_stepField = QtWidgets.QLineEdit(parent=Form) - self.frequency_stepField.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter) - self.frequency_stepField.setObjectName("frequency_stepField") - self.horizontalLayout_3.addWidget(self.frequency_stepField) - self.label_6 = QtWidgets.QLabel(parent=Form) - self.label_6.setObjectName("label_6") - self.horizontalLayout_3.addWidget(self.label_6) - self.horizontalLayout_3.setStretch(2, 1) - self.verticalLayout.addLayout(self.horizontalLayout_3) - self.horizontalLayout_4 = QtWidgets.QHBoxLayout() - self.horizontalLayout_4.setObjectName("horizontalLayout_4") + self.gridLayout_3.addWidget(self.label_4, 2, 3, 1, 1) self.label_7 = QtWidgets.QLabel(parent=Form) self.label_7.setObjectName("label_7") - self.horizontalLayout_4.addWidget(self.label_7) - spacerItem = QtWidgets.QSpacerItem(32, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) - self.horizontalLayout_4.addItem(spacerItem) - self.averagesField = QtWidgets.QLineEdit(parent=Form) - self.averagesField.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter) - self.averagesField.setObjectName("averagesField") - self.horizontalLayout_4.addWidget(self.averagesField) - spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) - self.horizontalLayout_4.addItem(spacerItem1) - self.horizontalLayout_4.setStretch(3, 1) - self.verticalLayout.addLayout(self.horizontalLayout_4) + self.gridLayout_3.addWidget(self.label_7, 3, 0, 1, 1) + self.averagesEdit = QtWidgets.QLineEdit(parent=Form) + self.averagesEdit.setAlignment(QtCore.Qt.AlignmentFlag.AlignRight|QtCore.Qt.AlignmentFlag.AlignTrailing|QtCore.Qt.AlignmentFlag.AlignVCenter) + self.averagesEdit.setObjectName("averagesEdit") + self.gridLayout_3.addWidget(self.averagesEdit, 3, 2, 1, 1) + self.verticalLayout.addLayout(self.gridLayout_3) self.start_measurementButton = QtWidgets.QPushButton(parent=Form) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) @@ -114,14 +97,6 @@ class Ui_Form(object): self.label_10.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) self.label_10.setObjectName("label_10") self.verticalLayout_3.addWidget(self.label_10) - self.load_fileButton = QtWidgets.QPushButton(parent=Form) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Expanding) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.load_fileButton.sizePolicy().hasHeightForWidth()) - self.load_fileButton.setSizePolicy(sizePolicy) - self.load_fileButton.setObjectName("load_fileButton") - self.verticalLayout_3.addWidget(self.load_fileButton) self.file_pathLabel = QtWidgets.QLabel(parent=Form) self.file_pathLabel.setText("") self.file_pathLabel.setObjectName("file_pathLabel") @@ -143,7 +118,7 @@ class Ui_Form(object): self.infoBox.setWidgetResizable(True) self.infoBox.setObjectName("infoBox") self.scrollAreaWidgetContents = QtWidgets.QWidget() - self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 281, 673)) + self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 271, 719)) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -154,7 +129,7 @@ class Ui_Form(object): self.verticalLayout_2.addWidget(self.infoBox) self.verticalLayout_2.setStretch(2, 1) self.verticalLayout_3.addLayout(self.verticalLayout_2) - self.verticalLayout_3.setStretch(3, 1) + self.verticalLayout_3.setStretch(2, 1) self.verticalLayout_4.addLayout(self.verticalLayout_3) self.verticalLayout_4.setStretch(1, 1) self.horizontalLayout_6.addLayout(self.verticalLayout_4) @@ -198,19 +173,18 @@ class Ui_Form(object): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) self.label_8.setText(_translate("Form", "Measurement Settings:")) - self.label.setText(_translate("Form", "Start Frequency:")) - self.start_frequencyField.setText(_translate("Form", "50.0")) + self.label_6.setText(_translate("Form", "MHz")) + self.label_5.setText(_translate("Form", "Frequency Step:")) self.label_2.setText(_translate("Form", "MHz")) self.label_3.setText(_translate("Form", "Stop Frequency:")) + self.frequency_stepField.setText(_translate("Form", "0.1")) + self.start_frequencyField.setText(_translate("Form", "50.0")) + self.label.setText(_translate("Form", "Start Frequency:")) self.stop_frequencyField.setText(_translate("Form", "70.0")) self.label_4.setText(_translate("Form", "MHz")) - self.label_5.setText(_translate("Form", "Frequency Step:")) - self.frequency_stepField.setText(_translate("Form", "0.1")) - self.label_6.setText(_translate("Form", "MHz")) self.label_7.setText(_translate("Form", "Averages:")) - self.averagesField.setText(_translate("Form", "1000")) + self.averagesEdit.setText(_translate("Form", "1000")) self.start_measurementButton.setText(_translate("Form", "Start Measurement")) self.label_10.setText(_translate("Form", "Sequence Settings:")) - self.load_fileButton.setText(_translate("Form", "Load TNMR File")) self.label_9.setText(_translate("Form", "Info Box:")) from nqrduck.contrib.mplwidget import MplWidget