Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small cleanups to rqt_msg #16

Merged
merged 3 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<package format="2">
<name>rqt_msg</name>
<version>1.4.0</version>
<description>A Python GUI plugin for introspecting available ROS message types.
Note that the msgs available through this plugin is the ones that are stored
on your machine, not on the ROS core your rqt instance connects to.
</description>
<description>A Python GUI plugin for introspecting available ROS message types.</description>

<maintainer email="brandon@openrobotics.org">Brandon Ong</maintainer>

Expand All @@ -19,14 +16,18 @@
<author email="dthomas@osrfoundation.org">Dirk Thomas</author>
<author email="mikeblautman@gmail.com">Michael Lautman</author>

<exec_depend>python3-catkin-pkg-modules</exec_depend>
<exec_depend>ament_index_python</exec_depend>
<exec_depend version_gte="0.2.19">python_qt_binding</exec_depend>
<exec_depend>rclpy</exec_depend>
<exec_depend>rosidl_runtime_py</exec_depend>
<exec_depend>rqt_gui</exec_depend>
<exec_depend>rqt_gui_py</exec_depend>
<exec_depend>rqt_py_common</exec_depend>
<exec_depend>rqt_console</exec_depend>

<test_depend>ament_flake8</test_depend>
<test_depend>ament_xmllint</test_depend>

<export>
<architecture_independent/>
<rqt_gui plugin="${prefix}/plugin.xml"/>
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
'Topic :: Software Development',
],
description=(
'A Python GUI plugin for introspecting available ROS message types.' +
'Note that the msgs available through this plugin is the ones that are stored ' +
'on your machine, not on the ROS core your rqt instance connects to.'
'A Python GUI plugin for introspecting available ROS message types.'
),
license='BSD',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'rqt_msg = ' + package_name + '.main:main',
Expand Down
1 change: 0 additions & 1 deletion src/rqt_msg/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys

from rqt_gui.main import Main
from rqt_msg.messages import Messages


def main():
Expand Down
45 changes: 25 additions & 20 deletions src/rqt_msg/messages_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import os

from ament_index_python.resources import get_resource, get_resources
from ament_index_python.resources import get_resource

from python_qt_binding import loadUi
from python_qt_binding.QtCore import Qt
Expand All @@ -42,24 +42,23 @@

from rclpy import logging

from rosidl_runtime_py.utilities import get_action, get_service, get_message
from rosidl_runtime_py import get_action_interfaces, get_service_interfaces, get_message_interfaces
from rosidl_runtime_py import get_action_interfaces, get_message_interfaces, get_service_interfaces
from rosidl_runtime_py.utilities import get_action, get_message, get_service

from rqt_console.text_browse_dialog import TextBrowseDialog

from rqt_msg.messages_tree_view import MessagesTreeView

# from rqt_py_common import rosaction

from rqt_py_common import message_helpers
from rqt_py_common.rqt_roscomm_util import RqtRoscommUtil
from rqt_py_common.message_helpers import \
get_action_text_from_class, get_message_text_from_class, get_service_text_from_class
from rqt_py_common.rqt_roscomm_util import RqtRoscommUtil


class MessagesWidget(QWidget):
"""
This class is intended to be able to handle msg, srv & action (actionlib).
This class is intended to be able to handle msg, srv & action.

The name of the class is kept to use message, by following the habit of
rosmsg (a script that can handle both msg & srv).
"""
Expand All @@ -68,6 +67,8 @@ def __init__(self, mode=message_helpers.MSG_MODE,
pkg_name='rqt_msg',
ui_filename='messages.ui'):
"""
Construct a new MessagesWidget.

:param ui_filename: This Qt-based .ui file must have elements that are
referred from this class. Otherwise unexpected
errors are likely to happen. Best way to avoid that
Expand All @@ -77,7 +78,7 @@ def __init__(self, mode=message_helpers.MSG_MODE,
"""
super(MessagesWidget, self).__init__()

self._logger = logging.get_logger("MessagesWidget")
self._logger = logging.get_logger('MessagesWidget')

_, package_path = get_resource('packages', pkg_name)
ui_file = os.path.join(
Expand Down Expand Up @@ -109,12 +110,18 @@ def _refresh_msgs(self, package=None):
if package is None or len(package) == 0:
return
self._msgs = []
interfaces = {}
if self._mode == message_helpers.MSG_MODE:
msg_list = [f'{package}/{name}' for name in get_message_interfaces([package])[package]]
interfaces = get_message_interfaces([package])
elif self._mode == message_helpers.SRV_MODE:
msg_list = [f'{package}/{name}' for name in get_service_interfaces([package])[package]]
interfaces = get_service_interfaces([package])
elif self._mode == message_helpers.ACTION_MODE:
msg_list = [f'{package}/{name}' for name in get_action_interfaces([package])[package]]
interfaces = get_action_interfaces([package])

msg_list = []
if package in interfaces:
msg_list = [f'{package}/{name}' for name in interfaces[package]]

self._logger.debug(
'_refresh_msgs package={} msg_list={}'.format(package, msg_list))
for msg in msg_list:
Expand Down Expand Up @@ -186,9 +193,7 @@ def _handle_mouse_press(self, event,
return old_pressEvent(self._messages_tree, event)

def _rightclick_menu(self, event):
"""
:type event: QEvent
"""
""":type event: QEvent."""
# QTreeview.selectedIndexes() returns 0 when no node is selected.
# This can happen when after booting no left-click has been made yet
# (ie. looks like right-click doesn't count). These lines are the
Expand Down Expand Up @@ -220,7 +225,7 @@ def _rightclick_menu(self, event):

# We only want the base class so we transform eg. pkg1/my_srv/Request -> pkg1/my_srv
if selected_type_bare_tokens_len > 2:
selected_type_bare = "/".join(selected_type_bare.split('/')[:2])
selected_type_bare = '/'.join(selected_type_bare.split('/')[:2])

browsetext = None

Expand All @@ -236,18 +241,18 @@ def _rightclick_menu(self, event):
# If the type has two '/'s then we treat it as a srv or action type
elif selected_type_bare_tokens_len == 3:
if self._mode == message_helpers.SRV_MODE:
msg_class = get_service(selected_type_bare)
browsetext = get_service_text_from_class(msg_class)
msg_class = get_service(selected_type_bare)
browsetext = get_service_text_from_class(msg_class)

elif self._mode == message_helpers.ACTION_MODE:
msg_class = get_action(selected_type_bare)
browsetext = get_action_text_from_class(msg_class)

else:
self._logger.warn("Unrecognized value for self._mode: {} "
"for selected_type: {}".format(self._mode, selected_type))
self._logger.warn('Unrecognized value for self._mode: {} '
'for selected_type: {}'.format(self._mode, selected_type))
else:
self._logger.warn("Invalid selected_type: {}".format(selected_type))
self._logger.warn('Invalid selected_type: {}'.format(selected_type))

if browsetext is not None:
self._browsers.append(TextBrowseDialog(browsetext))
Expand Down
23 changes: 23 additions & 0 deletions test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2019 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_flake8.main import main
import pytest


@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc = main(argv=[])
assert rc == 0, 'Found errors'
23 changes: 23 additions & 0 deletions test/test_xmllint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2019 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_xmllint.main import main
import pytest


@pytest.mark.linter
@pytest.mark.xmllint
def test_xmllint():
rc = main(argv=['.'])
assert rc == 0, 'Found errors'