Skip to content

Commit

Permalink
Tweak limits.
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Agüero <[email protected]>
  • Loading branch information
caguero committed Mar 13, 2024
1 parent d5ebb40 commit fcd44f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 69 deletions.
42 changes: 2 additions & 40 deletions resource/rotational.ui
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,13 @@
<property name="windowTitle">
<string>Rotational</string>
</property>
<widget class="QLabel" name="min_value_label">
<property name="geometry">
<rect>
<x>30</x>
<y>470</y>
<width>81</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Min Value:</string>
</property>
</widget>
<widget class="QTextEdit" name="min_value">
<property name="geometry">
<rect>
<x>110</x>
<y>470</y>
<width>51</width>
<height>31</height>
</rect>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;-45&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="placeholderText">
<string/>
</property>
</widget>
<widget class="QTextEdit" name="max_value">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>260</x>
<x>230</x>
<y>470</y>
<width>51</width>
<height>31</height>
Expand Down Expand Up @@ -101,7 +63,7 @@ p, li { white-space: pre-wrap; }
<widget class="QLabel" name="max_value_label">
<property name="geometry">
<rect>
<x>170</x>
<x>140</x>
<y>476</y>
<width>81</width>
<height>21</height>
Expand Down
30 changes: 14 additions & 16 deletions src/rqt_gauges/base_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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):
Expand Down
20 changes: 7 additions & 13 deletions src/rqt_gauges/rotational_gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit fcd44f5

Please sign in to comment.