def __init__(self, profile_data, parent=None): """Creates a new instance. :param profile_data the data of this response curve :param parent the parent widget """ super().__init__(parent) self.profile_data = profile_data self.main_layout = QtWidgets.QGridLayout(self) # Create the two sliders self.left_slider = DualSlider() self.left_slider.setRange(-100, 0) self.right_slider = DualSlider() self.right_slider.setRange(0, 100) # Create spin boxes for the left slider self.left_lower = DynamicDoubleSpinBox() self.left_lower.setMinimum(-1.0) self.left_lower.setMaximum(0.0) self.left_lower.setSingleStep(0.05) self.left_upper = DynamicDoubleSpinBox() self.left_upper.setMinimum(-1.0) self.left_upper.setMaximum(0.0) self.left_upper.setSingleStep(0.05) # Create spin boxes for the right slider self.right_lower = DynamicDoubleSpinBox() self.right_lower.setSingleStep(0.05) self.right_lower.setMinimum(0.0) self.right_lower.setMaximum(1.0) self.right_upper = DynamicDoubleSpinBox() self.right_upper.setSingleStep(0.05) self.right_upper.setMinimum(0.0) self.right_upper.setMaximum(1.0) self._normalizer =\ self.left_slider.range()[1] - self.left_slider.range()[0] # Hook up all the required callbacks self.left_slider.valueChanged.connect(self._update_left) self.right_slider.valueChanged.connect(self._update_right) self.left_lower.valueChanged.connect( lambda value: self._update_from_spinner( value, DualSlider.LowerHandle, self.left_slider)) self.left_upper.valueChanged.connect( lambda value: self._update_from_spinner( value, DualSlider.UpperHandle, self.left_slider)) self.right_lower.valueChanged.connect( lambda value: self._update_from_spinner( value, DualSlider.LowerHandle, self.right_slider)) self.right_upper.valueChanged.connect( lambda value: self._update_from_spinner( value, DualSlider.UpperHandle, self.right_slider)) # Set slider positions self.set_values(self.profile_data.deadzone) # Put everything into the layout self.main_layout.addWidget(self.left_slider, 0, 0, 1, 2) self.main_layout.addWidget(self.right_slider, 0, 2, 1, 2) self.main_layout.addWidget(self.left_lower, 1, 0) self.main_layout.addWidget(self.left_upper, 1, 1) self.main_layout.addWidget(self.right_lower, 1, 2) self.main_layout.addWidget(self.right_upper, 1, 3)
class DeadzoneWidget(QtWidgets.QWidget): """Widget visualizing deadzone settings as well as allowing the modification of these.""" def __init__(self, profile_data, parent=None): """Creates a new instance. :param profile_data the data of this response curve :param parent the parent widget """ super().__init__(parent) self.profile_data = profile_data self.main_layout = QtWidgets.QGridLayout(self) # Create the two sliders self.left_slider = DualSlider() self.left_slider.setRange(-100, 0) self.right_slider = DualSlider() self.right_slider.setRange(0, 100) # Create spin boxes for the left slider self.left_lower = DynamicDoubleSpinBox() self.left_lower.setMinimum(-1.0) self.left_lower.setMaximum(0.0) self.left_lower.setSingleStep(0.05) self.left_upper = DynamicDoubleSpinBox() self.left_upper.setMinimum(-1.0) self.left_upper.setMaximum(0.0) self.left_upper.setSingleStep(0.05) # Create spin boxes for the right slider self.right_lower = DynamicDoubleSpinBox() self.right_lower.setSingleStep(0.05) self.right_lower.setMinimum(0.0) self.right_lower.setMaximum(1.0) self.right_upper = DynamicDoubleSpinBox() self.right_upper.setSingleStep(0.05) self.right_upper.setMinimum(0.0) self.right_upper.setMaximum(1.0) self._normalizer =\ self.left_slider.range()[1] - self.left_slider.range()[0] # Hook up all the required callbacks self.left_slider.valueChanged.connect(self._update_left) self.right_slider.valueChanged.connect(self._update_right) self.left_lower.valueChanged.connect( lambda value: self._update_from_spinner( value, DualSlider.LowerHandle, self.left_slider)) self.left_upper.valueChanged.connect( lambda value: self._update_from_spinner( value, DualSlider.UpperHandle, self.left_slider)) self.right_lower.valueChanged.connect( lambda value: self._update_from_spinner( value, DualSlider.LowerHandle, self.right_slider)) self.right_upper.valueChanged.connect( lambda value: self._update_from_spinner( value, DualSlider.UpperHandle, self.right_slider)) # Set slider positions self.set_values(self.profile_data.deadzone) # Put everything into the layout self.main_layout.addWidget(self.left_slider, 0, 0, 1, 2) self.main_layout.addWidget(self.right_slider, 0, 2, 1, 2) self.main_layout.addWidget(self.left_lower, 1, 0) self.main_layout.addWidget(self.left_upper, 1, 1) self.main_layout.addWidget(self.right_lower, 1, 2) self.main_layout.addWidget(self.right_upper, 1, 3) def set_values(self, values): """Sets the deadzone values. :param values the new deadzone values """ self.left_slider.setLowerPosition(values[0] * self._normalizer) self.left_slider.setUpperPosition(values[1] * self._normalizer) self.right_slider.setLowerPosition(values[2] * self._normalizer) self.right_slider.setUpperPosition(values[3] * self._normalizer) def get_values(self): """Returns the current deadzone values. :return current deadzone values """ return [ self.left_lower.value(), self.left_upper.value(), self.right_lower.value(), self.right_upper.value() ] def _update_left(self, handle, value): """Updates the left spin boxes. :param handle the handle which was moved :param value the new value """ if handle == DualSlider.LowerHandle: self.left_lower.setValue(value / self._normalizer) self.profile_data.deadzone[0] = value / self._normalizer elif handle == DualSlider.UpperHandle: self.left_upper.setValue(value / self._normalizer) self.profile_data.deadzone[1] = value / self._normalizer def _update_right(self, handle, value): """Updates the right spin boxes. :param handle the handle which was moved :param value the new value """ if handle == DualSlider.LowerHandle: self.right_lower.setValue(value / self._normalizer) self.profile_data.deadzone[2] = value / self._normalizer elif handle == DualSlider.UpperHandle: self.right_upper.setValue(value / self._normalizer) self.profile_data.deadzone[3] = value / self._normalizer def _update_from_spinner(self, value, handle, widget): """Updates the slider position. :param value the new value :param handle the handle to move :param widget which slider widget to update """ if handle == DualSlider.LowerHandle: widget.setLowerPosition(value * self._normalizer) elif handle == DualSlider.UpperHandle: widget.setUpperPosition(value * self._normalizer)