Skip to content

Commit

Permalink
Use rosidl_runtime_py instead of rqt_py_common where possible (#24)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno committed Mar 16, 2021
1 parent 5d2ed2e commit 67918b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 55 deletions.
56 changes: 6 additions & 50 deletions src/rqt_publisher/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@

from rclpy.exceptions import InvalidTopicNameException
from rclpy.qos import QoSProfile

from rosidl_runtime_py.utilities import get_message

from rqt_gui_py.plugin import Plugin

from .publisher_widget import PublisherWidget
from rqt_py_common.message_helpers import get_message_class
from rqt_py_common.topic_helpers import get_slot_type

_list_types = [list, tuple, array.array]
try:
Expand Down Expand Up @@ -128,7 +130,7 @@ def _add_publisher(self, publisher_info):
if publisher_info['message_instance'] is None:
return

msg_module = get_message_class(publisher_info['type_name'])
msg_module = get_message(publisher_info['type_name'])
if not msg_module:
raise RuntimeError(
'The passed message type "{}" is invalid'.format(publisher_info['type_name']))
Expand Down Expand Up @@ -212,52 +214,6 @@ def _change_publisher_rate(self, publisher_info, topic_name, new_value):
# make sure the column value reflects the actual rate
return '%.2f' % publisher_info['rate']

def _change_publisher_expression(self, publisher_info, topic_name, new_value):
expression = str(new_value)
if len(expression) == 0:
if topic_name in publisher_info['expressions']:
del publisher_info['expressions'][topic_name]
# qDebug(
# 'Publisher._change_publisher_expression(): removed expression'
# 'for: %s' % (topic_name))
else:
# Strip topic name from the full topic path
slot_path = topic_name.replace(publisher_info['topic_name'], '', 1)
slot_path, slot_array_index = self._extract_array_info(slot_path)

# Get the property type from the message class
slot_type, is_array = \
get_slot_type(publisher_info['message_instance'].__class__, slot_path)
if slot_array_index is not None:
is_array = False

if is_array:
slot_type = list
# strip possible trailing error message from expression
error_prefix = '# error'
error_prefix_pos = expression.find(error_prefix)
if error_prefix_pos >= 0:
expression = expression[:error_prefix_pos]
success, _ = self._evaluate_expression(expression, slot_type)
if success:
old_expression = publisher_info['expressions'].get(topic_name, None)
publisher_info['expressions'][topic_name] = expression
try:
self._fill_message_slots(
publisher_info['message_instance'], publisher_info['topic_name'],
publisher_info['expressions'], publisher_info['counter'])

except Exception as e:
if old_expression is not None:
publisher_info['expressions'][topic_name] = old_expression
else:
del publisher_info['expressions'][topic_name]
return '%s %s: %s' % (expression, error_prefix, e)
return expression
else:
return '%s %s evaluating as "%s"' % (
expression, error_prefix, slot_type.__name__)

def _extract_array_info(self, type_str):
array_size = None
if '[' in type_str and type_str[-1] == ']':
Expand All @@ -274,7 +230,7 @@ def _create_message_instance(self, type_str):
base_type_str, array_size = self._extract_array_info(type_str)

try:
base_message_type = get_message_class(base_type_str)
base_message_type = get_message(base_type_str)
except LookupError as e:
qWarning("Creating message type {} failed. Please check your spelling and that the "
"message package has been built\n{}".format(base_type_str, e))
Expand Down
12 changes: 7 additions & 5 deletions src/rqt_publisher/publisher_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@
from qt_gui.ros_package_helper import get_package_path
from qt_gui_py_common.worker_thread import WorkerThread

from .publisher_tree_widget import PublisherTreeWidget
from rosidl_runtime_py import get_message_interfaces
from rosidl_runtime_py.utilities import get_message

from rqt_py_common.extended_combo_box import ExtendedComboBox
from rqt_py_common.message_helpers import get_message_class, get_all_message_types

from .publisher_tree_widget import PublisherTreeWidget

# main class inherits from the ui window class
class PublisherWidget(QWidget):
Expand Down Expand Up @@ -114,11 +116,11 @@ def _get_message_types(self, package_name):
def _update_thread_run(self):
# update type_combo_box
message_type_names = []
message_types = get_all_message_types()
message_types = get_message_interfaces()
for package, message_types in message_types.items():
for message_type in message_types:
base_type_str = package + '/msg/' + message_type
message_class = get_message_class(base_type_str)
base_type_str = f'{package}/{message_type}'
message_class = get_message(base_type_str)
if message_class is not None:
message_type_names.append(base_type_str)

Expand Down

0 comments on commit 67918b6

Please sign in to comment.