From b4129f98e2716e5a197d14289a63c5319f6e169f Mon Sep 17 00:00:00 2001 From: jupfi Date: Tue, 11 Jul 2023 17:50:42 +0200 Subject: [PATCH] Changed implementation of pulse options. --- .../base_spectrometer_model.py | 7 +- src/nqrduck_spectrometer/pulse_sequence.py | 4 +- src/nqrduck_spectrometer/pulseparameters.py | 78 ++++++++++++------- 3 files changed, 57 insertions(+), 32 deletions(-) diff --git a/src/nqrduck_spectrometer/base_spectrometer_model.py b/src/nqrduck_spectrometer/base_spectrometer_model.py index b0d86f7..47720c5 100644 --- a/src/nqrduck_spectrometer/base_spectrometer_model.py +++ b/src/nqrduck_spectrometer/base_spectrometer_model.py @@ -34,11 +34,16 @@ class BaseSpectrometerModel(ModuleModel): class PulseParameter: def __init__(self, name): self.name = name + self.options = OrderedDict() def get_pixmap(self): raise NotImplementedError + def add_option(self, name, option): + self.options[name] = option + def get_options(self): - raise NotImplementedError + return self.options + diff --git a/src/nqrduck_spectrometer/pulse_sequence.py b/src/nqrduck_spectrometer/pulse_sequence.py index c089ea0..187fa9c 100644 --- a/src/nqrduck_spectrometer/pulse_sequence.py +++ b/src/nqrduck_spectrometer/pulse_sequence.py @@ -1,5 +1,7 @@ from collections import OrderedDict + class PulseSequence: + """A pulse sequence is a collection of events that are executed in a certain order.""" def __init__(self, name) -> None: self.name = name self.events = OrderedDict() @@ -33,7 +35,7 @@ class PulseSequence: for parameter in self.events[event].parameters.keys(): event_data["parameters"].append({ "name": parameter, - "value": self.events[event].parameters[parameter].state + "value": self.events[event].parameters[parameter].get_options() }) data["events"].append(event_data) return data \ No newline at end of file diff --git a/src/nqrduck_spectrometer/pulseparameters.py b/src/nqrduck_spectrometer/pulseparameters.py index 05e6ca9..c736def 100644 --- a/src/nqrduck_spectrometer/pulseparameters.py +++ b/src/nqrduck_spectrometer/pulseparameters.py @@ -2,21 +2,53 @@ from PyQt6.QtGui import QPixmap from pathlib import Path from .base_spectrometer_model import BaseSpectrometerModel +class Option(): + """Defines options for the pulse parameters which can then be set accordingly. + """ + def set_value(self): + raise NotImplementedError + +class BooleanOption(Option): + """Defines a boolean option for a pulse parameter. + """ + def __init__(self, state) -> None: + super().__init__() + self.state = state + + def set_value(self, state): + self.state = state + +class NumericOption(Option): + """Defines a numeric option for a pulse parameter. + """ + def __init__(self, value) -> None: + super().__init__() + self.value = value + + def set_value(self, value): + self.value = float(value) + +class WidgetSelectionOption(Option): + """Defines a widget selection option for a pulse parameter. + """ + def __init__(self, widgets) -> None: + super().__init__() + + class TXPulse(BaseSpectrometerModel.PulseParameter): def __init__(self, name) -> None: super().__init__(name) - self.tx_state = False - self.tx_phase = 0 + self.add_option("TX Amplitude", NumericOption(0)) + self.add_option("TX Phase", NumericOption(0)) - # Create a button - self.button = QPushButton(self) - self.button.setGeometry(0, 0, 200, 200) - - # Set a custom image for the button - image_path = "resources/wip_no_pulse.png" - pixmap = QPixmap(image_path) - self.button.setIcon(pixmap) - self.button.setIconSize(pixmap.size()) + def get_pixmap(self): + self_path = Path(__file__).parent + if self.options["TX Amplitude"].value > 0: + image_path = self_path / "resources/pulseparameter/wip_txpulse.png" + else: + image_path = self_path / "resources/pulseparameter/wip_no_txpulse.png" + pixmap = QPixmap(str(image_path)) + return pixmap class RectPulse(): def __init__(self, name) -> None: @@ -30,39 +62,25 @@ class TXPulse(BaseSpectrometerModel.PulseParameter): def __init__(self, name) -> None: super().__init__(name) - class RXReadout(BaseSpectrometerModel.PulseParameter): - def __init__(self, name) -> None: - super().__init__(name) - self.rx_freq = 0 - self.rx_phase = 0 - -class TXPhase(BaseSpectrometerModel.PulseParameter): +class RXReadout(BaseSpectrometerModel.PulseParameter): def __init__(self, name) -> None: super().__init__(name) - self.phase = 0 - -class RXPhase(BaseSpectrometerModel.PulseParameter): - def __init__(self, name) -> None: - super().__init__(name) - self.phase = 0 class Gate(BaseSpectrometerModel.PulseParameter): + def __init__(self, name) -> None: super().__init__(name) - self.state = False + self.add_option("Gate State", BooleanOption(False)) def get_pixmap(self): self_path = Path(__file__).parent - if self.state is False: + if self.options["Gate State"].state == False: image_path = self_path / "resources/pulseparameter/wip_no_txpulse.png" - elif self.state is True: + else: image_path = self_path / "resources/pulseparameter/wip_txpulse.png" pixmap = QPixmap(str(image_path)) return pixmap - def get_options(self): - return (bool, self.state) - def set_options(self, options): self.state = options