35 from decimal
import Decimal
39 from python_qt_binding
import loadUi
40 from python_qt_binding.QtCore
import QLocale, Signal
41 from python_qt_binding.QtGui
import QDoubleValidator, QIntValidator
42 from python_qt_binding.QtWidgets
import QMenu, QWidget
49 'bool':
'BooleanEditor',
50 'str':
'StringEditor',
51 'int':
'IntegerEditor',
52 'double':
'DoubleEditor',
58 ui_bool = os.path.join(rp.get_path(
'rqt_reconfigure'),
'resource',
60 ui_str = os.path.join(rp.get_path(
'rqt_reconfigure'),
'resource',
62 ui_num = os.path.join(rp.get_path(
'rqt_reconfigure'),
'resource',
65 ui_enum = os.path.join(rp.get_path(
'rqt_reconfigure'),
'resource',
71 This class is abstract -- its child classes should be instantiated. 73 There exist two kinds of "update" methods: 74 - _update_paramserver for Parameter Server. 75 - update_value for the value displayed on GUI. 80 @param updater: A class that extends threading.Thread. 81 @type updater: rqt_reconfigure.param_updater.ParamUpdater 94 self.tr(
'Set to Default')
99 Update the value on Parameter Server. 107 To be implemented in subclass, but still used. 109 Update the value that's displayed on the arbitrary GUI component 110 based on user's input. 112 This method is not called from the GUI thread, so any changes to 113 QObjects will need to be done through a signal. 118 self._updater.update({self.
param_name: value})
122 Should be overridden in subclass. 124 :type grid: QFormLayout 126 self._paramname_label.setText(self.
param_name)
129 self._paramname_label.setMinimumWidth(100)
130 grid.addRow(self._paramname_label, self)
137 Should be overridden in subclass. 142 self._update_paramserver(self.param_default)
145 self.cmenu.exec_(e.globalPos())
149 _update_signal = Signal(bool)
152 super(BooleanEditor, self).
__init__(updater, config)
153 loadUi(ui_bool, self)
162 self._update_signal.connect(self._checkbox.setChecked)
169 self._update_signal.emit(value)
173 _update_signal = Signal(str)
176 super(StringEditor, self).
__init__(updater, config)
179 self._paramval_lineedit.setText(config[
'default'])
183 self._paramval_lineedit.editingFinished.connect(self.
edit_finished)
186 self._update_signal.connect(self._paramval_lineedit.setText)
189 self.cmenu.addAction(self.tr(
'Set to Empty String')
194 logging.debug(
'StringEditor update_value={}'.format(value))
195 self._update_signal.emit(value)
198 logging.debug(
'StringEditor edit_finished val={}'.format(
199 self._paramval_lineedit.text()))
207 _update_signal = Signal(int)
210 super(IntegerEditor, self).
__init__(updater, config)
216 self._min_val_label.setText(str(self.
_min))
217 self._max_val_label.setText(str(self.
_max))
218 self._slider_horizontal.setRange(self.
_min, self.
_max)
222 self._paramval_lineEdit.setValidator(QIntValidator(self.
_min,
226 self._paramval_lineEdit.setText(str(config[
'default']))
227 self._slider_horizontal.setValue(int(config[
'default']))
230 self._slider_horizontal.sliderMoved.connect(self.
_slider_moved)
233 self._paramval_lineEdit.editingFinished.connect(self.
_text_changed)
237 self._slider_horizontal.setTracking(
False)
244 self.cmenu.addAction(self.tr(
'Set to Maximum')
246 self.cmenu.addAction(self.tr(
'Set to Minimum')
251 self._paramval_lineEdit.setText(str(
252 self._slider_horizontal.sliderPosition()))
266 self._update_signal.emit(int(value))
270 self._slider_horizontal.blockSignals(
True)
272 self._slider_horizontal.setValue(value)
274 self._paramval_lineEdit.setText(str(value))
275 self._slider_horizontal.blockSignals(
False)
285 _update_signal = Signal(float)
288 super(DoubleEditor, self).
__init__(updater, config)
292 if config[
'min'] != -float(
'inf'):
293 self.
_min = float(config[
'min'])
294 self._min_val_label.setText(str(self.
_min))
297 self._min_val_label.setText(
'-inf')
299 if config[
'max'] != float(
'inf'):
300 self.
_max = float(config[
'max'])
301 self._max_val_label.setText(str(self.
_max))
304 self._max_val_label.setText(
'inf')
306 if config[
'min'] != -float(
'inf')
and config[
'max'] != float(
'inf'):
310 self.
_func =
lambda x: math.atan(x)
311 self.
_ifunc =
lambda x: math.tan(x)
317 self.setDisabled(
True)
324 validator = QDoubleValidator(self.
_min, self.
_max, 8, self)
325 validator.setLocale(QLocale(QLocale.C))
326 self._paramval_lineEdit.setValidator(validator)
329 self._paramval_lineEdit.setText(str(config[
'default']))
330 self._slider_horizontal.setValue(
334 self._slider_horizontal.sliderMoved.connect(self.
_slider_moved)
337 self._paramval_lineEdit.editingFinished.connect(self.
_text_changed)
341 self._slider_horizontal.setTracking(
False)
348 self.cmenu.addAction(self.tr(
'Set to Maximum')
350 self.cmenu.addAction(self.tr(
'Set to Minimum')
352 self.cmenu.addAction(self.tr(
'Set to NaN')
357 self._paramval_lineEdit.setText(
'{0:f}'.format(Decimal(str(
371 """@return: Current value in text field.""" 373 self._slider_horizontal.sliderPosition() / self.
scale 374 )
if self.
scale else 0
380 return int(round((self.
_func(value)) * self.
scale))
384 self._update_signal.emit(float(value))
388 self._slider_horizontal.blockSignals(
True)
390 if not math.isnan(value):
393 self._slider_horizontal.setValue(
396 self._paramval_lineEdit.setText(
'{0:f}'.format(Decimal(str(value))))
397 self._slider_horizontal.blockSignals(
False)
410 _update_signal = Signal(int)
413 super(EnumEditor, self).
__init__(updater, config)
415 loadUi(ui_enum, self)
418 enum = eval(config[
'edit_method'])[
'enum']
420 logging.error(
'reconfig EnumEditor) Malformed enum')
424 self.
names = [item[
'name']
for item
in enum]
425 self.
values = [item[
'value']
for item
in enum]
427 items = [
'%s (%s)' % (self.
names[i], self.
values[i])
428 for i
in range(0, len(self.
names))]
431 self._combobox.addItems(items)
434 self._combobox.setCurrentIndex(self.values.index(config[
'default']))
437 self._combobox.currentIndexChanged[
'int'].connect(self.
selected)
450 self._update_signal.emit(self.values.index(value))
454 self._combobox.blockSignals(
True)
455 self._combobox.setCurrentIndex(idx)
456 self._combobox.blockSignals(
False)