Skip to content

Commit

Permalink
rqt_reconfigure) Fix to "Range limits do not update until panel is re…
Browse files Browse the repository at this point in the history
  • Loading branch information
Isao Isaac Saito committed Aug 28, 2013
1 parent ad703c9 commit e97a9c7
Showing 1 changed file with 77 additions and 64 deletions.
141 changes: 77 additions & 64 deletions rqt_reconfigure/src/rqt_reconfigure/param_editors.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ def __init__(self, updater, config):

# Emit signal when cursor leaves the text field.
self._paramval_lineedit.editingFinished.connect(self.edit_finished)
#TODO: Add textChanged to capture the change while cursor is still in
# Add textChanged to capture the change while cursor is still in
# the text field.
self._paramval_lineedit.textChanged.connect(self.edit_finished)

def update_value(self, value):
rospy.logdebug('StringEditor update_value={}'.format(value))
Expand All @@ -163,46 +164,50 @@ def __init__(self, updater, config):

loadUi(ui_int, self)

self.min = int(config['min'])
self.max = int(config['max'])
self._min_val_label.setText(str(self.min))
self._max_val_label.setText(str(self.max))
self._min = int(config['min'])
self._max = int(config['max'])
self._min_val_label.setText(str(self._min))
self._max_val_label.setText(str(self._max))

self._slider_horizontal.setRange(self.min, self.max)
self._slider_horizontal.sliderReleased.connect(self.slider_released)
self._slider_horizontal.sliderMoved.connect(self.update_text)
# valueChanged gets called when groove is clicked on.
self._slider_horizontal.valueChanged.connect(self.update_value)
self._slider_horizontal.setRange(self._min, self._max)

# TODO: Fix that the naming of _paramval_lineEdit instance is not
# consistent among Editor's subclasses.
self._paramval_lineEdit.setValidator(QIntValidator(self.min,
self.max, self))
self._paramval_lineEdit.editingFinished.connect(self.editing_finished)
self._paramval_lineEdit.setValidator(QIntValidator(self._min,
self._max, self))

# Connect slots
self._paramval_lineEdit.textChanged.connect(self._text_edited)
self._slider_horizontal.sliderReleased.connect(self._slider_released)
#self._slider_horizontal.sliderMoved.connect(self._update_text_gui)
# valueChanged gets called when groove is clicked on.
#self._slider_horizontal.valueChanged.connect(self.update_value)

# TODO: This should not always get set to the default it should be the
# current value
self._paramval_lineEdit.setText(str(config['default']))
self._slider_horizontal.setSliderPosition(int(config['default']))

def editing_finished(self):
self._slider_horizontal.setSliderPosition(
int(self._paramval_lineEdit.text()))
def _text_edited(self):
self._update_paramserver(int(self._paramval_lineEdit.text()))

def slider_released(self):
self.update_text(self._slider_horizontal.value())
self._update_paramserver(self._slider_horizontal.value())
def _slider_released(self):
'''Slot for mouse being released from slider.'''
_slider_val = self._slider_horizontal.value()
self._update_text_gui(_slider_val)

def update_text(self, val):
rospy.logdebug(' IntegerEditor.update_text val=%s', str(val))
self._paramval_lineEdit.setText(str(val))
#TODO: Run self._update_paramserver to update the value on PServer
def _update_text_gui(self, value):
rospy.logdebug(' IntegerEditor._update_text_gui val=%s', str(value))
self._paramval_lineEdit.setText(str(value))
# Run self._update_paramserver to update the value on PServer
self._update_paramserver(value)
self.update_value(value)

def update_value(self, val):
self._slider_horizontal.setSliderPosition(int(val))
# Can be redundant when the trigger is the move of slider.
self._slider_horizontal.setSliderPosition(val)

self._paramval_lineEdit.setText(str(val))
rospy.logdebug(' IntegerEditor.update_val val=%s', str(val))


class DoubleEditor(EditorWidget):
Expand All @@ -213,70 +218,78 @@ def __init__(self, updater, config):

# Handle unbounded doubles nicely
if config['min'] != -float('inf'):
self.min = float(config['min'])
self._min_val_label.setText(str(self.min))
self.func = lambda x: x
self.ifunc = self.func
self._min = float(config['min'])
self._min_val_label.setText(str(self._min))
self._func = lambda x: x
self._ifunc = self._func
else:
self.min = -1e10000
self._min = -1e10000
self._min_val_label.setText('-inf')
self.func = lambda x: math.atan(x)
self.ifunc = lambda x: math.tan(x)
self._func = lambda x: math.atan(x)
self._ifunc = lambda x: math.tan(x)

if config['max'] != float('inf'):
self.max = float(config['max'])
self._max_val_label.setText(str(self.max))
self.func = lambda x: x
self.ifunc = self.func
self._max = float(config['max'])
self._max_val_label.setText(str(self._max))
self._func = lambda x: x
self._ifunc = self._func
else:
self.max = 1e10000
self._max = 1e10000
self._max_val_label.setText('inf')
self.func = lambda x: math.atan(x)
self.ifunc = lambda x: math.tan(x)
self._func = lambda x: math.atan(x)
self._ifunc = lambda x: math.tan(x)

self.scale = (self.func(self.max) - self.func(self.min)) / 100
self.scale = (self._func(self._max) - self._func(self._min)) / 100
if self.scale == 0:
self.setDisabled(True)

self.offset = self.func(self.min)
self.offset = self._func(self._min)

self._slider_horizontal.setRange(self.slider_value(self.min),
self.slider_value(self.max))
self._slider_horizontal.sliderReleased.connect(self.slider_released)
self._slider_horizontal.sliderMoved.connect(self.update_text)
self._slider_horizontal.setRange(self._get_value_slider(self._min),
self._get_value_slider(self._max))

self._paramval_lineEdit.setValidator(QDoubleValidator(
self.min, self.max,
self._min, self._max,
8, self))
self._paramval_lineEdit.editingFinished.connect(self.editing_finished)

self._paramval_lineEdit.setText(str(config['default']))
self._slider_horizontal.setSliderPosition(
self.slider_value(config['default']))
self._get_value_slider(config['default']))

def editing_finished(self):
self._slider_horizontal.setSliderPosition(
self.slider_value(float(self._paramval_lineEdit.text())))
# Connect slots
self._paramval_lineEdit.textChanged.connect(self._text_edited)
self._slider_horizontal.sliderReleased.connect(self._slider_released)

def _text_edited(self):
'''Slot for text changed event in text field.'''
self._update_paramserver(float(self._paramval_lineEdit.text()))

def get_value(self):
return self.ifunc(self._slider_horizontal.value() * self.scale)
def _get_value_textfield(self):
'''@return: Current value in text field.'''
return self._ifunc(self._slider_horizontal.value() * self.scale)

def slider_released(self):
self.update_text(self.get_value())
self._update_paramserver(self.get_value())
def _slider_released(self):
'''Slot for mouse being released from slider.'''
_slider_val = self._get_value_textfield()
self._update_text_gui(_slider_val)

def slider_value(self, value):
return int(round((self.func(value)) / self.scale)) if self.scale else 0
def _get_value_slider(self, value):
'''
@rtype: double
'''
return int(round((self._func(value)) / self.scale)) if self.scale else 0

def update_text(self, value):
self._paramval_lineEdit.setText(str(self.get_value()))
rospy.logdebug(' DblEditor.update_text val=%s', str(value))
#TODO: Run self._update_paramserver to update the value on PServer
def _update_text_gui(self, value):
self._paramval_lineEdit.setText(str(value))
rospy.loginfo(' DblEditor._update_text_gui val=%s', str(value))
# Run self._update_paramserver to update the value on PServer
self._update_paramserver(value)
self.update_value(value)

def update_value(self, val):
# Can be redundant when the trigger is the move of slider.
self._slider_horizontal.setSliderPosition(
self.slider_value(float(val)))
self._get_value_slider(float(val)))

self._paramval_lineEdit.setText(str(val))


Expand Down

0 comments on commit e97a9c7

Please sign in to comment.