35 from dynamic_reconfigure
import (DynamicReconfigureCallbackException,
36 DynamicReconfigureParameterException)
38 from python_qt_binding.QtCore
import QMargins
39 from python_qt_binding.QtGui
import QIcon
40 from python_qt_binding.QtWidgets
import (QFileDialog, QHBoxLayout,
43 from rospy.service
import ServiceException
48 from .param_editors
import EditorWidget
49 from .param_groups
import find_cfg, GroupWidget
50 from .param_updater
import ParamUpdater
55 A wrapper of dynamic_reconfigure.client instance. 57 Represents a widget where users can view and modify ROS params. 62 :type reconf: dynamic_reconfigure.client 65 group_desc = reconf.get_group_descriptions()
66 logging.debug(
'DynreconfClientWidget.group_desc=%s', group_desc)
67 super(DynreconfClientWidget, self).
__init__(ParamUpdater(reconf),
68 group_desc, node_name)
73 self.button_header.setContentsMargins(QMargins(0, 0, 0, 0))
78 self.load_button.setIcon(QIcon.fromTheme(
'document-open'))
79 self.save_button.setIcon(QIcon.fromTheme(
'document-save'))
87 self.setMinimumWidth(150)
104 names = [name
for name, v
in config.items()]
108 for widget
in self.editor_widgets:
109 if isinstance(widget, EditorWidget):
110 if widget.param_name
in names:
111 logging.debug(
'EDITOR widget.param_name=%s',
113 widget.update_value(config[widget.param_name])
114 elif isinstance(widget, GroupWidget):
115 cfg =
find_cfg(config, widget.param_name)
116 logging.debug(
'GROUP widget.param_name=%s',
118 widget.update_group(cfg)
121 filename = QFileDialog.getOpenFileName(
122 self, self.tr(
'Load from File'),
'.',
123 self.tr(
'YAML file {.yaml} (*.yaml)'))
124 if filename[0] !=
'':
128 filename = QFileDialog.getSaveFileName(
129 self, self.tr(
'Save parameters to file...'),
'.',
130 self.tr(
'YAML files {.yaml} (*.yaml)'))
131 if filename[0] !=
'':
135 configuration = self.reconf.get_configuration()
136 if configuration
is not None:
137 with open(filename,
'w')
as f:
138 yaml.dump(configuration, f)
141 with open(filename,
'r') as f: 143 for doc
in yaml.load_all(f.read()):
144 configuration.update(doc)
147 self.reconf.update_configuration(configuration)
148 except ServiceException
as e:
150 "Call for reconfiguration wasn't successful because: %s",
153 except DynamicReconfigureParameterException
as e:
155 "Reconfiguration wasn't successful because: %s",
158 except DynamicReconfigureCallbackException
as e:
160 "Reconfiguration wasn't successful because: %s",
168 for w
in self.editor_widgets: