From fcd44f5bff6c08eef917c8f81f1673e5c49f781f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Wed, 13 Mar 2024 16:32:07 +0100 Subject: [PATCH] Tweak limits. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- resource/rotational.ui | 42 ++---------------------------- src/rqt_gauges/base_widget.py | 30 ++++++++++----------- src/rqt_gauges/rotational_gauge.py | 20 +++++--------- 3 files changed, 23 insertions(+), 69 deletions(-) diff --git a/resource/rotational.ui b/resource/rotational.ui index 5d1e41c..693c731 100644 --- a/resource/rotational.ui +++ b/resource/rotational.ui @@ -28,51 +28,13 @@ Rotational - - - - 30 - 470 - 81 - 31 - - - - - 12 - - - - Min Value: - - - - - - 110 - 470 - 51 - 31 - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">-45</p></body></html> - - - - - true - 260 + 230 470 51 31 @@ -101,7 +63,7 @@ p, li { white-space: pre-wrap; } - 170 + 140 476 81 21 diff --git a/src/rqt_gauges/base_widget.py b/src/rqt_gauges/base_widget.py index 9dd89a1..9e8c01b 100644 --- a/src/rqt_gauges/base_widget.py +++ b/src/rqt_gauges/base_widget.py @@ -24,23 +24,21 @@ def __init__(self, node, name, ui_path): self._topic_completer.update_topics(self.node) self.topic_to_subscribe.setCompleter(self._topic_completer) - # Objects Properties - self.max_value.setAlignment(Qt.AlignCenter) - self.min_value.setAlignment(Qt.AlignCenter) - try: getattr(self.gauge, 'maxValue') + self.max_value.setAlignment(Qt.AlignCenter) self.max_value.setPlaceholderText(str(self.gauge.maxValue)) self.max_value.textChanged.connect(self.updateMaxValue) except AttributeError: - print("obj does not have attribute 'maxValue'") + pass try: getattr(self.gauge, 'minValue') + self.min_value.setAlignment(Qt.AlignCenter) self.min_value.setPlaceholderText(str(self.gauge.minValue)) self.min_value.textChanged.connect(self.updateMinValue) except AttributeError: - print("obj does not have attribute 'minValue'") + pass try: getattr(self.gauge, 'units') @@ -67,19 +65,19 @@ def dropEvent(self, event): @pyqtSlot() def updateMinValue(self): - new_min_value = self.min_value.toPlainText() - if new_min_value.isnumeric(): - self.gauge.setMinValue(int(new_min_value)) - else: - self.gauge.setMinValue(0) + try: + new_min_value = int(self.min_value.toPlainText()) + self.gauge.setMinValue(new_min_value) + except ValueError: + pass @pyqtSlot() def updateMaxValue(self): - new_max_value = self.max_value.toPlainText() - if new_max_value.isnumeric(): - self.gauge.setMaxValue(int(new_max_value)) - else: - self.gauge.setMaxValue(180) + try: + new_max_value = int(self.max_value.toPlainText()) + self.gauge.setMaxValue(new_max_value) + except ValueError: + pass @pyqtSlot(float) def updateValue(self, value): diff --git a/src/rqt_gauges/rotational_gauge.py b/src/rqt_gauges/rotational_gauge.py index cf77401..5c554a4 100644 --- a/src/rqt_gauges/rotational_gauge.py +++ b/src/rqt_gauges/rotational_gauge.py @@ -99,29 +99,23 @@ def updateValue(self, value: float): self.value = value self.repaint() - def setMinValue(self, min_value): - # Modifies the minimum value of the gauge - # Args: - # min: Value to update the minimum value of the gauge. - if self.value < min_value: - self.value = min_value - if min_value >= self.maxValue: - self.minValue = self.maxValue - 1 - else: - self.minValue = min_value - - self.update() - def setMaxValue(self, max_value): # Modifies the maximum value of the gauge # Args: # max: Value to update the maximum value of the gauge. + + # Sanity check: We only allow positive max values. + if max_value <= 0: + return + if self.value > max_value: self.value = max_value if max_value <= self.minValue: self.maxValue = self.minValue + 1 + self.minValue = -self.maxValue + 1 else: self.maxValue = max_value + self.minValue = -max_value self.update()