From 05dc0b7c5653af8e9b905a7ff711521b6d6f1742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Tue, 27 Feb 2024 16:42:16 +0100 Subject: [PATCH 01/13] Creating a base_widget class. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- resource/dial.ui | 2 +- resource/rotational.ui | 78 +++++++++++---- .../{dial_widget.py => base_widget.py} | 60 ++++++------ src/rqt_gauges/dial.py | 9 +- src/rqt_gauges/rotational.py | 10 +- src/rqt_gauges/rotational_gauge.py | 15 ++- src/rqt_gauges/rotational_widget.py | 95 ------------------- 7 files changed, 116 insertions(+), 153 deletions(-) rename src/rqt_gauges/{dial_widget.py => base_widget.py} (64%) delete mode 100644 src/rqt_gauges/rotational_widget.py diff --git a/resource/dial.ui b/resource/dial.ui index a585e9e..7352e72 100644 --- a/resource/dial.ui +++ b/resource/dial.ui @@ -150,7 +150,7 @@ p, li { white-space: pre-wrap; } Topic: - + 0 diff --git a/resource/rotational.ui b/resource/rotational.ui index 3acaae1..a6e4194 100644 --- a/resource/rotational.ui +++ b/resource/rotational.ui @@ -28,13 +28,51 @@ Rotational + + + + 40 + 460 + 81 + 31 + + + + + 12 + + + + Min Value: + + + + + + 120 + 460 + 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;">0</p></body></html> + + + + + true - 230 + 272 460 51 31 @@ -60,6 +98,24 @@ p, li { white-space: pre-wrap; } + + + + 190 + 460 + 81 + 31 + + + + + 12 + + + + Max Value: + + @@ -91,24 +147,6 @@ p, li { white-space: pre-wrap; } Topic: - - - - 140 - 466 - 81 - 21 - - - - - 12 - - - - Angle: - - @@ -119,7 +157,7 @@ p, li { white-space: pre-wrap; } - + 10 diff --git a/src/rqt_gauges/dial_widget.py b/src/rqt_gauges/base_widget.py similarity index 64% rename from src/rqt_gauges/dial_widget.py rename to src/rqt_gauges/base_widget.py index 40b5144..dce257f 100644 --- a/src/rqt_gauges/dial_widget.py +++ b/src/rqt_gauges/base_widget.py @@ -1,6 +1,3 @@ -import os - -from ament_index_python.resources import get_resource from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtWidgets import QWidget from python_qt_binding import loadUi @@ -10,18 +7,16 @@ from .utils import generate_field_evals, get_topic_type -class DialWidget(QWidget): +class BaseWidget(QWidget): - def __init__(self, node): + def __init__(self, node, name, ui_path): super().__init__() - self.setObjectName('Dial_widget') + self.setObjectName(name) self.node = node self.sub = None - _, package_path = get_resource('packages', 'rqt_gauges') - ui_file = os.path.join(package_path, 'share', 'rqt_gauges', 'resource', 'dial.ui') - loadUi(ui_file, self) + loadUi(ui_path, self) self.topic_to_subscribe.setNode(self.node) @@ -33,15 +28,23 @@ def __init__(self, node): self.max_value.setAlignment(Qt.AlignCenter) self.min_value.setAlignment(Qt.AlignCenter) - self.max_value.setPlaceholderText(str(self.dial_gauge.maxValue)) - self.min_value.setPlaceholderText(str(self.dial_gauge.minValue)) - + try: + getattr(self.gauge, "maxValue") + self.max_value.setPlaceholderText(str(self.gauge.maxValue)) + self.max_value.textChanged.connect(self.updateMaxValue) + except AttributeError: + print("obj does not have attribute 'maxValue'") + + try: + getattr(self.gauge, "minValue") + self.min_value.setPlaceholderText(str(self.gauge.minValue)) + self.min_value.textChanged.connect(self.updateMinValue) + except AttributeError: + print("obj does not have attribute 'minValue'") + # Signals Connection - self.min_value.textChanged.connect(self.updateMinValue) - self.max_value.textChanged.connect(self.updateMaxValue) - self.units.currentTextChanged.connect(self.updateUnits) self.subscribe_button.pressed.connect(self.updateSubscription) - self.dial_gauge.updateValueSignal.connect(self.updateValue) + self.gauge.updateValueSignal.connect(self.updateValue) def dragEnterEvent(self, event): event.accept() @@ -60,26 +63,21 @@ def dropEvent(self, event): def updateMinValue(self): new_min_value = self.min_value.toPlainText() if new_min_value.isnumeric(): - self.dial_gauge.setMinValue(int(new_min_value)) + self.gauge.setMinValue(int(new_min_value)) else: - self.dial_gauge.setMinValue(0) + self.gauge.setMinValue(0) @pyqtSlot() def updateMaxValue(self): new_max_value = self.max_value.toPlainText() if new_max_value.isnumeric(): - self.dial_gauge.setMaxValue(int(new_max_value)) + self.gauge.setMaxValue(int(new_max_value)) else: - self.dial_gauge.setMaxValue(180) + self.gauge.setMaxValue(180) @pyqtSlot(float) def updateValue(self, value): - self.dial_gauge.updateValue(value) - - @pyqtSlot(str) - def updateUnits(self, new_units): - self.dial_gauge.units = new_units - self.dial_gauge.update() + self.gauge.updateValue(value) @pyqtSlot() def updateSubscription(self): @@ -96,17 +94,17 @@ def updateSubscription(self): self.sub = self.node.create_subscription( data_class, topic_name, - self.dial_callback, + self.callback, 10) - def dial_callback(self, msg): + def callback(self, msg): value = msg for f in self.field_evals: value = f(value) if value is not None: if type(value) == int or type(value) == float or type(value) == str: - self.dial_gauge.updateValueSignal.emit(float(value)) + self.gauge.updateValueSignal.emit(float(value)) else: - self.dial_gauge.updateValueSignal.emit(self.dial_gauge.minValue) + self.gauge.updateValueSignal.emit(self.gauge.minValue) else: - self.dial_gauge.updateValueSignal.emit(self.dial_gauge.minValue) + self.gauge.updateValueSignal.emit(self.gauge.minValue) diff --git a/src/rqt_gauges/dial.py b/src/rqt_gauges/dial.py index 67056e4..e9d8188 100644 --- a/src/rqt_gauges/dial.py +++ b/src/rqt_gauges/dial.py @@ -1,6 +1,9 @@ +import os + +from ament_index_python.resources import get_resource from qt_gui.plugin import Plugin -from .dial_widget import DialWidget +from .base_widget import BaseWidget class Dial(Plugin): @@ -12,5 +15,7 @@ def __init__(self, context): self._context = context self._node = context.node - self._widget = DialWidget(self._node) + _, package_path = get_resource('packages', 'rqt_gauges') + ui_file = os.path.join(package_path, 'share', 'rqt_gauges', 'resource', 'dial.ui') + self._widget = BaseWidget(self._node, 'Dial_widget', ui_file) context.add_widget(self._widget) diff --git a/src/rqt_gauges/rotational.py b/src/rqt_gauges/rotational.py index a66fbbc..156b043 100644 --- a/src/rqt_gauges/rotational.py +++ b/src/rqt_gauges/rotational.py @@ -1,6 +1,9 @@ +import os + +from ament_index_python.resources import get_resource from qt_gui.plugin import Plugin -from .rotational_widget import RotationalWidget +from .base_widget import BaseWidget class Rotational(Plugin): @@ -12,5 +15,8 @@ def __init__(self, context): self._context = context self._node = context.node - self._widget = RotationalWidget(self._node) + _, package_path = get_resource('packages', 'rqt_gauges') + ui_file = os.path.join(package_path, 'share', 'rqt_gauges', 'resource', 'rotational.ui') + self._widget = BaseWidget(self._node, 'Rotational_widget', ui_file) + context.add_widget(self._widget) diff --git a/src/rqt_gauges/rotational_gauge.py b/src/rqt_gauges/rotational_gauge.py index 8ee70e2..cf77401 100644 --- a/src/rqt_gauges/rotational_gauge.py +++ b/src/rqt_gauges/rotational_gauge.py @@ -99,6 +99,19 @@ 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: @@ -107,10 +120,8 @@ def setMaxValue(self, 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() diff --git a/src/rqt_gauges/rotational_widget.py b/src/rqt_gauges/rotational_widget.py deleted file mode 100644 index a2bf13b..0000000 --- a/src/rqt_gauges/rotational_widget.py +++ /dev/null @@ -1,95 +0,0 @@ -import os - -from ament_index_python.resources import get_resource -from PyQt5.QtCore import pyqtSlot, Qt -from PyQt5.QtWidgets import QWidget -from python_qt_binding import loadUi -from rosidl_runtime_py.utilities import get_message -from rqt_py_common.topic_completer import TopicCompleter - -from .utils import generate_field_evals, get_topic_type - - -class RotationalWidget(QWidget): - - def __init__(self, node): - super().__init__() - self.setObjectName('Rotational_widget') - - self.node = node - self.sub = None - - _, package_path = get_resource('packages', 'rqt_gauges') - ui_file = os.path.join(package_path, 'share', 'rqt_gauges', - 'resource', 'rotational.ui') - loadUi(ui_file, self) - - self.topic_to_subscribe.setNode(self.node) - - self._topic_completer = TopicCompleter(self.topic_to_subscribe) - self._topic_completer.update_topics(self.node) - self.topic_to_subscribe.setCompleter(self._topic_completer) - - # Objects Properties - self.max_value.setAlignment(Qt.AlignCenter) - - self.max_value.setPlaceholderText(str(self.rotational_gauge.maxValue)) - - self.max_value.textChanged.connect(self.updateMaxValue) - self.subscribe_button.pressed.connect(self.updateSubscription) - self.rotational_gauge.updateValueSignal.connect(self.updateValue) - - def dragEnterEvent(self, event): - event.accept() - - def dropEvent(self, event): - if event.mimeData().hasText(): - topic_name = str(event.mimeData().text()) - else: - droped_item = event.source().selectedItems()[0] - topic_name = str(droped_item.data(0, Qt.UserRole)) - self.topic_to_subscribe.setText(topic_name) - self.updateSubscription() - event.accept() - - @pyqtSlot() - def updateMaxValue(self): - new_max_value = self.max_value.toPlainText() - if new_max_value.isnumeric(): - self.rotational_gauge.setMaxValue(int(new_max_value)) - else: - self.rotational_gauge.setMaxValue(45) - - @pyqtSlot() - def updateSubscription(self): - if self.node.destroy_subscription(self.sub): - print('Previous subscription deleted') - else: - print('There was no previous subscription') - topic_path = self.topic_to_subscribe.text() - topic_type, topic_name, fields = get_topic_type(self.node, topic_path) - self.field_evals = generate_field_evals(fields) - if topic_type is not None: - print('Subscribing to:', topic_name, 'Type:', topic_type, 'Field:', fields) - data_class = get_message(topic_type) - self.sub = self.node.create_subscription( - data_class, - topic_name, - self.rotational_callback, - 10) - - @pyqtSlot(float) - def updateValue(self, value): - self.rotational_gauge.updateValue(value) - - def rotational_callback(self, msg): - value = msg - for f in self.field_evals: - value = f(value) - if value is not None: - if type(value) == int or type(value) == float or type(value) == str: - self.rotational_gauge.updateValueSignal.emit(float(value)) - else: - self.rotational_gauge.updateValueSignal.emit(0.0) - else: - self.rotational_gauge.updateValueSignal.emit(0.0) From dbd076b420482bb8dc5fd56e8b22803c6f0954a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Tue, 27 Feb 2024 16:45:37 +0100 Subject: [PATCH 02/13] Tweak. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- src/rqt_gauges/base_widget.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rqt_gauges/base_widget.py b/src/rqt_gauges/base_widget.py index dce257f..be20161 100644 --- a/src/rqt_gauges/base_widget.py +++ b/src/rqt_gauges/base_widget.py @@ -41,7 +41,7 @@ def __init__(self, node, name, ui_path): self.min_value.textChanged.connect(self.updateMinValue) except AttributeError: print("obj does not have attribute 'minValue'") - + # Signals Connection self.subscribe_button.pressed.connect(self.updateSubscription) self.gauge.updateValueSignal.connect(self.updateValue) From 347172f1b96a8fea3038d4235964664a3d49ea82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Tue, 27 Feb 2024 17:06:49 +0100 Subject: [PATCH 03/13] Style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- src/rqt_gauges/base_widget.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rqt_gauges/base_widget.py b/src/rqt_gauges/base_widget.py index be20161..86d859e 100644 --- a/src/rqt_gauges/base_widget.py +++ b/src/rqt_gauges/base_widget.py @@ -29,14 +29,14 @@ def __init__(self, node, name, ui_path): self.min_value.setAlignment(Qt.AlignCenter) try: - getattr(self.gauge, "maxValue") + getattr(self.gauge, 'maxValue') self.max_value.setPlaceholderText(str(self.gauge.maxValue)) self.max_value.textChanged.connect(self.updateMaxValue) except AttributeError: print("obj does not have attribute 'maxValue'") try: - getattr(self.gauge, "minValue") + getattr(self.gauge, 'minValue') self.min_value.setPlaceholderText(str(self.gauge.minValue)) self.min_value.textChanged.connect(self.updateMinValue) except AttributeError: From 7d78d2ee8516cf2072b981606d51b528eb995b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Mon, 4 Mar 2024 18:21:56 +0100 Subject: [PATCH 04/13] More updates. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- plugin.xml | 4 +- resource/bar_gauge.ui | 492 ----------------------------- setup.py | 2 +- src/rqt_gauges/bar_gauge.py | 64 +++- src/rqt_gauges/bar_gauge_widget.py | 93 ------ 5 files changed, 57 insertions(+), 598 deletions(-) delete mode 100644 resource/bar_gauge.ui delete mode 100644 src/rqt_gauges/bar_gauge_widget.py diff --git a/plugin.xml b/plugin.xml index ea88801..8c1da2b 100644 --- a/plugin.xml +++ b/plugin.xml @@ -29,7 +29,7 @@ Gauges visualization tool. - + A bar visualization tool. @@ -39,7 +39,7 @@ folder Plugins related to visualization. - + utilities-system-monitor Gauges visualization tool. diff --git a/resource/bar_gauge.ui b/resource/bar_gauge.ui deleted file mode 100644 index b4bcd9b..0000000 --- a/resource/bar_gauge.ui +++ /dev/null @@ -1,492 +0,0 @@ - - - BarGauge - - - - 0 - 0 - 250 - 550 - - - - - 250 - 550 - - - - - 250 - 550 - - - - true - - - BarGauge - - - - - 10 - 20 - 71 - 31 - - - - - 12 - - - - Topic: - - - - - - 60 - 20 - 170 - 31 - - - - - - - 90 - 75 - 81 - 31 - - - - Subscribe - - - - - - 110 - 126 - 51 - 301 - - - - - - - - - 0 - 255 - 0 - - - - - - - 0 - 255 - 0 - - - - - - - - - 0 - 255 - 0 - - - - - - - 0 - 255 - 0 - - - - - - - - - 145 - 145 - 145 - - - - - - - 0 - 255 - 0 - - - - - - - - 100 - - - 80 - - - false - - - Qt::Vertical - - - %f% - - - - - - 0 - 436 - 221 - 61 - - - - - 25 - - - - 0.0 - - - Qt::AlignCenter - - - - - - - -10 - 0 - 471 - 20 - - - - Qt::Horizontal - - - - - - 86 - 109 - 20 - 31 - - - - 1 - - - - - - 80 - 380 - 21 - 31 - - - - 0.1 - - - - - - 80 - 260 - 31 - 21 - - - - 0.5 - - - - - - 85 - 410 - 21 - 31 - - - - 0 - - - - - - 80 - 320 - 21 - 21 - - - - 0.3 - - - - - - 80 - 350 - 21 - 21 - - - - 0.2 - - - - - - 80 - 170 - 21 - 21 - - - - 0.8 - - - - - - 80 - 290 - 21 - 21 - - - - 0.4 - - - - - - 80 - 230 - 21 - 21 - - - - 0.6 - - - - - - 80 - 140 - 21 - 21 - - - - 0.9 - - - - - - 80 - 200 - 21 - 21 - - - - 0.7 - - - - - - 100 - 420 - 16 - 16 - - - - Qt::Horizontal - - - - - - 100 - 116 - 16 - 20 - - - - Qt::Horizontal - - - - - - 100 - 390 - 16 - 16 - - - - Qt::Horizontal - - - - - - 100 - 140 - 16 - 31 - - - - Qt::Horizontal - - - - - - 100 - 170 - 16 - 31 - - - - Qt::Horizontal - - - - - - 100 - 200 - 16 - 31 - - - - Qt::Horizontal - - - - - - 100 - 230 - 16 - 31 - - - - Qt::Horizontal - - - - - - 100 - 260 - 16 - 31 - - - - Qt::Horizontal - - - - - - 100 - 290 - 16 - 31 - - - - Qt::Horizontal - - - - - - 100 - 320 - 16 - 31 - - - - Qt::Horizontal - - - - - - 100 - 350 - 16 - 31 - - - - Qt::Horizontal - - - - - - TopicQLineEdit - QLineEdit -
rqt_gauges.topic_q_line_edit.h
-
-
- - -
diff --git a/setup.py b/setup.py index 745aa87..7a868ee 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ ('share/' + package_name + '/resource', ['resource/rotational.ui']), ('share/' + package_name + '/resource', - ['resource/bar_gauge.ui']), + ['resource/bar.ui']), ('share/' + package_name, ['package.xml']), ('share/' + package_name, ['plugin.xml']), ], diff --git a/src/rqt_gauges/bar_gauge.py b/src/rqt_gauges/bar_gauge.py index 1d395bc..0fe71a4 100644 --- a/src/rqt_gauges/bar_gauge.py +++ b/src/rqt_gauges/bar_gauge.py @@ -1,16 +1,60 @@ -from qt_gui.plugin import Plugin +import math -from .bar_gauge_widget import BarGaugeWidget +from PyQt5.QtCore import pyqtSignal +from PyQt5.QtWidgets import QProgressBar, QWidget -class BarGauge(Plugin): +class BarGauge(QWidget): - def __init__(self, context): - super().__init__(context) - self.setObjectName('BarGauge') + updateValueSignal = pyqtSignal(float) - self._context = context - self._node = context.node + def __init__(self, node): + # Constructor method of the class, initializes all the variables needed to create + # the gauge. - self._widget = BarGaugeWidget(self._node) - context.add_widget(self._widget) + super().__init__() + + self.minValue = 0 + self.maxValue = 1 + self.raw_value = self.minValue + self.value = self.minValue + + def updateValue(self, value: float): + # Updates the value that the gauge is indicating. + # Args: + # value: Value to update the gauge with. + self.raw_value = value + value = max(value, self.minValue) + value = min(value, self.maxValue) + 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. + if self.value > max_value: + self.value = max_value + if max_value <= self.minValue: + self.maxValue = self.minValue + 1 + else: + self.maxValue = max_value + + self.update() + + def paintEvent(self, event): + self.bar_gauge.setValue(self.value) + self.value_label.setText(str(raw_value / 100.0)) diff --git a/src/rqt_gauges/bar_gauge_widget.py b/src/rqt_gauges/bar_gauge_widget.py deleted file mode 100644 index ce06504..0000000 --- a/src/rqt_gauges/bar_gauge_widget.py +++ /dev/null @@ -1,93 +0,0 @@ -import os - -from ament_index_python.resources import get_resource -from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt -from PyQt5.QtWidgets import QWidget -from python_qt_binding import loadUi -from rosidl_runtime_py.utilities import get_message -from rqt_py_common.topic_completer import TopicCompleter - -from .utils import generate_field_evals, get_topic_type - - -class BarGaugeWidget(QWidget): - - updateValueSignal = pyqtSignal(int, int) - - def __init__(self, node): - super().__init__() - self.setObjectName('BarGauge_widget') - - self.node = node - self.sub = None - - _, package_path = get_resource('packages', 'rqt_gauges') - ui_file = os.path.join(package_path, 'share', - 'rqt_gauges', 'resource', 'bar_gauge.ui') - loadUi(ui_file, self) - - # Topic Completer - self.topic_to_subscribe.setNode(self.node) - self._topic_completer = TopicCompleter(self.topic_to_subscribe) - self._topic_completer.update_topics(self.node) - self.topic_to_subscribe.setCompleter(self._topic_completer) - - # Signals Connection - self.subscribe.pressed.connect(self.updateSubscription) - self.updateValueSignal.connect(self.updateValue) - - def dragEnterEvent(self, event): - event.accept() - - def dropEvent(self, event): - if event.mimeData().hasText(): - topic_name = str(event.mimeData().text()) - else: - droped_item = event.source().selectedItems()[0] - topic_name = str(droped_item.data(0, Qt.UserRole)) - - self.topic_to_subscribe.setText(topic_name) - self.updateSubscription() - - event.accept() - - @pyqtSlot() - def updateSubscription(self): - if self.node.destroy_subscription(self.sub): - print('Previous subscription deleted') - else: - print('There was no previous subscription') - topic_path = self.topic_to_subscribe.text() - topic_type, topic_name, fields = get_topic_type(self.node, topic_path) - self.field_evals = generate_field_evals(fields) - if topic_type is not None: - print('Subscribing to:', topic_name, 'Type:', topic_type, 'Field:', fields) - data_class = get_message(topic_type) - self.sub = self.node.create_subscription( - data_class, - topic_name, - self.callback, - 10) - - @pyqtSlot(int, int) - def updateValue(self, value, raw_value): - self.bar_gauge.setValue(value) - self.value_label.setText(str(raw_value / 100.0)) - - def callback(self, msg): - value = msg - for f in self.field_evals: - value = f(value) - if value is not None and (type(value) == int or type(value) == float - or type(value) == str): - raw_value = int(value*100) - if value < 0: - value = 0 - print('The value is not between 0 and 1') - elif value > 1: - value = 1 - print('The value is not between 0 and 1') - - self.updateValueSignal.emit(int(value*100), raw_value) - else: - print('The value is not valid') From 47d47ba285523aa29287f065aa28a5058ba86553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Tue, 5 Mar 2024 15:21:24 +0100 Subject: [PATCH 05/13] Adding files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- resource/bar.ui | 596 ++++++++++++++++++++++++++++++++++++++++++ src/rqt_gauges/bar.py | 22 ++ 2 files changed, 618 insertions(+) create mode 100644 resource/bar.ui create mode 100644 src/rqt_gauges/bar.py diff --git a/resource/bar.ui b/resource/bar.ui new file mode 100644 index 0000000..217b3f8 --- /dev/null +++ b/resource/bar.ui @@ -0,0 +1,596 @@ + + + Bar + + + + 0 + 0 + 250 + 550 + + + + + 250 + 550 + + + + + 250 + 550 + + + + true + + + Bar + + + + + 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;">0</p></body></html> + + + + + + + + + 260 + 470 + 51 + 31 + + + + + 50 + false + false + false + false + + + + <!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;">180</p></body></html> + + + + + + + + + 170 + 476 + 81 + 21 + + + + + 12 + + + + Max Value: + + + + + + 10 + 20 + 71 + 31 + + + + + 12 + + + + Topic: + + + + + + 60 + 20 + 170 + 31 + + + + + + + 90 + 75 + 81 + 31 + + + + Subscribe + + + + + + 110 + 126 + 51 + 301 + + + + true + + + + + + 110 + 126 + 51 + 301 + + + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + + + 145 + 145 + 145 + + + + + + + 0 + 255 + 0 + + + + + + + + 100 + + + 80 + + + false + + + Qt::Vertical + + + %f% + + + + + + 0 + 436 + 221 + 61 + + + + + 25 + + + + 0.0 + + + Qt::AlignCenter + + + + + + + -10 + 0 + 471 + 20 + + + + Qt::Horizontal + + + + + + 86 + 109 + 20 + 31 + + + + 1 + + + + + + 80 + 380 + 21 + 31 + + + + 0.1 + + + + + + 80 + 260 + 31 + 21 + + + + 0.5 + + + + + + 85 + 410 + 21 + 31 + + + + 0 + + + + + + 80 + 320 + 21 + 21 + + + + 0.3 + + + + + + 80 + 350 + 21 + 21 + + + + 0.2 + + + + + + 80 + 170 + 21 + 21 + + + + 0.8 + + + + + + 80 + 290 + 21 + 21 + + + + 0.4 + + + + + + 80 + 230 + 21 + 21 + + + + 0.6 + + + + + + 80 + 140 + 21 + 21 + + + + 0.9 + + + + + + 80 + 200 + 21 + 21 + + + + 0.7 + + + + + + 100 + 420 + 16 + 16 + + + + Qt::Horizontal + + + + + + 100 + 116 + 16 + 20 + + + + Qt::Horizontal + + + + + + 100 + 390 + 16 + 16 + + + + Qt::Horizontal + + + + + + 100 + 140 + 16 + 31 + + + + Qt::Horizontal + + + + + + 100 + 170 + 16 + 31 + + + + Qt::Horizontal + + + + + + 100 + 200 + 16 + 31 + + + + Qt::Horizontal + + + + + + 100 + 230 + 16 + 31 + + + + Qt::Horizontal + + + + + + 100 + 260 + 16 + 31 + + + + Qt::Horizontal + + + + + + 100 + 290 + 16 + 31 + + + + Qt::Horizontal + + + + + + 100 + 320 + 16 + 31 + + + + Qt::Horizontal + + + + + + 100 + 350 + 16 + 31 + + + + Qt::Horizontal + + + + + + BarGauge + QWidget +
rqt_gauges.bar_gauge.h
+ 1 +
+ + TopicQLineEdit + QLineEdit +
rqt_gauges.topic_q_line_edit.h
+
+
+ + +
diff --git a/src/rqt_gauges/bar.py b/src/rqt_gauges/bar.py new file mode 100644 index 0000000..9cbdb16 --- /dev/null +++ b/src/rqt_gauges/bar.py @@ -0,0 +1,22 @@ +import os + +from ament_index_python.resources import get_resource +from qt_gui.plugin import Plugin + +from .base_widget import BaseWidget + + +class Bar(Plugin): + + def __init__(self, context): + super().__init__(context) + self.setObjectName('Bar') + + self._context = context + self._node = context.node + + _, package_path = get_resource('packages', 'rqt_gauges') + ui_file = os.path.join(package_path, 'share', 'rqt_gauges', 'resource', 'bar.ui') + self._widget = BaseWidget(self._node, 'Bar_widget', ui_file) + + context.add_widget(self._widget) From 10b570f2d29459c4eae669b0895a495a68dac69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Tue, 5 Mar 2024 15:35:28 +0100 Subject: [PATCH 06/13] Adding files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- src/rqt_gauges/bar_gauge.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/rqt_gauges/bar_gauge.py b/src/rqt_gauges/bar_gauge.py index 0fe71a4..34b8db8 100644 --- a/src/rqt_gauges/bar_gauge.py +++ b/src/rqt_gauges/bar_gauge.py @@ -1,7 +1,5 @@ -import math - from PyQt5.QtCore import pyqtSignal -from PyQt5.QtWidgets import QProgressBar, QWidget +from PyQt5.QtWidgets import QWidget class BarGauge(QWidget): @@ -57,4 +55,4 @@ def setMaxValue(self, max_value): def paintEvent(self, event): self.bar_gauge.setValue(self.value) - self.value_label.setText(str(raw_value / 100.0)) + self.value_label.setText(str(self.raw_value / 100.0)) From e18e08618643432e5033f2e6cbf228ea8e0cd2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Tue, 5 Mar 2024 16:34:25 +0100 Subject: [PATCH 07/13] Tweaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- resource/bar.ui | 32 ++++++++++++++++---------------- src/rqt_gauges/bar_gauge.py | 18 +++++++++++++----- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/resource/bar.ui b/resource/bar.ui index 217b3f8..c6246e9 100644 --- a/resource/bar.ui +++ b/resource/bar.ui @@ -6,19 +6,19 @@ 0 0 - 250 + 300 550
- 250 + 300 550 - 250 + 300 550 @@ -31,8 +31,8 @@ - 30 - 470 + 10 + 490 81 31 @@ -49,8 +49,8 @@ - 110 - 470 + 90 + 490 51 31 @@ -69,8 +69,8 @@ p, li { white-space: pre-wrap; } - 260 - 470 + 230 + 490 51 31 @@ -98,10 +98,10 @@ p, li { white-space: pre-wrap; } - 170 - 476 + 150 + 490 81 - 21 + 31 @@ -167,7 +167,7 @@ p, li { white-space: pre-wrap; } true - + - 0 - 436 + 25 + 425 221 61 diff --git a/src/rqt_gauges/bar_gauge.py b/src/rqt_gauges/bar_gauge.py index 34b8db8..f292e74 100644 --- a/src/rqt_gauges/bar_gauge.py +++ b/src/rqt_gauges/bar_gauge.py @@ -1,5 +1,5 @@ from PyQt5.QtCore import pyqtSignal -from PyQt5.QtWidgets import QWidget +from PyQt5.QtWidgets import QProgressBar, QWidget class BarGauge(QWidget): @@ -12,12 +12,17 @@ def __init__(self, node): super().__init__() - self.minValue = 0 - self.maxValue = 1 + # Progress bar + self.bar_gauge = QProgressBar(self) + self.bar_gauge.setGeometry(110, 126, 51, 301) + + self.minValue = 0.0 + self.maxValue = 1.0 self.raw_value = self.minValue self.value = self.minValue def updateValue(self, value: float): + print('UpdateValue()', value) # Updates the value that the gauge is indicating. # Args: # value: Value to update the gauge with. @@ -25,7 +30,9 @@ def updateValue(self, value: float): value = max(value, self.minValue) value = min(value, self.maxValue) self.value = value - self.repaint() + self.bar_gauge.setValue(self.value) + self.value_label.setText(str(self.raw_value)) + self.update() def setMinValue(self, min_value): # Modifies the minimum value of the gauge @@ -54,5 +61,6 @@ def setMaxValue(self, max_value): self.update() def paintEvent(self, event): + print('paintEvent()', self.value, ' ', self.raw_value) self.bar_gauge.setValue(self.value) - self.value_label.setText(str(self.raw_value / 100.0)) + self.value_label.setText(str(self.raw_value)) From 932d144a94fd759012ec872b85d8fadf8437727e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Tue, 5 Mar 2024 16:45:42 +0100 Subject: [PATCH 08/13] Updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- src/rqt_gauges/bar_gauge.py | 10 ++++++---- src/rqt_gauges/dial_gauge.py | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rqt_gauges/bar_gauge.py b/src/rqt_gauges/bar_gauge.py index f292e74..2b815dc 100644 --- a/src/rqt_gauges/bar_gauge.py +++ b/src/rqt_gauges/bar_gauge.py @@ -21,6 +21,8 @@ def __init__(self, node): self.raw_value = self.minValue self.value = self.minValue + self.show() + def updateValue(self, value: float): print('UpdateValue()', value) # Updates the value that the gauge is indicating. @@ -30,8 +32,8 @@ def updateValue(self, value: float): value = max(value, self.minValue) value = min(value, self.maxValue) self.value = value - self.bar_gauge.setValue(self.value) - self.value_label.setText(str(self.raw_value)) + self.bar_gauge.setValue(int(self.value * 100)) + # self.value_label.setText(str(self.raw_value)) self.update() def setMinValue(self, min_value): @@ -62,5 +64,5 @@ def setMaxValue(self, max_value): def paintEvent(self, event): print('paintEvent()', self.value, ' ', self.raw_value) - self.bar_gauge.setValue(self.value) - self.value_label.setText(str(self.raw_value)) + self.bar_gauge.setValue(int(self.value * 100)) + # self.value_label.setText(str(self.raw_value)) diff --git a/src/rqt_gauges/dial_gauge.py b/src/rqt_gauges/dial_gauge.py index 46e1a0b..0065430 100644 --- a/src/rqt_gauges/dial_gauge.py +++ b/src/rqt_gauges/dial_gauge.py @@ -408,6 +408,7 @@ def resizeEvent(self, event): self.rescale_method() def paintEvent(self, event): + print('paintEvent()') self.draw_outer_circle() # Colored pie area From 26b3b1a55ae8626d50e9cce042dc8c780c2ebbed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Tue, 5 Mar 2024 17:56:27 +0100 Subject: [PATCH 09/13] Functional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- resource/bar.ui | 4 ++-- src/rqt_gauges/bar_gauge.py | 35 +++++++++++++---------------------- src/rqt_gauges/dial_gauge.py | 2 -- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/resource/bar.ui b/resource/bar.ui index c6246e9..9dd81fb 100644 --- a/resource/bar.ui +++ b/resource/bar.ui @@ -256,7 +256,7 @@ p, li { white-space: pre-wrap; } %f% --> - + diff --git a/src/rqt_gauges/bar_gauge.py b/src/rqt_gauges/bar_gauge.py index 2b815dc..813a415 100644 --- a/src/rqt_gauges/bar_gauge.py +++ b/src/rqt_gauges/bar_gauge.py @@ -1,30 +1,31 @@ -from PyQt5.QtCore import pyqtSignal -from PyQt5.QtWidgets import QProgressBar, QWidget +from PyQt5.QtCore import pyqtSignal, Qt +from PyQt5.QtWidgets import QLabel, QProgressBar, QWidget class BarGauge(QWidget): updateValueSignal = pyqtSignal(float) - def __init__(self, node): + def __init__(self, parent): # Constructor method of the class, initializes all the variables needed to create # the gauge. - super().__init__() + super().__init__(parent) # Progress bar - self.bar_gauge = QProgressBar(self) - self.bar_gauge.setGeometry(110, 126, 51, 301) + self.bar = QProgressBar(parent) + self.bar.setGeometry(110, 126, 51, 301) + self.bar.setOrientation(Qt.Vertical) + + self.valueLabel = QLabel(parent) + self.valueLabel.setGeometry(25, 425, 221, 61) self.minValue = 0.0 - self.maxValue = 1.0 + self.maxValue = 100.0 self.raw_value = self.minValue self.value = self.minValue - self.show() - def updateValue(self, value: float): - print('UpdateValue()', value) # Updates the value that the gauge is indicating. # Args: # value: Value to update the gauge with. @@ -32,9 +33,8 @@ def updateValue(self, value: float): value = max(value, self.minValue) value = min(value, self.maxValue) self.value = value - self.bar_gauge.setValue(int(self.value * 100)) - # self.value_label.setText(str(self.raw_value)) - self.update() + self.bar.setValue(int(self.value)) + self.valueLabel.setText(str(self.raw_value)) def setMinValue(self, min_value): # Modifies the minimum value of the gauge @@ -47,8 +47,6 @@ def setMinValue(self, min_value): else: self.minValue = min_value - self.update() - def setMaxValue(self, max_value): # Modifies the maximum value of the gauge # Args: @@ -59,10 +57,3 @@ def setMaxValue(self, max_value): self.maxValue = self.minValue + 1 else: self.maxValue = max_value - - self.update() - - def paintEvent(self, event): - print('paintEvent()', self.value, ' ', self.raw_value) - self.bar_gauge.setValue(int(self.value * 100)) - # self.value_label.setText(str(self.raw_value)) diff --git a/src/rqt_gauges/dial_gauge.py b/src/rqt_gauges/dial_gauge.py index 0065430..fa0d179 100644 --- a/src/rqt_gauges/dial_gauge.py +++ b/src/rqt_gauges/dial_gauge.py @@ -408,8 +408,6 @@ def resizeEvent(self, event): self.rescale_method() def paintEvent(self, event): - print('paintEvent()') - self.draw_outer_circle() # Colored pie area if self.enable_filled_Polygon: From 10bad3bd6ae5e260c444cefe5374d90728fd979c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Tue, 5 Mar 2024 21:00:22 +0100 Subject: [PATCH 10/13] QT Style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- resource/bar.ui | 116 ++++++++++++++++++------------------ src/rqt_gauges/bar_gauge.py | 27 ++++++--- 2 files changed, 78 insertions(+), 65 deletions(-) diff --git a/resource/bar.ui b/resource/bar.ui index 9dd81fb..ba71ac8 100644 --- a/resource/bar.ui +++ b/resource/bar.ui @@ -6,20 +6,20 @@ 0 0 - 300 - 550 + 250 + 475 - 300 - 550 + 250 + 475 - 300 - 550 + 250 + 475 @@ -32,7 +32,7 @@ 10 - 490 + 410 81 31 @@ -50,7 +50,7 @@ 90 - 490 + 410 51 31 @@ -69,8 +69,8 @@ p, li { white-space: pre-wrap; } - 230 - 490 + 90 + 115 51 31 @@ -89,7 +89,7 @@ p, li { white-space: pre-wrap; } <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;">180</p></body></html> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">100</p></body></html> @@ -98,8 +98,8 @@ p, li { white-space: pre-wrap; } - 150 - 490 + 10 + 115 81 31 @@ -294,150 +294,150 @@ p, li { white-space: pre-wrap; } - 86 - 109 - 20 - 31 + 202 + 102 + 40 + 41 - 1 + 100% - 80 + 210 380 - 21 + 31 31 - 0.1 + 10% - 80 + 210 260 31 21 - 0.5 + 50% - 85 + 219 410 - 21 + 31 31 - 0 + 0% - 80 + 210 320 - 21 + 31 21 - 0.3 + 30% - 80 + 210 350 - 21 + 31 21 - 0.2 + 20% - 80 + 210 170 - 21 + 31 21 - 0.8 + 80% - 80 + 210 290 - 21 + 31 21 - 0.4 + 40% - 80 + 210 230 - 21 + 31 21 - 0.6 + 60% - 80 + 210 140 - 21 + 31 21 - 0.9 + 90% - 80 + 210 200 - 21 + 31 21 - 0.7 + 70% - 100 + 191 420 16 16 @@ -450,7 +450,7 @@ p, li { white-space: pre-wrap; } - 100 + 191 116 16 20 @@ -463,7 +463,7 @@ p, li { white-space: pre-wrap; } - 100 + 191 390 16 16 @@ -476,7 +476,7 @@ p, li { white-space: pre-wrap; } - 100 + 191 140 16 31 @@ -489,7 +489,7 @@ p, li { white-space: pre-wrap; } - 100 + 191 170 16 31 @@ -502,7 +502,7 @@ p, li { white-space: pre-wrap; } - 100 + 191 200 16 31 @@ -515,7 +515,7 @@ p, li { white-space: pre-wrap; } - 100 + 191 230 16 31 @@ -528,7 +528,7 @@ p, li { white-space: pre-wrap; } - 100 + 191 260 16 31 @@ -541,7 +541,7 @@ p, li { white-space: pre-wrap; } - 100 + 191 290 16 31 @@ -554,7 +554,7 @@ p, li { white-space: pre-wrap; } - 100 + 191 320 16 31 @@ -567,7 +567,7 @@ p, li { white-space: pre-wrap; } - 100 + 191 350 16 31 diff --git a/src/rqt_gauges/bar_gauge.py b/src/rqt_gauges/bar_gauge.py index 813a415..06ccb3b 100644 --- a/src/rqt_gauges/bar_gauge.py +++ b/src/rqt_gauges/bar_gauge.py @@ -12,18 +12,23 @@ def __init__(self, parent): super().__init__(parent) + self.minValue = 0.0 + self.maxValue = 100.0 + self.raw_value = self.minValue + self.value = self.minValue + # Progress bar self.bar = QProgressBar(parent) - self.bar.setGeometry(110, 126, 51, 301) + self.bar.setGeometry(150, 126, 51, 301) self.bar.setOrientation(Qt.Vertical) + self.bar.setRange(int(self.minValue), int(self.maxValue)) + # Value label self.valueLabel = QLabel(parent) - self.valueLabel.setGeometry(25, 425, 221, 61) - - self.minValue = 0.0 - self.maxValue = 100.0 - self.raw_value = self.minValue - self.value = self.minValue + self.valueLabel.setGeometry(65, 425, 221, 61) + self.valueLabel.setAlignment(Qt.AlignCenter) + self.valueLabel.setStyleSheet("QLabel{font-size: 25pt;}") + self.valueLabel.setText('0.0') def updateValue(self, value: float): # Updates the value that the gauge is indicating. @@ -35,6 +40,8 @@ def updateValue(self, value: float): self.value = value self.bar.setValue(int(self.value)) self.valueLabel.setText(str(self.raw_value)) + + self.update() def setMinValue(self, min_value): # Modifies the minimum value of the gauge @@ -47,6 +54,9 @@ def setMinValue(self, min_value): else: self.minValue = min_value + self.bar.setRange(int(self.minValue), int(self.maxValue)) + self.update() + def setMaxValue(self, max_value): # Modifies the maximum value of the gauge # Args: @@ -57,3 +67,6 @@ def setMaxValue(self, max_value): self.maxValue = self.minValue + 1 else: self.maxValue = max_value + + self.bar.setRange(int(self.minValue), int(self.maxValue)) + self.update() From 011fc316146cbe00ca3dd8e3df95b5a66f9fac59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Tue, 5 Mar 2024 21:01:43 +0100 Subject: [PATCH 11/13] Clean MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- resource/bar.ui | 111 ------------------------------------ src/rqt_gauges/bar_gauge.py | 4 +- 2 files changed, 2 insertions(+), 113 deletions(-) diff --git a/resource/bar.ui b/resource/bar.ui index ba71ac8..0ac428e 100644 --- a/resource/bar.ui +++ b/resource/bar.ui @@ -167,117 +167,6 @@ p, li { white-space: pre-wrap; } true - - - diff --git a/src/rqt_gauges/bar_gauge.py b/src/rqt_gauges/bar_gauge.py index 06ccb3b..f0d6fb2 100644 --- a/src/rqt_gauges/bar_gauge.py +++ b/src/rqt_gauges/bar_gauge.py @@ -27,7 +27,7 @@ def __init__(self, parent): self.valueLabel = QLabel(parent) self.valueLabel.setGeometry(65, 425, 221, 61) self.valueLabel.setAlignment(Qt.AlignCenter) - self.valueLabel.setStyleSheet("QLabel{font-size: 25pt;}") + self.valueLabel.setStyleSheet('QLabel{font-size: 25pt;}') self.valueLabel.setText('0.0') def updateValue(self, value: float): @@ -40,7 +40,7 @@ def updateValue(self, value: float): self.value = value self.bar.setValue(int(self.value)) self.valueLabel.setText(str(self.raw_value)) - + self.update() def setMinValue(self, min_value): From d5ebb40e851c5f8097792de82483b2d09adfe918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Thu, 7 Mar 2024 16:03:55 +0100 Subject: [PATCH 12/13] Tweaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- resource/dial.ui | 22 +--------------------- resource/rotational.ui | 20 ++++++++++---------- src/rqt_gauges/base_widget.py | 11 +++++++++++ 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/resource/dial.ui b/resource/dial.ui index 7352e72..82e3622 100644 --- a/resource/dial.ui +++ b/resource/dial.ui @@ -181,7 +181,7 @@ p, li { white-space: pre-wrap; } Units: - + 370 @@ -190,26 +190,6 @@ p, li { white-space: pre-wrap; } 31 - - - Mph - - - - - Km/h - - - - - m/s - - - - - - - diff --git a/resource/rotational.ui b/resource/rotational.ui index a6e4194..5d1e41c 100644 --- a/resource/rotational.ui +++ b/resource/rotational.ui @@ -31,8 +31,8 @@ - 40 - 460 + 30 + 470 81 31 @@ -49,8 +49,8 @@ - 120 - 460 + 110 + 470 51 31 @@ -60,7 +60,7 @@ <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;">0</p></body></html> +<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> @@ -72,8 +72,8 @@ p, li { white-space: pre-wrap; } - 272 - 460 + 260 + 470 51 31 @@ -101,10 +101,10 @@ p, li { white-space: pre-wrap; } - 190 - 460 + 170 + 476 81 - 31 + 21 diff --git a/src/rqt_gauges/base_widget.py b/src/rqt_gauges/base_widget.py index 86d859e..9dd89a1 100644 --- a/src/rqt_gauges/base_widget.py +++ b/src/rqt_gauges/base_widget.py @@ -42,6 +42,12 @@ def __init__(self, node, name, ui_path): except AttributeError: print("obj does not have attribute 'minValue'") + try: + getattr(self.gauge, 'units') + self.units.textChanged.connect(self.updateUnits) + except AttributeError: + pass + # Signals Connection self.subscribe_button.pressed.connect(self.updateSubscription) self.gauge.updateValueSignal.connect(self.updateValue) @@ -79,6 +85,11 @@ def updateMaxValue(self): def updateValue(self, value): self.gauge.updateValue(value) + @pyqtSlot() + def updateUnits(self): + self.gauge.units = self.units.toPlainText() + self.gauge.update() + @pyqtSlot() def updateSubscription(self): if self.node.destroy_subscription(self.sub): 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 13/13] 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()