35 from dynamic_reconfigure
import (DynamicReconfigureCallbackException,
36 DynamicReconfigureParameterException)
37 from dynamic_reconfigure.encoding
import Config
39 from python_qt_binding.QtCore
import QMargins
40 from python_qt_binding.QtGui
import QIcon
41 from python_qt_binding.QtWidgets
import (QFileDialog, QHBoxLayout,
44 from rospy.service
import ServiceException
48 from rqt_reconfigure
import logging
55 mapping = loader.construct_mapping(node, deep=
True)
56 assert 'state' in mapping
57 return Config(mapping.get(
'dictitems', {}))
61 u'tag:yaml.org,2002:python/object/new:dynamic_reconfigure.encoding.Config',
62 config_constructor, Loader=yaml.SafeLoader)
67 A wrapper of dynamic_reconfigure.client instance. 69 Represents a widget where users can view and modify ROS params. 74 :type reconf: dynamic_reconfigure.client 77 group_desc = reconf.get_group_descriptions()
78 logging.debug(
'ParamClientWidget.group_desc={}'.format(group_desc))
80 group_desc, node_name)
85 self.button_header.setContentsMargins(QMargins(0, 0, 0, 0))
90 self.load_button.setIcon(QIcon.fromTheme(
'document-open'))
91 self.save_button.setIcon(QIcon.fromTheme(
'document-save'))
99 self.setMinimumWidth(150)
116 names = [name
for name, v
in config.items()]
121 if isinstance(widget, EditorWidget):
122 if widget.param_name
in names:
123 logging.debug(
'EDITOR widget.param_name={}'.format(
125 widget.update_value(config[widget.param_name])
126 elif isinstance(widget, GroupWidget):
127 cfg =
find_cfg(config, widget.param_name)
128 logging.debug(
'GROUP widget.param_name={}'.format(
130 widget.update_group(cfg)
133 filename = QFileDialog.getOpenFileName(
134 self, self.tr(
'Load from File'),
'.',
135 self.tr(
'YAML file {.yaml} (*.yaml)'))
136 if filename[0] !=
'':
140 filename = QFileDialog.getSaveFileName(
141 self, self.tr(
'Save parameters to file...'),
'.',
142 self.tr(
'YAML files {.yaml} (*.yaml)'))
143 if filename[0] !=
'':
147 configuration = self.reconf.get_configuration()
148 if configuration
is not None:
149 with open(filename,
'w')
as f:
150 yaml.dump(configuration, f)
153 with open(filename,
'r') as f: 155 for doc
in yaml.safe_load_all(f.read()):
156 configuration.update(doc)
159 self.reconf.update_configuration(configuration)
160 except ServiceException
as e:
162 "Call for reconfiguration wasn't successful" 163 ' because: {}'.format(e.message)
165 except DynamicReconfigureParameterException
as e:
167 "Reconfiguration wasn't successful" 168 ' because: {}'.format(e.message)
170 except DynamicReconfigureCallbackException
as e:
172 "Reconfiguration wasn't successful" 173 ' because: {}'.format(e.message)