nqrduck-spectrometer/src/nqrduck_spectrometer/model.py

69 lines
2.6 KiB
Python
Raw Normal View History

2024-04-01 08:55:46 +00:00
"""The model for the nqrduck-spectrometer module. This module is responsible for managing the spectrometers."""
2023-07-03 18:25:05 +00:00
import logging
2023-07-08 09:06:09 +00:00
from PyQt6.QtCore import pyqtSignal
2023-07-01 14:19:52 +00:00
from nqrduck.module.module_model import ModuleModel
2023-07-04 11:07:43 +00:00
from .base_spectrometer import BaseSpectrometer
2023-07-01 14:19:52 +00:00
2023-07-03 18:25:05 +00:00
logger = logging.getLogger(__name__)
2023-07-01 14:19:52 +00:00
2024-04-01 08:55:46 +00:00
2023-07-01 14:19:52 +00:00
class SpectrometerModel(ModuleModel):
2024-04-01 08:55:46 +00:00
"""The model for the spectrometer module.
This class is responsible for managing the spectrometers.
Args:
module (Module) : The module that the spectrometer is connected to
Attributes:
active_spectrometer (BaseSpectrometer) : The currently active spectrometer
available_spectrometers (dict) : A dictionary of all available spectrometers
Signals:
spectrometer_added (BaseSpectrometer) : Signal emitted when a spectrometer is added
active_spectrometer_changed (BaseSpectrometer) : Signal emitted when the active spectrometer is changed
"""
2023-07-04 11:07:43 +00:00
spectrometer_added = pyqtSignal(BaseSpectrometer)
active_spectrometer_changed = pyqtSignal(BaseSpectrometer)
2023-07-01 14:19:52 +00:00
2023-07-03 18:25:05 +00:00
def __init__(self, module) -> None:
2024-04-01 08:55:46 +00:00
"""Initializes the spectrometer model."""
2023-07-03 18:25:05 +00:00
super().__init__(module)
self._active_spectrometer = None
2023-07-04 11:07:43 +00:00
self._available_spectrometers = dict()
2023-07-03 18:25:05 +00:00
@property
def active_spectrometer(self):
2024-04-01 08:55:46 +00:00
"""The currently active spectrometer. This is the one that is currently being used."""
2023-07-03 18:25:05 +00:00
return self._active_spectrometer
2024-04-01 08:55:46 +00:00
2023-07-03 18:25:05 +00:00
@active_spectrometer.setter
def active_spectrometer(self, value):
self._active_spectrometer = value
2023-07-04 11:07:43 +00:00
self.active_spectrometer_changed.emit(value)
spectrometer_module_name = value.model.toolbar_name
logger.debug("Active spectrometer changed to %s", spectrometer_module_name)
2024-04-01 08:55:46 +00:00
self.module.nqrduck_signal.emit(
"active_spectrometer_changed", spectrometer_module_name
)
2023-07-01 14:19:52 +00:00
@property
2023-07-03 18:25:05 +00:00
def available_spectrometers(self):
2024-04-01 08:55:46 +00:00
"""A dictionary of all available spectrometers. The key is the name of the spectrometer and the value is the module."""
2023-07-03 18:25:05 +00:00
return self._available_spectrometers
2024-04-01 08:55:46 +00:00
2023-07-04 11:07:43 +00:00
def add_spectrometers(self, spectrometer_module_name, module):
2024-04-01 08:55:46 +00:00
"""Adds a spectrometer to the available spectrometers.
Args:
spectrometer_module_name (str) : The name of the spectrometer
module (BaseSpectrometer) : The module of the spectrometer
"""
self._available_spectrometers[spectrometer_module_name] = module
2023-07-04 11:07:43 +00:00
logger.debug("Added module: %s", spectrometer_module_name)
self.spectrometer_added.emit(module)
2023-07-06 14:40:35 +00:00
self.active_spectrometer = module
2024-03-16 13:43:18 +00:00
self.add_submodule(spectrometer_module_name)