Commit b4014267 authored by Thomas Vincent's avatar Thomas Vincent

Make RoiAxisWidget use new RangeSlider + add getSliderState method there

parent 18a704e1
......@@ -30,11 +30,18 @@ __license__ = "MIT"
__date__ = "15/09/2016"
from collections import namedtuple
from silx.gui import qt as Qt
from ..widgets.RangeSlider import RangeSlider
from ..silx_imports.RangeSlider import RangeSlider
from ..widgets.Input import StyledLineEdit, FixedSizeLabel
RangeSliderState = namedtuple('RangeSliderState', ['left', 'right',
'leftIndex', 'rightIndex'])
class RoiAxisWidget(Qt.QWidget):
"""
Widget with a double slider and two line edit
......@@ -42,9 +49,7 @@ class RoiAxisWidget(Qt.QWidget):
"""
sigSliderMoved = Qt.Signal(object)
""" Signal triggered when the slider is moved. Equivalent to connecting
directly to the sliders sigSliderMoved signal.
"""
""" Signal triggered when the slider values has changed."""
def slider(self):
"""
......@@ -65,7 +70,7 @@ class RoiAxisWidget(Qt.QWidget):
qLabel = FixedSizeLabel(nChar=1)
qLabel.setFrameStyle(Qt.QFrame.NoFrame | Qt.QFrame.Plain)
qLabel.setText(label)
slider = self.__slider = RangeSlider()
self.__slider = RangeSlider()
leftEdit = self.__leftEdit = StyledLineEdit(nChar=7)
leftEditValidator = Qt.QDoubleValidator(leftEdit)
......@@ -81,35 +86,43 @@ class RoiAxisWidget(Qt.QWidget):
rightEdit.editingFinished.connect(self.__rightEditingFinished)
layout.addWidget(qLabel, 0, 0)
layout.addWidget(slider, 0, 1, 1, 2)
layout.addWidget(self.__slider, 0, 1, 1, 2)
layout.addWidget(leftEdit, 1, 1)
layout.addWidget(rightEdit, 1, 2)
layout.setColumnStretch(3, 1)
slider.sigSliderMoved.connect(self.__sliderMoved)
slider.sigSliderMoved.connect(self.sigSliderMoved)
self.__slider.sigValueChanged.connect(self.__sliderValueChanged)
def getSliderState(self):
"""Returns current slider state
:rtype: RangeSliderState
"""
firstValue, secondValue = self.slider().getValues()
firstPos, secondPos = self.slider().getPositions()
state = RangeSliderState(left=firstValue,
right=secondValue,
leftIndex=firstPos,
rightIndex=secondPos)
return state
def __leftEditingFinished(self):
"""Handle left line edit editing finished"""
self.__slider.setSliderValue('left', float(self.__leftEdit.text()))
# leftEdit gets updated through sigSliderMoved
self.__slider.setFirstValue(float(self.__leftEdit.text()))
def __rightEditingFinished(self):
"""Handle right line edit editing finished"""
self.__slider.setSliderValue('right', float(self.__rightEdit.text()))
# rightEdit gets updated through sigSliderMoved
self.__slider.setSecondValue(float(self.__rightEdit.text()))
def __sliderMoved(self, event):
"""
Slot triggered when one of the slider is moved. Updates the
line edits.
:param event:
:return:
"""
self.__leftEdit.setText('{0:6g}'.format(event.left))
self.__rightEdit.setText('{0:6g}'.format(event.right))
def __sliderValueChanged(self, first, second):
"""Slot triggered when one of the slider is moved.
Updates the line edits and emits sigSliderMoved.
if __name__ == '__main__':
pass
:param float first:
:param float second:
"""
self.__leftEdit.setText('{0:6g}'.format(first))
self.__rightEdit.setText('{0:6g}'.format(second))
self.sigSliderMoved.emit(self.getSliderState())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment