From fb17bf66cc95832c63fe9f2f0b887b11d056d0e7 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Tue, 2 Jul 2024 11:38:29 +0200 Subject: [PATCH] feat(widget_io): added method to check and adjust limits of spinboxes --- bec_widgets/utils/widget_io.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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): """