diff --git a/src/nqrduck_spectrometer/base_spectrometer.py b/src/nqrduck_spectrometer/base_spectrometer.py index 821c131..6d87e2e 100644 --- a/src/nqrduck_spectrometer/base_spectrometer.py +++ b/src/nqrduck_spectrometer/base_spectrometer.py @@ -1,7 +1,9 @@ +from PyQt5.QtCore import pyqtSignal from nqrduck.module.module import Module class BaseSpectrometer(Module): """Base class for all spectrometers. All spectrometers should inherit from this class.""" + change_spectrometer = pyqtSignal(str) def __init__(self, model, view, controller): super().__init__(model, None, controller) @@ -17,3 +19,7 @@ class BaseSpectrometer(Module): def start_measurement(self): """Starts the measurement.""" raise NotImplementedError + + def set_active(self): + """Sets the spectrometer as the active spectrometer.""" + self.change_spectrometer.emit(self._model.name) diff --git a/src/nqrduck_spectrometer/view.py b/src/nqrduck_spectrometer/view.py index aef5e5d..4288544 100644 --- a/src/nqrduck_spectrometer/view.py +++ b/src/nqrduck_spectrometer/view.py @@ -1,5 +1,6 @@ import logging from PyQt5.QtWidgets import QWidget, QToolButton, QToolBar, QAction, QMenu +from PyQt5.QtCore import pyqtSlot, pyqtSignal from nqrduck.module.module_view import ModuleView from .widget import Ui_Form @@ -25,6 +26,7 @@ class SpectrometerView(ModuleView): def on_spectrometer_added(self, module): """This method changes the active spectrometer to the one that was just added.""" + module.change_spectrometer.connect(self.on_menu_button_clicked) self.on_spectrometer_widget_changed(module._inner_view) def create_menu_entry(self): @@ -36,11 +38,13 @@ class SpectrometerView(ModuleView): for spectrometer_name, spectrometer_module in self._module.model._available_spectrometers.items(): logger.debug("Adding module to menu: %s", spectrometer_name) select_action = QAction(spectrometer_module.model.toolbar_name, menu_item) - select_action.triggered.connect(lambda: self.on_menu_button_clicked(spectrometer_name)) + select_action.triggered.connect(spectrometer_module.set_active) actions.append(select_action) self.add_menubar_item.emit("Hardware", actions) + @pyqtSlot(str) def on_menu_button_clicked(self, spectrometer_name): logger.debug("Active module changed to: %s", spectrometer_name) self._module.model.active_spectrometer = self._module.model.available_spectrometers[spectrometer_name] +