Commit f0ae1824 authored by Jerome Carnis's avatar Jerome Carnis 🦊
Browse files

deviceMethodWidget.py: avoid temporal coupling in the method `control_changed`

parent 5c5cb115
Pipeline #28255 failed with stages
in 5 minutes and 29 seconds
......@@ -231,7 +231,6 @@ class MethodEnabledByAttributeWidget(DeviceMethodEnabledWidget):
parent=None,
) -> None:
self.external_device_attribute = external_device_attribute
self._editable_widgets: List[int] = []
super().__init__(
device=device,
method=method,
......@@ -244,15 +243,17 @@ class MethodEnabledByAttributeWidget(DeviceMethodEnabledWidget):
"""
Slot executed when a signal is emitted from `sig_control_changed`.
"""
editable_widgets = self._find_editable_widgets()
if self.input_value is not None:
for index in self._editable_widgets:
for index in editable_widgets:
if value:
self.input_value.children()[index].setEnabled(False) # type: ignore
else:
self.input_value.children()[index].setEnabled(True) # type: ignore
def _find_editable_widgets(self) -> None:
def _find_editable_widgets(self) -> List[int]:
"""Find the indices of the input fields that should be enabled/disabled"""
editable_widgets: List[int] = []
if self.input_value is not None:
for idx, child in enumerate(self.input_value.children()):
if type(child) == QWidget: # pylint: disable=unidiomatic-typecheck
......@@ -260,8 +261,9 @@ class MethodEnabledByAttributeWidget(DeviceMethodEnabledWidget):
# inherited from it
for grandchild in child.children():
if isinstance(grandchild, (QSpinBox, QDoubleSpinBox)):
self._editable_widgets.append(idx)
editable_widgets.append(idx)
break
return editable_widgets
def init_signals(self) -> None:
"""
......
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