diff --git a/src/nqrduck_broadband/controller.py b/src/nqrduck_broadband/controller.py index c2e56e3..5ae50a7 100644 --- a/src/nqrduck_broadband/controller.py +++ b/src/nqrduck_broadband/controller.py @@ -112,9 +112,7 @@ class BroadbandController(ModuleController): self.module.view.add_info_text("Starting broadband measurement.") # Start the first measurement - self.module.view.add_info_text("Starting measurement at frequency: " + str(start_frequency)) - self.module.nqrduck_signal.emit("set_frequency", str(start_frequency)) - self.module.nqrduck_signal.emit("start_measurement", None) + self.start_single_measurement(start_frequency) @pyqtSlot() @@ -129,9 +127,17 @@ class BroadbandController(ModuleController): # Get the next frequency to measure next_frequency = self.module.model.current_broadband_measurement.get_next_measurement_frequency() logger.debug("Next frequency: " + str(next_frequency)) - # Start the next measurement - self.module.view.add_info_text("Starting measurement at frequency: " + str(next_frequency)) - self.module.nqrduck_signal.emit("set_frequency", str(next_frequency)) - self.module.nqrduck_signal.emit("start_measurement", None) + self.start_single_measurement(next_frequency) else: - self.module.view.add_info_text("Broadband measurement finished.") \ No newline at end of file + self.module.view.add_info_text("Broadband measurement finished.") + + def start_single_measurement(self, frequency : float) -> None: + """Starts a single measurement. + + Args: + frequency (float): Frequency in MHz. + """ + logger.debug("Starting single measurement.") + self.module.view.add_info_text("Starting measurement at frequency: " + str(frequency)) + self.module.nqrduck_signal.emit("set_frequency", str(frequency)) + self.module.nqrduck_signal.emit("start_measurement", None) \ No newline at end of file diff --git a/src/nqrduck_broadband/model.py b/src/nqrduck_broadband/model.py index cdec199..d985825 100644 --- a/src/nqrduck_broadband/model.py +++ b/src/nqrduck_broadband/model.py @@ -14,6 +14,7 @@ class BroadbandModel(ModuleModel): start_frequency_changed = pyqtSignal(float) stop_frequency_changed = pyqtSignal(float) + frequency_step_changed = pyqtSignal(float) LUT_changed = pyqtSignal() def __init__(self, module) -> None: @@ -48,6 +49,7 @@ class BroadbandModel(ModuleModel): @frequency_step.setter def frequency_step(self, value): self._frequency_step = value + self.frequency_step_changed.emit(value) @property def current_broadband_measurement(self): diff --git a/src/nqrduck_broadband/view.py b/src/nqrduck_broadband/view.py index dd2fce9..debda48 100644 --- a/src/nqrduck_broadband/view.py +++ b/src/nqrduck_broadband/view.py @@ -52,6 +52,7 @@ class BroadbandView(ModuleView): self.module.model.start_frequency_changed.connect(self.on_start_frequency_change) self.module.model.stop_frequency_changed.connect(self.on_stop_frequency_change) + self.module.model.frequency_step_changed.connect(self.on_frequency_step_change) self._ui_form.start_measurementButton.clicked.connect(self.start_measurement_clicked) self.start_broadband_measurement.connect(self.module._controller.start_broadband_measurement) @@ -149,6 +150,19 @@ class BroadbandView(ModuleView): self._ui_form.broadbandPlot.canvas.flush_events() self._ui_form.stop_frequencyField.setText(str(stop_frequency* 1e-6)) + @pyqtSlot(float) + def on_frequency_step_change(self, frequency_step : float) -> None: + """This method is called when the frequency step is changed. + It adjusts the view to the new frequency step. + """ + logger.debug("Adjusting view to new frequency step: " + str(frequency_step * 1e-6)) + self._ui_form.broadbandPlot.canvas.ax.set_xlim(right=frequency_step*1e-6) + self._ui_form.broadbandPlot.canvas.draw() + self._ui_form.broadbandPlot.canvas.flush_events() + # Fix float representation + frequency_step = str("{:.2f}".format(frequency_step * 1e-6)) + self._ui_form.frequencystepEdit.setText(frequency_step) + @pyqtSlot() def on_editing_finished(self, value : str) -> None: """This method is called when the user finished editing a field.