Fixed issue with decimals.

This commit is contained in:
jupfi 2024-04-26 17:30:57 +02:00
parent 80e66c8aad
commit 9dfa5ec41b
2 changed files with 8 additions and 11 deletions

View file

@ -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",

View file

@ -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."""