nqrduck-spectrometer/src/nqrduck_spectrometer/model.py

41 lines
1.4 KiB
Python
Raw Normal View History

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
class SpectrometerModel(ModuleModel):
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:
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):
2023-07-06 14:40:35 +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
@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)
2023-07-03 18:25:05 +00:00
2023-07-01 14:19:52 +00:00
@property
2023-07-03 18:25:05 +00:00
def available_spectrometers(self):
2023-07-06 14:40:35 +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
2023-07-04 11:07:43 +00:00
def add_spectrometers(self, spectrometer_module_name, module):
self._available_spectrometers [spectrometer_module_name] = module
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
2023-07-03 18:25:05 +00:00
2023-07-01 18:49:21 +00:00