Commit 4398b6ca authored by Jerome Carnis's avatar Jerome Carnis 🦊
Browse files

attributeDeviceDisplayWidget.py: fix bug with soft limits

add a limit check on the GUI value before updating the attribute
parent c20d2b1e
Pipeline #28104 passed with stages
in 9 minutes and 6 seconds
import time
from collections import deque
import pint
from PyQt5.QtCore import pyqtSignal, pyqtSlot
from pint import DimensionalityError
from typing import Dict, Tuple
......@@ -138,25 +139,41 @@ class AttributeDeviceDisplayWidget(DeviceWidget, AttributeDisplayWidget):
)
def on_value_set(self, value):
if isinstance(value, units.Quantity):
self._add_in_setpoint_history(value)
self.logger.info("Set {} to {}".format(self.initial_attribute, value))
value = value.to(self.attribute[UNIT])
value = value.m
elif self.attribute.numerical and self.get_unit() is not None:
try:
value = units.Quantity(value, self.get_unit())
if isinstance(value, units.Quantity) or (
self.attribute.numerical and self.get_unit() is not None
):
if not isinstance(value, units.Quantity):
try:
value = units.Quantity(value, self.get_unit())
value = value.to(self.attribute[UNIT])
except (
AttributeError,
pint.UndefinedUnitError,
pint.DefinitionSyntaxError,
):
value = units.Quantity(value)
else:
value = value.to(self.attribute[UNIT])
if self.attribute.within_limits(value):
value = value.m
self._add_in_setpoint_history(value)
self.logger.info("Set {} to {}".format(self.initial_attribute, value))
value = value.to(self.attribute[UNIT]).m
except AttributeError:
pass
self.logger.info(
"Set {} to {} {}".format(
self.initial_attribute, value, self.attribute[UNIT]
)
)
else:
self.logger.info(f"Can't set value {value}, out of limits")
value = self.attribute.value().m # set value back to what it was before
elif self.attribute[TYPE] == TYPE_LIST:
value = self.get_widget_value()
print("on_value_set TYPE_LIST", value)
try:
self.device.set_attribute(
self.initial_attribute + [VALUE],
self.initial_attribute + [VALUE], # e.g. ['Position', 'Value']
self.attribute_widget.attribute_type_cast(value),
callback=self.sigErrorCheck.emit,
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment