Skip to content

Commit

Permalink
Fixed issue with decimals.
Browse files Browse the repository at this point in the history
  • Loading branch information
jupfi committed Apr 26, 2024
1 parent 80e66c8 commit 9dfa5ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/nqrduck_pulseprogrammer/model.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,15 +17,15 @@ def __init__(self, module):
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",
Expand Down
12 changes: 5 additions & 7 deletions src/nqrduck_pulseprogrammer/view.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -180,7 +178,7 @@ def on_events_changed(self) -> None:
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)

Expand Down Expand Up @@ -433,7 +431,7 @@ def edit_event(self) -> None:
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)
Expand Down Expand Up @@ -545,13 +543,13 @@ def get_name(self) -> str:
"""
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."""
Expand Down

0 comments on commit 9dfa5ec

Please sign in to comment.