mirror of
https://github.com/nqrduck/nqrduck-spectrometer.git
synced 2024-12-31 20:58:07 +00:00
Implemented change of spectrometer.
This commit is contained in:
parent
35e1fd0e6c
commit
9c479a11fd
2 changed files with 11 additions and 1 deletions
|
@ -1,7 +1,9 @@
|
||||||
|
from PyQt5.QtCore import pyqtSignal
|
||||||
from nqrduck.module.module import Module
|
from nqrduck.module.module import Module
|
||||||
|
|
||||||
class BaseSpectrometer(Module):
|
class BaseSpectrometer(Module):
|
||||||
"""Base class for all spectrometers. All spectrometers should inherit from this class."""
|
"""Base class for all spectrometers. All spectrometers should inherit from this class."""
|
||||||
|
change_spectrometer = pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, model, view, controller):
|
def __init__(self, model, view, controller):
|
||||||
super().__init__(model, None, controller)
|
super().__init__(model, None, controller)
|
||||||
|
@ -17,3 +19,7 @@ class BaseSpectrometer(Module):
|
||||||
def start_measurement(self):
|
def start_measurement(self):
|
||||||
"""Starts the measurement."""
|
"""Starts the measurement."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def set_active(self):
|
||||||
|
"""Sets the spectrometer as the active spectrometer."""
|
||||||
|
self.change_spectrometer.emit(self._model.name)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
from PyQt5.QtWidgets import QWidget, QToolButton, QToolBar, QAction, QMenu
|
from PyQt5.QtWidgets import QWidget, QToolButton, QToolBar, QAction, QMenu
|
||||||
|
from PyQt5.QtCore import pyqtSlot, pyqtSignal
|
||||||
from nqrduck.module.module_view import ModuleView
|
from nqrduck.module.module_view import ModuleView
|
||||||
from .widget import Ui_Form
|
from .widget import Ui_Form
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ class SpectrometerView(ModuleView):
|
||||||
|
|
||||||
def on_spectrometer_added(self, module):
|
def on_spectrometer_added(self, module):
|
||||||
"""This method changes the active spectrometer to the one that was just added."""
|
"""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)
|
self.on_spectrometer_widget_changed(module._inner_view)
|
||||||
|
|
||||||
def create_menu_entry(self):
|
def create_menu_entry(self):
|
||||||
|
@ -36,11 +38,13 @@ class SpectrometerView(ModuleView):
|
||||||
for spectrometer_name, spectrometer_module in self._module.model._available_spectrometers.items():
|
for spectrometer_name, spectrometer_module in self._module.model._available_spectrometers.items():
|
||||||
logger.debug("Adding module to menu: %s", spectrometer_name)
|
logger.debug("Adding module to menu: %s", spectrometer_name)
|
||||||
select_action = QAction(spectrometer_module.model.toolbar_name, menu_item)
|
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)
|
actions.append(select_action)
|
||||||
|
|
||||||
self.add_menubar_item.emit("Hardware", actions)
|
self.add_menubar_item.emit("Hardware", actions)
|
||||||
|
|
||||||
|
@pyqtSlot(str)
|
||||||
def on_menu_button_clicked(self, spectrometer_name):
|
def on_menu_button_clicked(self, spectrometer_name):
|
||||||
logger.debug("Active module changed to: %s", spectrometer_name)
|
logger.debug("Active module changed to: %s", spectrometer_name)
|
||||||
self._module.model.active_spectrometer = self._module.model.available_spectrometers[spectrometer_name]
|
self._module.model.active_spectrometer = self._module.model.available_spectrometers[spectrometer_name]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue