From 9dfa5ec41b78e04fc80724ec3d4edb90ea81de85 Mon Sep 17 00:00:00 2001 From: jupfi Date: Fri, 26 Apr 2024 17:30:57 +0200 Subject: [PATCH] Fixed issue with decimals. --- src/nqrduck_pulseprogrammer/model.py | 7 +++---- src/nqrduck_pulseprogrammer/view.py | 12 +++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/nqrduck_pulseprogrammer/model.py b/src/nqrduck_pulseprogrammer/model.py index 8fe445e..7b2197e 100644 --- a/src/nqrduck_pulseprogrammer/model.py +++ b/src/nqrduck_pulseprogrammer/model.py @@ -1,5 +1,4 @@ import logging -from decimal import Decimal from collections import OrderedDict from PyQt6.QtCore import pyqtSignal from nqrduck.module.module_model import ModuleModel @@ -18,15 +17,15 @@ class PulseProgrammerModel(ModuleModel): self.pulse_parameter_options = OrderedDict() self.pulse_sequence = PulseSequence("Untitled pulse sequence") - def add_event(self, event_name: str, duration: Decimal = 20): + def add_event(self, event_name: str, duration: float = 20): """Add a new event to the current pulse sequence. Args: event_name (str): A human-readable name for the event - duration (Decimal): The duration of the event in µs. Defaults to 20. + duration (float): The duration of the event in µs. Defaults to 20. """ self.pulse_sequence.events.append( - PulseSequence.Event(event_name, "%.16gu" % duration) + PulseSequence.Event(event_name, "%.16gu" % float(duration)) ) logger.debug( "Creating event %s with object id %s", diff --git a/src/nqrduck_pulseprogrammer/view.py b/src/nqrduck_pulseprogrammer/view.py index 0750bdb..8ba069a 100644 --- a/src/nqrduck_pulseprogrammer/view.py +++ b/src/nqrduck_pulseprogrammer/view.py @@ -1,7 +1,5 @@ import logging import functools -from collections import OrderedDict -from decimal import Decimal from PyQt6.QtGui import QValidator from PyQt6.QtWidgets import ( QFormLayout, @@ -180,7 +178,7 @@ class PulseProgrammerView(ModuleView): logger.debug("Adding event to pulseprogrammer view: %s", event.name) # Create a label for the event event_label = QLabel( - "%s : %.16g µs" % (event.name, (event.duration * Decimal(1e6))) + "%s : %.16g µs" % (event.name, (event.duration * 1e6)) ) event_layout.addWidget(event_label) @@ -433,7 +431,7 @@ class EventOptionsWidget(QWidget): duration_label = QLabel("Duration:") duration_lineedit = QLineEdit() unit_label = QLabel("µs") - duration_lineedit.setText("%.16g" % (self.event.duration * Decimal(1e6))) + duration_lineedit.setText("%.16g" % (self.event.duration * 1e6)) duration_layout.addWidget(duration_label) duration_layout.addWidget(duration_lineedit) duration_layout.addWidget(unit_label) @@ -545,13 +543,13 @@ class AddEventDialog(QDialog): """ return self.name_input.text() - def get_duration(self) -> Decimal: + def get_duration(self) -> float: """Returns the duration entered by the user, or a fallback value." Returns: - Decimal: The duration value provided by the user, or 20 + float: The duration value provided by the user, or 20 """ - return Decimal(self.duration_lineedit.text() or 20) + return self.duration_lineedit.text() or 20 def check_input(self) -> None: """Checks if the name and duration entered by the user is valid. If it is, the dialog is accepted. If not, the user is informed of the error."""