mirror of
https://github.com/nqrduck/nqrduck-spectrometer.git
synced 2024-11-09 20:40:02 +00:00
Implemented dispatcher
This commit is contained in:
parent
86a1a8ed5a
commit
b0eee8aeb3
4 changed files with 59 additions and 12 deletions
|
@ -13,13 +13,11 @@ class BaseSpectrometer(Module):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pulse_program(self):
|
def pulse_program(self):
|
||||||
"""Pulse program of the spectrometer."""
|
"""Pulse program of the spectrometer.
|
||||||
raise NotImplementedError
|
"""
|
||||||
|
|
||||||
def start_measurement(self):
|
|
||||||
"""Starts the measurement."""
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def set_active(self):
|
def set_active(self):
|
||||||
"""Sets the spectrometer as the active spectrometer."""
|
"""Sets the spectrometer as the active spectrometer.
|
||||||
|
"""
|
||||||
self.change_spectrometer.emit(self._model.name)
|
self.change_spectrometer.emit(self._model.name)
|
||||||
|
|
11
src/nqrduck_spectrometer/base_spectrometer_controller.py
Normal file
11
src/nqrduck_spectrometer/base_spectrometer_controller.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
from nqrduck.module.module_controller import ModuleController
|
||||||
|
|
||||||
|
class BaseSpectrometerController(ModuleController):
|
||||||
|
|
||||||
|
def __init__(self, module):
|
||||||
|
super().__init__(module)
|
||||||
|
|
||||||
|
def start_measurement(self):
|
||||||
|
"""Starts the measurement.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
|
@ -1,15 +1,23 @@
|
||||||
import logging
|
import logging
|
||||||
|
from PyQt5.QtCore import pyqtSlot
|
||||||
from nqrduck.module.module_controller import ModuleController
|
from nqrduck.module.module_controller import ModuleController
|
||||||
from nqrduck.core.main_controller import MainController
|
from nqrduck.core.main_controller import MainController
|
||||||
from nqrduck_spectrometer.base_spectrometer import BaseSpectrometer
|
from nqrduck_spectrometer.base_spectrometer import BaseSpectrometer
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SpectrometerController(ModuleController):
|
class SpectrometerController(ModuleController):
|
||||||
|
"""This class is the controller for the spectrometer module."""
|
||||||
|
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
|
"""This method initializes the controller.
|
||||||
|
:param module: The module that this controller belongs to.
|
||||||
|
"""
|
||||||
super().__init__(module)
|
super().__init__(module)
|
||||||
|
|
||||||
def _load_spectrometer_modules(self):
|
def _load_spectrometer_modules(self):
|
||||||
|
"""This method loads the spectrometer modules and adds them to the spectrometer model."""
|
||||||
# Get the modules with entry points in the nqrduck group
|
# Get the modules with entry points in the nqrduck group
|
||||||
modules = MainController._get_modules()
|
modules = MainController._get_modules()
|
||||||
logger.debug("Found modules: %s", modules)
|
logger.debug("Found modules: %s", modules)
|
||||||
|
@ -17,18 +25,43 @@ class SpectrometerController(ModuleController):
|
||||||
for module_name, module in modules.items():
|
for module_name, module in modules.items():
|
||||||
# Check if the module instance is a spectrometer by checking if it inherits from BaseSpectrometer
|
# Check if the module instance is a spectrometer by checking if it inherits from BaseSpectrometer
|
||||||
if not issubclass(type(module), BaseSpectrometer):
|
if not issubclass(type(module), BaseSpectrometer):
|
||||||
logger.debug("Module is not a spectrometer: %s ... skipping", module_name)
|
logger.debug(
|
||||||
|
"Module is not a spectrometer: %s ... skipping", module_name
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Import the module
|
# Import the module
|
||||||
logger.debug("Loading spectromter module: %s", module_name)
|
logger.debug("Loading spectromter module: %s", module_name)
|
||||||
module.model.widget_changed.connect(self._module.view.on_spectrometer_widget_changed)
|
module.model.widget_changed.connect(
|
||||||
|
self._module.view.on_spectrometer_widget_changed
|
||||||
|
)
|
||||||
logger.debug("Adding spectrometer to spectrometer model: %s", module_name)
|
logger.debug("Adding spectrometer to spectrometer model: %s", module_name)
|
||||||
self._module.model.add_spectrometers(module_name, module)
|
self._module.model.add_spectrometers(module_name, module)
|
||||||
|
|
||||||
self._module.view.create_menu_entry()
|
self._module.view.create_menu_entry()
|
||||||
|
|
||||||
|
def process_signals(self, key: str, value: str):
|
||||||
|
if key == "start_measurement":
|
||||||
|
self.on_measurement_start()
|
||||||
|
|
||||||
def on_loading(self):
|
def on_loading(self):
|
||||||
self._module.model.spectrometer_added.connect(self._module.view.on_spectrometer_added)
|
"""This method is called when the module is loaded.
|
||||||
self._module.model.active_spectrometer_changed.connect(self._module.view.on_active_spectrometer_changed)
|
It connects the signals from the spectrometer model to the view.
|
||||||
|
"""
|
||||||
|
self._module.model.spectrometer_added.connect(
|
||||||
|
self._module.view.on_spectrometer_added
|
||||||
|
)
|
||||||
|
self._module.model.active_spectrometer_changed.connect(
|
||||||
|
self._module.view.on_active_spectrometer_changed
|
||||||
|
)
|
||||||
self._load_spectrometer_modules()
|
self._load_spectrometer_modules()
|
||||||
|
|
||||||
|
def on_measurement_start(self):
|
||||||
|
"""This method is called when a measurement is started.
|
||||||
|
It calls the on_measurement_start method of the active spectrometer.
|
||||||
|
"""
|
||||||
|
logger.debug(
|
||||||
|
"Measurement started with spectrometer: %s",
|
||||||
|
self._module.model.active_spectrometer,
|
||||||
|
)
|
||||||
|
self._module.model.active_spectrometer.controller.start_measurement()
|
||||||
|
|
|
@ -16,6 +16,8 @@ class SpectrometerModel(ModuleModel):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def active_spectrometer(self):
|
def active_spectrometer(self):
|
||||||
|
"""The currently active spectrometer. This is the one that is currently being used.
|
||||||
|
"""
|
||||||
return self._active_spectrometer
|
return self._active_spectrometer
|
||||||
|
|
||||||
@active_spectrometer.setter
|
@active_spectrometer.setter
|
||||||
|
@ -25,11 +27,14 @@ class SpectrometerModel(ModuleModel):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available_spectrometers(self):
|
def available_spectrometers(self):
|
||||||
|
"""A dictionary of all available spectrometers. The key is the name of the spectrometer and the value is the module.
|
||||||
|
"""
|
||||||
return self._available_spectrometers
|
return self._available_spectrometers
|
||||||
|
|
||||||
def add_spectrometers(self, spectrometer_module_name, module):
|
def add_spectrometers(self, spectrometer_module_name, module):
|
||||||
self._available_spectrometers [spectrometer_module_name] = module
|
self._available_spectrometers [spectrometer_module_name] = module
|
||||||
logger.debug("Added module: %s", spectrometer_module_name)
|
logger.debug("Added module: %s", spectrometer_module_name)
|
||||||
self.spectrometer_added.emit(module)
|
self.spectrometer_added.emit(module)
|
||||||
|
self.active_spectrometer = module
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue