Skip to content

Commit

Permalink
Allow drag and drop from rqt_topic_monitor (#29)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Co-authored-by: Carlos Agüero <[email protected]>
  • Loading branch information
ahcorde and caguero authored Feb 8, 2024
1 parent f697c5c commit 8e11aca
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
12 changes: 12 additions & 0 deletions resource/speedometer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<height>500</height>
</size>
</property>
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>Speedometer</string>
</property>
Expand Down Expand Up @@ -153,6 +159,9 @@ p, li { white-space: pre-wrap; }
<height>411</height>
</rect>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="units_label">
<property name="geometry">
Expand Down Expand Up @@ -211,6 +220,9 @@ p, li { white-space: pre-wrap; }
<height>31</height>
</rect>
</property>
<property name="dragEnabled">
<bool>false</bool>
</property>
</widget>
</widget>
<customwidgets>
Expand Down
3 changes: 3 additions & 0 deletions resource/steering_wheel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<height>550</height>
</size>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>SteeringWheel</string>
</property>
Expand Down
3 changes: 3 additions & 0 deletions resource/throttle_brake_pedals.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<height>550</height>
</size>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>ThrottleBrakePedals</string>
</property>
Expand Down
13 changes: 13 additions & 0 deletions src/rqt_gauges/speedometer_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ def __init__(self, node):
self.subscribe_button.pressed.connect(self.updateSubscription)
self.speedometer_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 updateMinValue(self):
new_min_value = self.min_value.toPlainText()
Expand Down
13 changes: 13 additions & 0 deletions src/rqt_gauges/steering_wheel_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ def __init__(self, node):
self.subscribe_button.pressed.connect(self.updateSubscription)
self.steering_wheel_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()
Expand Down
20 changes: 19 additions & 1 deletion src/rqt_gauges/throttle_brake_pedals_widget.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from ament_index_python.resources import get_resource
from PyQt5.QtCore import pyqtSignal, pyqtSlot
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
Expand Down Expand Up @@ -46,6 +46,24 @@ def __init__(self, node):
self.updateThrottleValueSignal.connect(self.updateThrottle)
self.updateBrakeValueSignal.connect(self.updateBrake)

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))

if (event.pos().x() < self.size().width() / 2):
self.throttle_topic_to_subscribe.setText(topic_name)
self.throttleUpdateSubscription()
else:
self.brake_topic_to_subscribe.setText(topic_name)
self.brakeUpdateSubscription()
event.accept()

@pyqtSlot()
def throttleUpdateSubscription(self):
if self.node.destroy_subscription(self.throttle_sub):
Expand Down

0 comments on commit 8e11aca

Please sign in to comment.