diff --git a/bec_widgets/utils/widget_io.py b/bec_widgets/utils/widget_io.py index 1ff3e1d8..d2a85fac 100644 --- a/bec_widgets/utils/widget_io.py +++ b/bec_widgets/utils/widget_io.py @@ -145,6 +145,26 @@ class WidgetIO: elif not ignore_errors: raise ValueError(f"No handler for widget type: {type(widget)}") + @staticmethod + def check_and_adjust_limits(spin_box: QDoubleSpinBox, number: float): + """ + Check if the new limits are within the current limits, if not adjust the limits. + + Args: + number(float): The new value to check against the limits. + """ + + min_value = spin_box.minimum() + max_value = spin_box.maximum() + + # Calculate the new limits + new_limit = number + 5 * number + + if number < min_value: + spin_box.setMinimum(new_limit) + elif number > max_value: + spin_box.setMaximum(new_limit) + @staticmethod def _find_handler(widget): """